mirror of
https://github.com/modelec/servo_moteurs.git
synced 2026-01-18 16:47:23 +01:00
Je remt bien ce que j'ai cassé
This commit is contained in:
123
MyTCPClient.cpp
123
MyTCPClient.cpp
@@ -13,12 +13,13 @@ void MyTCPClient::handleMessage(const std::string &message) {
|
||||
}
|
||||
|
||||
if (token[1] == "servo_moteur" || token[1] == "all") {
|
||||
// std::cout << message << std::endl;
|
||||
std::cout << message << std::endl;
|
||||
if (token[2] == "ping") {
|
||||
this->sendMessage("servo_moteur;ihm;pong;1");
|
||||
}
|
||||
else if (token[2] == "ouvrir pince") {
|
||||
int pince = std::stoi(token[3]);
|
||||
std::cout << "ouvrir pince : " << pince << std::endl;
|
||||
this->ouvrir_pince(pince);
|
||||
}
|
||||
else if (token[2] == "fermer pince") {
|
||||
@@ -31,7 +32,10 @@ void MyTCPClient::handleMessage(const std::string &message) {
|
||||
this->fermer_pince(2);
|
||||
this->baisser_bras();
|
||||
}
|
||||
else if (token[2] == "lever bras") {
|
||||
else if(token[2] == "transport bras"){
|
||||
this->transport_bras();
|
||||
}
|
||||
else if (token[2] == "lever bras") {
|
||||
this->fermer_pince(0);
|
||||
this->fermer_pince(2);
|
||||
this->lever_bras();
|
||||
@@ -77,15 +81,15 @@ void MyTCPClient::pwm_setServoPosition(int servo, int position) {
|
||||
pca.set_pwm(servo, 0, on_time);
|
||||
}
|
||||
|
||||
void MyTCPClient::baisser_bras() {
|
||||
/*void MyTCPClient::baisser_bras() {
|
||||
int angle;
|
||||
switch(this->poisitionBras){
|
||||
case BRAS_HAUT:
|
||||
angle = 100;
|
||||
break;
|
||||
case BRAS_TRANSPORT:
|
||||
angle = 17;
|
||||
break;
|
||||
switch(this->positionBras){
|
||||
case BRAS_HAUT:
|
||||
angle = 100;
|
||||
break;
|
||||
case BRAS_TRANSPORT:
|
||||
angle = 17;
|
||||
break;
|
||||
}
|
||||
this->positionBras = BRAS_BAS;
|
||||
for (int i = 1; i <= angle;i++){
|
||||
@@ -93,8 +97,8 @@ void MyTCPClient::baisser_bras() {
|
||||
this->pwm_setServoPosition(4, i);
|
||||
this->pwm_setServoPosition(5, angle-i);
|
||||
}
|
||||
}
|
||||
/*void MyTCPClient::baisser_bras(bool force) {
|
||||
}*/
|
||||
void MyTCPClient::baisser_bras(bool force) {
|
||||
if (brasBaisse == 0 && !force){
|
||||
return;
|
||||
}
|
||||
@@ -104,50 +108,52 @@ void MyTCPClient::baisser_bras() {
|
||||
this->pwm_setServoPosition(4, i);
|
||||
this->pwm_setServoPosition(5, angle-i);
|
||||
}
|
||||
this->positionBras = BRAS_BAS;
|
||||
brasBaisse = 0;
|
||||
}*/
|
||||
}
|
||||
|
||||
void MyTCPClient::transport_bras(){
|
||||
int angle;
|
||||
switch(this->poisitionBras){
|
||||
case BRAS_BAS:
|
||||
angle = 17;
|
||||
for (int i = 1; i <= angle; i++){
|
||||
usleep(5'000);
|
||||
this->pwm_setServoPosition(4, angle-i);
|
||||
this->pwm_setServoPosition(5, i);
|
||||
}
|
||||
break;
|
||||
case BRAS_HAUT:
|
||||
angle = 90;
|
||||
for (int i = 1; i <= angle; i++){
|
||||
usleep(5'000);
|
||||
this->pwm_setServoPosition(4, i);
|
||||
this->pwm_setServoPosition(5, angle-i);
|
||||
}
|
||||
break;
|
||||
switch(this->positionBras){
|
||||
case BRAS_BAS:
|
||||
angle = 17;
|
||||
for (int i = 1; i <= angle; i++){
|
||||
usleep(5'000);
|
||||
this->pwm_setServoPosition(4, angle-i);
|
||||
this->pwm_setServoPosition(5, i);
|
||||
}
|
||||
break;
|
||||
case BRAS_HAUT:
|
||||
angle = 90;
|
||||
for (int i = 1; i <= angle; i++){
|
||||
usleep(5'000);
|
||||
this->pwm_setServoPosition(4, i);
|
||||
this->pwm_setServoPosition(5, angle-i);
|
||||
}
|
||||
break;
|
||||
}
|
||||
this->positionBras = BRAS_TRANSPORT;
|
||||
}
|
||||
|
||||
/*
|
||||
void MyTCPClient::lever_bras() {
|
||||
int angle;
|
||||
switch(this->poisitionBras){
|
||||
case BRAS_BAS:
|
||||
angle = 107;
|
||||
break;
|
||||
case BRAS_TRANSPORT:
|
||||
angle = 90
|
||||
break;
|
||||
}
|
||||
switch(this->positionBras){
|
||||
case BRAS_BAS:
|
||||
angle = 107;
|
||||
break;
|
||||
case BRAS_TRANSPORT:
|
||||
angle = 90;
|
||||
break;
|
||||
}
|
||||
this->positionBras = BRAS_HAUT;
|
||||
for (int i = 1; i <= angle;i++){
|
||||
usleep(5'000);
|
||||
this->pwm_setServoPosition(4, angle-i);
|
||||
this->pwm_setServoPosition(5, i);
|
||||
}
|
||||
|
||||
/*void MyTCPClient::lever_bras(bool force) {
|
||||
usleep(5'000);
|
||||
this->pwm_setServoPosition(4, angle-i);
|
||||
this->pwm_setServoPosition(5, i);
|
||||
}
|
||||
}
|
||||
*/
|
||||
void MyTCPClient::lever_bras(bool force) {
|
||||
if (!brasBaisse == 2 && !force){
|
||||
return;
|
||||
}
|
||||
@@ -158,7 +164,8 @@ void MyTCPClient::lever_bras() {
|
||||
this->pwm_setServoPosition(5, i);
|
||||
}
|
||||
brasBaisse = 2;
|
||||
}*/
|
||||
this->positionBras = BRAS_HAUT;
|
||||
}
|
||||
|
||||
void MyTCPClient::fermer_pince(int pince, bool force) {
|
||||
if (!pinceOuverte[pince] && !force){
|
||||
@@ -171,21 +178,21 @@ void MyTCPClient::fermer_pince(int pince, bool force) {
|
||||
switch(pince){
|
||||
case 0:
|
||||
angle = 142;
|
||||
old_angle = 115;
|
||||
old_angle = 115;
|
||||
break;
|
||||
case 1:
|
||||
angle = 42;
|
||||
old_angle = 22;
|
||||
old_angle = 22;
|
||||
break;
|
||||
case 2:
|
||||
angle = 152;
|
||||
old_angle = 130;
|
||||
old_angle = 130;
|
||||
break;
|
||||
}
|
||||
// std::cout << "Fermer pince : " << pince << std::endl;
|
||||
std::cout << "Fermer pince : " << pince << std::endl;
|
||||
for(int i = old_angle; i <= angle;i++){
|
||||
this->pwm_setServoPosition(pince, i);
|
||||
usleep(5'000);
|
||||
this->pwm_setServoPosition(pince, i);
|
||||
usleep(5'000);
|
||||
}
|
||||
pinceOuverte[pince] = false;
|
||||
}
|
||||
@@ -201,21 +208,21 @@ void MyTCPClient::ouvrir_pince(int pince, bool force) {
|
||||
switch(pince){
|
||||
case 0:
|
||||
angle = 115;
|
||||
old_angle = 142;
|
||||
old_angle = 142;
|
||||
break;
|
||||
case 1:
|
||||
angle = 22;
|
||||
old_angle = 42;
|
||||
old_angle = 42;
|
||||
break;
|
||||
case 2:
|
||||
angle = 130;
|
||||
old_angle = 152;
|
||||
old_angle = 152;
|
||||
break;
|
||||
}
|
||||
// std::cout << "Ouvrir pince : " << pince << std::endl;
|
||||
std::cout << "Ouvrir pince : " << pince << std::endl;
|
||||
for (int i = old_angle; i >= angle;i--){
|
||||
this->pwm_setServoPosition(pince, i);
|
||||
usleep(5'000);
|
||||
this->pwm_setServoPosition(pince, i);
|
||||
usleep(5'000);
|
||||
}
|
||||
pinceOuverte[pince] = true;
|
||||
}
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
|
||||
#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
|
||||
#define BRAS_BAS 0
|
||||
#define BRAS_HAUT 1
|
||||
#define BRAS_TRANSPORT 2
|
||||
class MyTCPClient : public TCPClient {
|
||||
public:
|
||||
explicit MyTCPClient(const char* serverIP = "127.0.0.1", int port = 8080);
|
||||
@@ -25,10 +25,14 @@ public:
|
||||
void pwm_setServoPosition(int servo, int position);
|
||||
|
||||
void baisser_bras(bool force = false);
|
||||
|
||||
// void baisser_bras();
|
||||
|
||||
void transport_bras();
|
||||
|
||||
void lever_bras(bool force = false);
|
||||
|
||||
// void lever_bras();
|
||||
|
||||
void fermer_pince(int pince, bool force = false);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user