switch to enum

This commit is contained in:
ackimixs
2024-04-15 19:03:29 +02:00
parent d2bfcc6e00
commit acad34128d
2 changed files with 25 additions and 15 deletions

View File

@@ -94,17 +94,17 @@ void MyTCPClient::baisser_bras() {
case BRAS_TRANSPORT:
begin_angle = 83;
angle = 19;
for (int i=1;i <= angle;i++){
this->pwm_setServoPosition(4, begin_angle+i);
if (angle-i>=5){
this->pwm_setServoPosition(5, angle-i);//Je brode, je brode
}
}
this->positionBras = BRAS_BAS;
return;
for (int i=1;i <= angle;i++){
this->pwm_setServoPosition(4, begin_angle+i);
if (angle-i>=5){
this->pwm_setServoPosition(5, angle-i);//Je brode, je brode
}
}
this->positionBras = BRAS_BAS;
return;
case BRAS_BAS:
this->pwm_setServoPosition(4, 102);
this->pwm_setServoPosition(5, 5);
this->pwm_setServoPosition(5, 5);
return;
}
for (int i = begin_angle; i >= angle;i--){
@@ -144,12 +144,15 @@ void MyTCPClient::transport_bras(){
case BRAS_HAUT:
begin_angle = 107;
angle = 83;
for (int i = 1; i <= angle; i++){
for (int i = 1; i <= angle; i++){
usleep(5'000);
this->pwm_setServoPosition(4, i);
this->pwm_setServoPosition(5, begin_angle-i-7);
}
break;
default:
return;
}
this->positionBras = BRAS_TRANSPORT;
}
@@ -164,8 +167,11 @@ void MyTCPClient::lever_bras() {
case BRAS_TRANSPORT:
begin_angle = 17;
break;
default:
return;
}
for (int i = begin_angle; i <= angle;i++){
for (int i = begin_angle; i <= angle;i++){
usleep(5'000);
this->pwm_setServoPosition(4, angle-i);
this->pwm_setServoPosition(5, i);

View File

@@ -9,9 +9,13 @@
#define SERVO_MIN 82 // 0.02*4096
#define SERVO_MAX 492 // 0.12*4096
#define BRAS_BAS 0
#define BRAS_HAUT 1
#define BRAS_TRANSPORT 2
enum BrasState {
BRAS_BAS,
BRAS_HAUT,
BRAS_TRANSPORT
};
class MyTCPClient : public TCPClient {
public:
explicit MyTCPClient(const char* serverIP = "127.0.0.1", int port = 8080);
@@ -46,7 +50,7 @@ public:
private:
PiPCA9685::PCA9685 pca;
int positionBras;
BrasState positionBras = BRAS_BAS;
bool pinceOuverte[3] = {true, true, true};
int brasBaisse = 0;
};