From e3746fcdabd11061491dd855476c5a30a109b737 Mon Sep 17 00:00:00 2001 From: ackimixs Date: Mon, 8 Apr 2024 20:56:48 +0200 Subject: [PATCH 01/17] ; --- MyTCPClient.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/MyTCPClient.cpp b/MyTCPClient.cpp index e5522d2..84ece55 100644 --- a/MyTCPClient.cpp +++ b/MyTCPClient.cpp @@ -93,15 +93,15 @@ void MyTCPClient::fermer_pince(int pince) { switch(pince){ case 0: angle = 142; - old_angle = 110; + old_angle = 110; break; case 1: angle = 42; - old_angle = 22; + old_angle = 22; break; case 2: angle = 152; - old_angle = 120 + old_angle = 120; break; } std::cout << "Fermer pince : " << pince << std::endl; @@ -118,16 +118,16 @@ void MyTCPClient::ouvrir_pince(int pince) { } switch(pince){ case 0: - angle = 110; - old_angle = 142; + angle = 115; + old_angle = 142; break; case 1: angle = 22; - old_angle = 42; + old_angle = 42; break; case 2: - angle = 120; - old_angle = 152; + angle = 130; + old_angle = 152; break; } std::cout << "Ouvrir pince : " << pince << std::endl; From 27782e396cdcc63bfdbeac86faf043973531b450 Mon Sep 17 00:00:00 2001 From: ackimixs Date: Tue, 9 Apr 2024 20:11:04 +0200 Subject: [PATCH 02/17] close pince 0 and 2 if bras is moved --- MyTCPClient.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/MyTCPClient.cpp b/MyTCPClient.cpp index 84ece55..ef7b3bc 100644 --- a/MyTCPClient.cpp +++ b/MyTCPClient.cpp @@ -28,9 +28,13 @@ void MyTCPClient::handleMessage(const std::string &message) { this->fermer_pince(pince); } else if (token[2] == "baisser bras") { + this->fermer_pince(0); + this->fermer_pince(2); this->baisser_bras(); } else if (token[2] == "lever bras") { + this->fermer_pince(0); + this->fermer_pince(2); this->lever_bras(); } else if (token[2] == "check panneau") { @@ -93,7 +97,7 @@ void MyTCPClient::fermer_pince(int pince) { switch(pince){ case 0: angle = 142; - old_angle = 110; + old_angle = 115; break; case 1: angle = 42; @@ -101,7 +105,7 @@ void MyTCPClient::fermer_pince(int pince) { break; case 2: angle = 152; - old_angle = 120; + old_angle = 130; break; } std::cout << "Fermer pince : " << pince << std::endl; From 482e4c5a09a448356f327dbc4c08924187d6dc85 Mon Sep 17 00:00:00 2001 From: ackimixs Date: Tue, 9 Apr 2024 20:15:33 +0200 Subject: [PATCH 03/17] don't move is already in place --- MyTCPClient.cpp | 22 +++++++++++++++++++++- MyTCPClient.h | 3 +++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/MyTCPClient.cpp b/MyTCPClient.cpp index ef7b3bc..ebe3bf6 100644 --- a/MyTCPClient.cpp +++ b/MyTCPClient.cpp @@ -63,6 +63,10 @@ void MyTCPClient::pwm_setFrequency(float freq) { void MyTCPClient::pwm_init() { pwm_setFrequency(50.0); + this->fermer_pince(0); + this->fermer_pince(1); + this->fermer_pince(2); + this->baisser_bras(); } @@ -72,24 +76,35 @@ void MyTCPClient::pwm_setServoPosition(int servo, int position) { } void MyTCPClient::baisser_bras() { + if (brasBaisse){ + return; + } int angle = 100; for (int i = 1; i <= angle;i++){ usleep(5'000); this->pwm_setServoPosition(4, i); this->pwm_setServoPosition(5, angle-i); } + brasBaisse = true; } void MyTCPClient::lever_bras() { + if (!brasBaisse){ + return; + } int angle = 107; for (int i = 1; i <= angle;i++){ usleep(5'000); this->pwm_setServoPosition(4, angle-i); this->pwm_setServoPosition(5, i); } + brasBaisse = false; } void MyTCPClient::fermer_pince(int pince) { + if (!pinceOuverte[pince]){ + return; + } int angle, old_angle; if (pince < 0 || pince > 2){ return; @@ -111,11 +126,15 @@ void MyTCPClient::fermer_pince(int pince) { std::cout << "Fermer pince : " << pince << std::endl; for(int i = old_angle; i <= angle;i++){ this->pwm_setServoPosition(pince, i); - usleep(5'000); + usleep(5'000); } + pinceOuverte[pince] = false; } void MyTCPClient::ouvrir_pince(int pince) { + if (pinceOuverte[pince]){ + return; + } int angle, old_angle; if (pince < 0 || pince > 2){ return; @@ -139,6 +158,7 @@ void MyTCPClient::ouvrir_pince(int pince) { this->pwm_setServoPosition(pince, i); usleep(5'000); } + pinceOuverte[pince] = false; } diff --git a/MyTCPClient.h b/MyTCPClient.h index 37bdba9..53db162 100644 --- a/MyTCPClient.h +++ b/MyTCPClient.h @@ -38,4 +38,7 @@ public: private: PiPCA9685::PCA9685 pca; + + bool pinceOuverte[3] = {false, false, false}; + bool brasBaisse = false; }; From 434f54a6625ee1b1a5c059cfa34d43fef9a99e0f Mon Sep 17 00:00:00 2001 From: ackimixs Date: Tue, 9 Apr 2024 20:16:33 +0200 Subject: [PATCH 04/17] change default state --- MyTCPClient.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MyTCPClient.h b/MyTCPClient.h index 53db162..f8a2369 100644 --- a/MyTCPClient.h +++ b/MyTCPClient.h @@ -39,6 +39,6 @@ public: private: PiPCA9685::PCA9685 pca; - bool pinceOuverte[3] = {false, false, false}; - bool brasBaisse = false; + bool pinceOuverte[3] = {true, true, true}; + bool brasBaisse = true; }; From 7bc3e78de0afcf830283317732384cddca8bba05 Mon Sep 17 00:00:00 2001 From: ackimixs Date: Tue, 9 Apr 2024 20:21:12 +0200 Subject: [PATCH 05/17] don't move the bras --- MyTCPClient.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MyTCPClient.cpp b/MyTCPClient.cpp index ebe3bf6..425ad35 100644 --- a/MyTCPClient.cpp +++ b/MyTCPClient.cpp @@ -30,12 +30,12 @@ void MyTCPClient::handleMessage(const std::string &message) { else if (token[2] == "baisser bras") { this->fermer_pince(0); this->fermer_pince(2); - this->baisser_bras(); + // this->baisser_bras(); } else if (token[2] == "lever bras") { this->fermer_pince(0); this->fermer_pince(2); - this->lever_bras(); + // this->lever_bras(); } else if (token[2] == "check panneau") { int bras = std::stoi(token[3]); From b38a75fafb591b149dbd1e1c00a4857a3b61549c Mon Sep 17 00:00:00 2001 From: ackimixs Date: Tue, 9 Apr 2024 20:24:06 +0200 Subject: [PATCH 06/17] oops --- MyTCPClient.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MyTCPClient.cpp b/MyTCPClient.cpp index 425ad35..f1879d0 100644 --- a/MyTCPClient.cpp +++ b/MyTCPClient.cpp @@ -158,7 +158,7 @@ void MyTCPClient::ouvrir_pince(int pince) { this->pwm_setServoPosition(pince, i); usleep(5'000); } - pinceOuverte[pince] = false; + pinceOuverte[pince] = true; } From 31f1125a3add0f181acab866e3946f82f41b85c8 Mon Sep 17 00:00:00 2001 From: ackimixs Date: Tue, 9 Apr 2024 20:24:55 +0200 Subject: [PATCH 07/17] isok --- MyTCPClient.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MyTCPClient.cpp b/MyTCPClient.cpp index f1879d0..2282403 100644 --- a/MyTCPClient.cpp +++ b/MyTCPClient.cpp @@ -30,12 +30,12 @@ void MyTCPClient::handleMessage(const std::string &message) { else if (token[2] == "baisser bras") { this->fermer_pince(0); this->fermer_pince(2); - // this->baisser_bras(); + this->baisser_bras(); } else if (token[2] == "lever bras") { this->fermer_pince(0); this->fermer_pince(2); - // this->lever_bras(); + this->lever_bras(); } else if (token[2] == "check panneau") { int bras = std::stoi(token[3]); From 244edc11a21bbd5f549adf100ae408f6adf966b6 Mon Sep 17 00:00:00 2001 From: ackimixs Date: Wed, 10 Apr 2024 15:03:20 +0200 Subject: [PATCH 08/17] add clear message and change angle to radian --- MyTCPClient.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/MyTCPClient.cpp b/MyTCPClient.cpp index 2282403..96fa3eb 100644 --- a/MyTCPClient.cpp +++ b/MyTCPClient.cpp @@ -51,8 +51,11 @@ void MyTCPClient::handleMessage(const std::string &message) { return; } int servo = std::stoi(args[0]); - int angle = std::stoi(args[1]); - this->pwm_setServoPosition(servo, angle); + double angleRad = std::stof(args[1]) / 100; + int angleDeg = static_cast(angleRad * 180 / 3.14159); + this->pwm_setServoPosition(servo, angleDeg); + } else if (token[2] == "clear") { + this->pwm_clear(); } } } From 7429e81f7dfb1d8c41545997bf273611bfb59adc Mon Sep 17 00:00:00 2001 From: ackimixs Date: Wed, 10 Apr 2024 21:46:17 +0200 Subject: [PATCH 09/17] add force --- MyTCPClient.cpp | 24 ++++++++++++------------ MyTCPClient.h | 8 ++++---- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/MyTCPClient.cpp b/MyTCPClient.cpp index 96fa3eb..10fa47c 100644 --- a/MyTCPClient.cpp +++ b/MyTCPClient.cpp @@ -66,10 +66,10 @@ void MyTCPClient::pwm_setFrequency(float freq) { void MyTCPClient::pwm_init() { pwm_setFrequency(50.0); - this->fermer_pince(0); - this->fermer_pince(1); - this->fermer_pince(2); - this->baisser_bras(); + this->fermer_pince(0, true); + this->fermer_pince(1, true); + this->fermer_pince(2, true); + this->baisser_bras(true); } @@ -78,8 +78,8 @@ void MyTCPClient::pwm_setServoPosition(int servo, int position) { pca.set_pwm(servo, 0, on_time); } -void MyTCPClient::baisser_bras() { - if (brasBaisse){ +void MyTCPClient::baisser_bras(bool force) { + if (brasBaisse && !force){ return; } int angle = 100; @@ -91,8 +91,8 @@ void MyTCPClient::baisser_bras() { brasBaisse = true; } -void MyTCPClient::lever_bras() { - if (!brasBaisse){ +void MyTCPClient::lever_bras(bool force) { + if (!brasBaisse && !force){ return; } int angle = 107; @@ -104,8 +104,8 @@ void MyTCPClient::lever_bras() { brasBaisse = false; } -void MyTCPClient::fermer_pince(int pince) { - if (!pinceOuverte[pince]){ +void MyTCPClient::fermer_pince(int pince, bool force) { + if (!pinceOuverte[pince] && !force){ return; } int angle, old_angle; @@ -134,8 +134,8 @@ void MyTCPClient::fermer_pince(int pince) { pinceOuverte[pince] = false; } -void MyTCPClient::ouvrir_pince(int pince) { - if (pinceOuverte[pince]){ +void MyTCPClient::ouvrir_pince(int pince, bool force) { + if (pinceOuverte[pince] && !force){ return; } int angle, old_angle; diff --git a/MyTCPClient.h b/MyTCPClient.h index f8a2369..75c096a 100644 --- a/MyTCPClient.h +++ b/MyTCPClient.h @@ -22,13 +22,13 @@ public: void pwm_setServoPosition(int servo, int position); - void baisser_bras(); + void baisser_bras(bool force = false); - void lever_bras(); + void lever_bras(bool force = false); - void fermer_pince(int pince); + void fermer_pince(int pince, bool force = false); - void ouvrir_pince(int pince); + void ouvrir_pince(int pince, bool force = false); void check_panneau(int quelBras); From 6763522232c98fae67977fe08169fa3731f7598c Mon Sep 17 00:00:00 2001 From: ackimixs Date: Thu, 11 Apr 2024 14:53:05 +0200 Subject: [PATCH 10/17] mid bras --- MyTCPClient.cpp | 27 +++++++++++++++++++++++---- MyTCPClient.h | 4 +++- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/MyTCPClient.cpp b/MyTCPClient.cpp index 10fa47c..d59f97c 100644 --- a/MyTCPClient.cpp +++ b/MyTCPClient.cpp @@ -37,6 +37,11 @@ void MyTCPClient::handleMessage(const std::string &message) { this->fermer_pince(2); this->lever_bras(); } + else if (token[2] == "mid bras") { + this->fermer_pince(0); + this->fermer_pince(2); + this->mid_bras(); + } else if (token[2] == "check panneau") { int bras = std::stoi(token[3]); this->check_panneau(bras); @@ -79,7 +84,7 @@ void MyTCPClient::pwm_setServoPosition(int servo, int position) { } void MyTCPClient::baisser_bras(bool force) { - if (brasBaisse && !force){ + if (brasBaisse == 0 && !force){ return; } int angle = 100; @@ -88,11 +93,25 @@ void MyTCPClient::baisser_bras(bool force) { this->pwm_setServoPosition(4, i); this->pwm_setServoPosition(5, angle-i); } - brasBaisse = true; + brasBaisse = 0; } +void MyTCPClient::mid_bras(bool force) { + if (brasBaisse == 1 && !force){ + return; + } + int angle = 102; + for (int i = 1; i <= angle;i++){ + usleep(5'000); + this->pwm_setServoPosition(4, angle-i); + this->pwm_setServoPosition(5, i); + } + brasBaisse = 1; +} + + void MyTCPClient::lever_bras(bool force) { - if (!brasBaisse && !force){ + if (!brasBaisse == 2 && !force){ return; } int angle = 107; @@ -101,7 +120,7 @@ void MyTCPClient::lever_bras(bool force) { this->pwm_setServoPosition(4, angle-i); this->pwm_setServoPosition(5, i); } - brasBaisse = false; + brasBaisse = 2; } void MyTCPClient::fermer_pince(int pince, bool force) { diff --git a/MyTCPClient.h b/MyTCPClient.h index 75c096a..8a86b8f 100644 --- a/MyTCPClient.h +++ b/MyTCPClient.h @@ -24,6 +24,8 @@ public: void baisser_bras(bool force = false); + void mid_bras(bool force = false); + void lever_bras(bool force = false); void fermer_pince(int pince, bool force = false); @@ -40,5 +42,5 @@ private: PiPCA9685::PCA9685 pca; bool pinceOuverte[3] = {true, true, true}; - bool brasBaisse = true; + int brasBaisse = 0; }; From 457052a3ef988cf55cf85466784d06783a689bc5 Mon Sep 17 00:00:00 2001 From: ackimixs Date: Thu, 11 Apr 2024 14:54:09 +0200 Subject: [PATCH 11/17] mid bras --- MyTCPClient.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MyTCPClient.cpp b/MyTCPClient.cpp index d59f97c..9c4a65b 100644 --- a/MyTCPClient.cpp +++ b/MyTCPClient.cpp @@ -100,11 +100,11 @@ void MyTCPClient::mid_bras(bool force) { if (brasBaisse == 1 && !force){ return; } - int angle = 102; + int angle = 110; for (int i = 1; i <= angle;i++){ usleep(5'000); - this->pwm_setServoPosition(4, angle-i); - this->pwm_setServoPosition(5, i); + this->pwm_setServoPosition(4, i); + this->pwm_setServoPosition(5, angle-i); } brasBaisse = 1; } From cb841ac380a5fb03a5aa5560c1996a32cafa05d4 Mon Sep 17 00:00:00 2001 From: ackimixs Date: Thu, 11 Apr 2024 14:54:53 +0200 Subject: [PATCH 12/17] mid bras --- MyTCPClient.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MyTCPClient.cpp b/MyTCPClient.cpp index 9c4a65b..fc43719 100644 --- a/MyTCPClient.cpp +++ b/MyTCPClient.cpp @@ -100,7 +100,7 @@ void MyTCPClient::mid_bras(bool force) { if (brasBaisse == 1 && !force){ return; } - int angle = 110; + int angle = 90; for (int i = 1; i <= angle;i++){ usleep(5'000); this->pwm_setServoPosition(4, i); From c7378fe758e5ee38a96c9a7b3636e411fdc69299 Mon Sep 17 00:00:00 2001 From: ackimixs Date: Thu, 11 Apr 2024 14:56:14 +0200 Subject: [PATCH 13/17] mid bras --- MyTCPClient.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MyTCPClient.cpp b/MyTCPClient.cpp index fc43719..89b8183 100644 --- a/MyTCPClient.cpp +++ b/MyTCPClient.cpp @@ -100,7 +100,7 @@ void MyTCPClient::mid_bras(bool force) { if (brasBaisse == 1 && !force){ return; } - int angle = 90; + int angle = 120; for (int i = 1; i <= angle;i++){ usleep(5'000); this->pwm_setServoPosition(4, i); From b12d2df9e831a188813d1176404ca75605a1b9ea Mon Sep 17 00:00:00 2001 From: ackimixs Date: Thu, 11 Apr 2024 14:57:00 +0200 Subject: [PATCH 14/17] mid bras --- MyTCPClient.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MyTCPClient.cpp b/MyTCPClient.cpp index 89b8183..ecda400 100644 --- a/MyTCPClient.cpp +++ b/MyTCPClient.cpp @@ -100,7 +100,7 @@ void MyTCPClient::mid_bras(bool force) { if (brasBaisse == 1 && !force){ return; } - int angle = 120; + int angle = 80; for (int i = 1; i <= angle;i++){ usleep(5'000); this->pwm_setServoPosition(4, i); From 487baae1fc33bcbcf89b3b979c8dd5dc8989cea9 Mon Sep 17 00:00:00 2001 From: ackimixs Date: Thu, 11 Apr 2024 14:59:15 +0200 Subject: [PATCH 15/17] mid bras --- MyTCPClient.cpp | 8 ++++---- MyTCPClient.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/MyTCPClient.cpp b/MyTCPClient.cpp index ecda400..e022144 100644 --- a/MyTCPClient.cpp +++ b/MyTCPClient.cpp @@ -37,11 +37,11 @@ void MyTCPClient::handleMessage(const std::string &message) { this->fermer_pince(2); this->lever_bras(); } - else if (token[2] == "mid bras") { + /*else if (token[2] == "mid bras") { this->fermer_pince(0); this->fermer_pince(2); this->mid_bras(); - } + }*/ else if (token[2] == "check panneau") { int bras = std::stoi(token[3]); this->check_panneau(bras); @@ -96,7 +96,7 @@ void MyTCPClient::baisser_bras(bool force) { brasBaisse = 0; } -void MyTCPClient::mid_bras(bool force) { +/*void MyTCPClient::mid_bras(bool force) { if (brasBaisse == 1 && !force){ return; } @@ -107,7 +107,7 @@ void MyTCPClient::mid_bras(bool force) { this->pwm_setServoPosition(5, angle-i); } brasBaisse = 1; -} +}*/ void MyTCPClient::lever_bras(bool force) { diff --git a/MyTCPClient.h b/MyTCPClient.h index 8a86b8f..9b51c73 100644 --- a/MyTCPClient.h +++ b/MyTCPClient.h @@ -24,7 +24,7 @@ public: void baisser_bras(bool force = false); - void mid_bras(bool force = false); + // void mid_bras(bool force = false); void lever_bras(bool force = false); From efaa61d0f3f4aa437658de7e7d9f98ec59d1f95f Mon Sep 17 00:00:00 2001 From: ackimixs Date: Thu, 11 Apr 2024 15:00:28 +0200 Subject: [PATCH 16/17] remove mid bras --- MyTCPClient.cpp | 19 ------------------- MyTCPClient.h | 2 -- 2 files changed, 21 deletions(-) diff --git a/MyTCPClient.cpp b/MyTCPClient.cpp index e022144..fa584a9 100644 --- a/MyTCPClient.cpp +++ b/MyTCPClient.cpp @@ -37,11 +37,6 @@ void MyTCPClient::handleMessage(const std::string &message) { this->fermer_pince(2); this->lever_bras(); } - /*else if (token[2] == "mid bras") { - this->fermer_pince(0); - this->fermer_pince(2); - this->mid_bras(); - }*/ else if (token[2] == "check panneau") { int bras = std::stoi(token[3]); this->check_panneau(bras); @@ -96,20 +91,6 @@ void MyTCPClient::baisser_bras(bool force) { brasBaisse = 0; } -/*void MyTCPClient::mid_bras(bool force) { - if (brasBaisse == 1 && !force){ - return; - } - int angle = 80; - for (int i = 1; i <= angle;i++){ - usleep(5'000); - this->pwm_setServoPosition(4, i); - this->pwm_setServoPosition(5, angle-i); - } - brasBaisse = 1; -}*/ - - void MyTCPClient::lever_bras(bool force) { if (!brasBaisse == 2 && !force){ return; diff --git a/MyTCPClient.h b/MyTCPClient.h index 9b51c73..45074d4 100644 --- a/MyTCPClient.h +++ b/MyTCPClient.h @@ -24,8 +24,6 @@ public: void baisser_bras(bool force = false); - // void mid_bras(bool force = false); - void lever_bras(bool force = false); void fermer_pince(int pince, bool force = false); From 9bfad7ca707b71a6d6d87d53d5dede0933c4fe77 Mon Sep 17 00:00:00 2001 From: ackimixs Date: Thu, 11 Apr 2024 17:49:56 +0200 Subject: [PATCH 17/17] remove log --- main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/main.cpp b/main.cpp index 513cf24..9eb17ec 100644 --- a/main.cpp +++ b/main.cpp @@ -14,7 +14,6 @@ int main(int argc, char* argv[]) { while (true) { std::string message; - std::cout << "Enter message ('quit' to exit): "; std::getline(std::cin, message); if (message == "quit") {