start:arduino:robots:mecanum
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédenteProchaine révisionLes deux révisions suivantes | ||
start:arduino:robots:mecanum [2022/07/31 11:44] – [Robot Mecanum Version 2 modifié par GL] gerardadmin | start:arduino:robots:mecanum [2022/12/13 22:37] – [programme1 test mecanum PS2] gerardadmin | ||
---|---|---|---|
Ligne 1259: | Ligne 1259: | ||
<code c robot_Original_Mecanum.ino> | <code c robot_Original_Mecanum.ino> | ||
- | // Tester par GL Fontionne | + | // Tester par GL; Fonctionne |
// | // | ||
//Configure THE PWM control pin | //Configure THE PWM control pin | ||
Ligne 1456: | Ligne 1456: | ||
- | ===== Robot Mecanum Version | + | ==== Robot Mecanum Version |
- | <code c Robot_Mecanum002.ino> | + | <code c Robot_Mecanum003.ino> |
- | // Tester par GL le 31 juillet | + | // Tester par GL le 19 Aout 2022 |
//Avec compensation vitesse moteur gauche ( M1 et M2 ) | //Avec compensation vitesse moteur gauche ( M1 et M2 ) | ||
Ligne 1474: | Ligne 1474: | ||
int vit=180; | int vit=180; | ||
- | int comp = ( vit / 3);// compensation de 1/3 de la vitesse pour les moteurs | + | int comp = vit /3; // Compensation |
int vitcomp= (vit - comp); | int vitcomp= (vit - comp); | ||
; | ; | ||
int tempo = 1000; | int tempo = 1000; | ||
+ | int tempo10 = 1000; | ||
int dure= 2; | int dure= 2; | ||
Ligne 1615: | Ligne 1616: | ||
void HC05() | void HC05() | ||
{ | { | ||
+ | if(Serial.available() == -1) { | ||
+ | | ||
+ | | ||
+ | } | ||
if(Serial.available() > 0) //Determine if the received data is greater than 0 | if(Serial.available() > 0) //Determine if the received data is greater than 0 | ||
{ | { | ||
serialData = Serial.read(); | serialData = Serial.read(); | ||
- | Serial.print(" | + | |
- | Serial.println(serialData); | + | |
- | | + | |
if | if | ||
else if(' | else if(' | ||
Ligne 1629: | Ligne 1632: | ||
else if(' | else if(' | ||
else if(' | else if(' | ||
+ | else if(' | ||
+ | else if(' | ||
+ | | ||
| | ||
Ligne 1640: | Ligne 1646: | ||
comp -= 5; // | comp -= 5; // | ||
} | } | ||
- | | + | |
- | Serial.println(vit); | + | |
- | Serial.print(" | + | |
- | Serial.println(vitcomp); | + | |
} | } | ||
if(' | if(' | ||
{ | { | ||
- | avant(); | + | avant(); |
+ | delay(tempo10); | ||
+ | cmd =' | ||
+ | serialData = ' | ||
+ | arret(); | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | | ||
// | // | ||
+ | } | ||
+ | else if(' | ||
+ | { | ||
+ | |||
+ | | ||
+ | | ||
+ | cmd =' | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
+ | else if(' | ||
+ | { | ||
+ | |||
+ | | ||
+ | | ||
+ | cmd =' | ||
+ | | ||
+ | | ||
+ | |||
+ | } | ||
+ | else if(' | ||
+ | { | ||
+ | |||
+ | | ||
+ | | ||
+ | cmd =' | ||
+ | | ||
+ | | ||
+ | |||
+ | } | ||
+ | else if(' | ||
+ | { | ||
+ | |||
+ | |||
+ | | ||
+ | | ||
+ | cmd =' | ||
+ | | ||
+ | | ||
+ | | ||
} | } | ||
else if(' | else if(' | ||
{ | { | ||
arriere(); | arriere(); | ||
+ | delay(tempo10); | ||
+ | cmd =' | ||
+ | serialData = ' | ||
+ | arret(); | ||
+ | | ||
} | } | ||
else if(' | else if(' | ||
{ | { | ||
TourneGauche(); | TourneGauche(); | ||
+ | delay(tempo10); | ||
+ | cmd =' | ||
+ | serialData = ' | ||
+ | arret(); | ||
+ | | ||
} | } | ||
+ | | ||
else if(' | else if(' | ||
{ | { | ||
- | TourneDroite(); | + | TourneDroite(); |
+ | delay(tempo10); | ||
+ | cmd =' | ||
+ | serialData = ' | ||
+ | arret(); | ||
+ | | ||
} | } | ||
Ligne 1667: | Ligne 1738: | ||
{ | { | ||
arret(); | arret(); | ||
+ | } | ||
+ | | ||
+ | | ||
+ | else if(' | ||
+ | { | ||
+ | | ||
+ | | ||
+ | cmd =' | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | void setup() | ||
+ | { | ||
+ | | ||
+ | |||
+ | | ||
+ | pinMode(Echo, | ||
+ | |||
+ | void Motor(int Dri,int Speed1,int Speed2,int Speed3,int Speed4); | ||
+ | int SR04(int Trig,int Echo); | ||
+ | void AvoidingObstacles(); | ||
+ | void HC05(); | ||
+ | |||
+ | } | ||
+ | |||
+ | void loop() | ||
+ | { | ||
+ | //distance = SR04(Trig, | ||
+ | |||
+ | HC05(); //Call the Bluetooth car control function | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ==== Robot Mecanum Version 4 modifié par GL ==== | ||
+ | |||
+ | <code c Robot_Mecanum004.ino> | ||
+ | |||
+ | // Tester par GL le 22 Aout 2022 | ||
+ | // Avec touche " | ||
+ | //Avec compensation vitesse moteur gauche ( M1 et M2 ) | ||
+ | /* | ||
+ | ^ | ||
+ | | ||
+ | | | ||
+ | | | ||
+ | | | ||
+ | | | ||
+ | | | ||
+ | | ||
+ | |||
+ | */ | ||
+ | #include < | ||
+ | |||
+ | //Define the pin of ultrasonic obstacle avoidance sensor | ||
+ | const int Trig = A2; //A2 is defined as the pin Trig connected to the ultrasonic sensor | ||
+ | const int Echo = A3; //A3 is defined as the pin Echo connected to the ultrasonic sensor | ||
+ | |||
+ | MotorDriver m; | ||
+ | |||
+ | |||
+ | int vit=180; | ||
+ | int comp = vit /3; | ||
+ | int vitcomp= (vit - comp); | ||
+ | ; | ||
+ | int tempo = 1000; | ||
+ | int tempo10 = 1000; | ||
+ | int dure= 2; | ||
+ | |||
+ | int distance = 0; // | ||
+ | char serialData; | ||
+ | char cmd; | ||
+ | |||
+ | void arret() | ||
+ | { | ||
+ | m.motor(1, | ||
+ | m.motor(2, | ||
+ | m.motor(3, | ||
+ | m.motor(4, | ||
+ | } | ||
+ | |||
+ | void avant() | ||
+ | { | ||
+ | m.motor(1, | ||
+ | m.motor(2, | ||
+ | m.motor(3, | ||
+ | m.motor(4, | ||
+ | } | ||
+ | |||
+ | void arriere() | ||
+ | { | ||
+ | m.motor(1, | ||
+ | m.motor(2, | ||
+ | m.motor(3, | ||
+ | m.motor(4, | ||
+ | } | ||
+ | |||
+ | void LatDroite() | ||
+ | { | ||
+ | m.motor(1, | ||
+ | m.motor(2, | ||
+ | m.motor(3, | ||
+ | m.motor(4, | ||
+ | } | ||
+ | |||
+ | void LatGauche() | ||
+ | { | ||
+ | m.motor(1, | ||
+ | m.motor(2, | ||
+ | m.motor(3, | ||
+ | m.motor(4, | ||
+ | } | ||
+ | void BiaisDroite() | ||
+ | { | ||
+ | m.motor(1, | ||
+ | m.motor(2, | ||
+ | m.motor(3, | ||
+ | m.motor(4, | ||
+ | } | ||
+ | |||
+ | |||
+ | void BiaisGauche() | ||
+ | { | ||
+ | m.motor(1, | ||
+ | m.motor(2, | ||
+ | m.motor(3, | ||
+ | m.motor(4, | ||
+ | | ||
+ | } | ||
+ | |||
+ | void TourneDroite() | ||
+ | { | ||
+ | m.motor(1, | ||
+ | m.motor(2, | ||
+ | m.motor(3, | ||
+ | m.motor(4, | ||
+ | } | ||
+ | |||
+ | void TourneGauche() | ||
+ | { | ||
+ | m.motor(1, | ||
+ | m.motor(2, | ||
+ | m.motor(3, | ||
+ | m.motor(4, | ||
+ | } | ||
+ | |||
+ | |||
+ | void DemiTourDroite() | ||
+ | { | ||
+ | m.motor(1, | ||
+ | m.motor(2, | ||
+ | m.motor(3, | ||
+ | m.motor(4, | ||
+ | } | ||
+ | |||
+ | void DemiTourGauche() | ||
+ | { | ||
+ | m.motor(1, | ||
+ | m.motor(2, | ||
+ | m.motor(3, | ||
+ | m.motor(4, | ||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | void Demo() | ||
+ | { | ||
+ | for (int i=0; i < 3 ; i++){ | ||
+ | avant(); | ||
+ | delay(tempo10); | ||
+ | arriere(); | ||
+ | delay(tempo10); | ||
+ | LatDroite(); | ||
+ | delay(tempo10); | ||
+ | LatGauche(); | ||
+ | delay(tempo10); | ||
+ | BiaisDroite(); | ||
+ | delay(tempo10); | ||
+ | BiaisGauche(); | ||
+ | delay(tempo10); | ||
+ | TourneDroite(); | ||
+ | delay(tempo10); | ||
+ | TourneGauche(); | ||
+ | delay(tempo10); | ||
+ | DemiTourDroite(); | ||
+ | delay(tempo10); | ||
+ | DemiTourGauche(); | ||
+ | delay(tempo10); | ||
+ | } | ||
+ | } | ||
+ | int SR04(int Trig,int Echo) | ||
+ | { | ||
+ | float cm = 0; | ||
+ | |||
+ | digitalWrite(Trig, | ||
+ | delayMicroseconds(2); | ||
+ | digitalWrite(Trig, | ||
+ | delayMicroseconds(15); | ||
+ | digitalWrite(Trig, | ||
+ | |||
+ | cm = pulseIn(Echo, | ||
+ | cm = (int(cm * 100.0))/ | ||
+ | // | ||
+ | // | ||
+ | // | ||
+ | |||
+ | return cm; //Returns cm value ranging data | ||
+ | } | ||
+ | |||
+ | void AvoidingObstacles() | ||
+ | { | ||
+ | if((distance > 20 ) || cmd == ' | ||
+ | { | ||
+ | delay(100);// | ||
+ | if(distance > 20)//Again, determine if the distance is really greater than 20cm | ||
+ | { | ||
+ | | ||
+ | } | ||
+ | else //Otherwise the distance is less than 20 | ||
+ | { | ||
+ | arriere(); | ||
+ | delay(500); | ||
+ | TourneGauche(); | ||
+ | delay(500); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | void HC05() | ||
+ | { | ||
+ | if(Serial.available() == -1) { | ||
+ | | ||
+ | | ||
+ | } | ||
+ | if(Serial.available() > 0) //Determine if the received data is greater than 0 | ||
+ | { | ||
+ | serialData = Serial.read(); | ||
+ | | ||
+ | if | ||
+ | else if(' | ||
+ | else if(' | ||
+ | else if(' | ||
+ | else if(' | ||
+ | else if(' | ||
+ | else if(' | ||
+ | else if(' | ||
+ | else if(' | ||
+ | else if(' | ||
+ | else if(' | ||
+ | | ||
+ | | ||
+ | |||
+ | else if( serialData == ' | ||
+ | { | ||
+ | comp += 5; // | ||
+ | | ||
+ | } | ||
+ | else if( serialData == ' | ||
+ | { | ||
+ | comp -= 5; // | ||
+ | } | ||
+ | | ||
+ | } | ||
+ | |||
+ | if(' | ||
+ | { | ||
+ | avant(); | ||
+ | delay(tempo10); | ||
+ | cmd =' | ||
+ | serialData = ' | ||
+ | arret(); | ||
+ | |||
+ | | ||
+ | |||
+ | | ||
+ | | ||
+ | |||
+ | | ||
+ | // | ||
} | } | ||
else if(' | else if(' | ||
{ | { | ||
+ | |||
| | ||
+ | | ||
+ | cmd =' | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
+ | else if(' | ||
+ | { | ||
+ | |||
+ | | ||
+ | | ||
+ | cmd =' | ||
+ | | ||
+ | | ||
+ | |||
+ | } | ||
+ | else if(' | ||
+ | { | ||
+ | |||
+ | | ||
+ | | ||
+ | cmd =' | ||
+ | | ||
+ | | ||
+ | |||
} | } | ||
else if(' | else if(' | ||
{ | { | ||
+ | |||
+ | |||
| | ||
+ | | ||
+ | cmd =' | ||
+ | | ||
+ | | ||
+ | | ||
} | } | ||
+ | else if(' | ||
+ | { | ||
+ | arriere(); | ||
+ | delay(tempo10); | ||
+ | cmd =' | ||
+ | serialData = ' | ||
+ | arret(); | ||
+ | | ||
+ | } | ||
+ | else if(' | ||
+ | { | ||
+ | TourneGauche(); | ||
+ | delay(tempo10); | ||
+ | cmd =' | ||
+ | serialData = ' | ||
+ | arret(); | ||
+ | | ||
+ | } | ||
+ | | ||
+ | else if(' | ||
+ | { | ||
+ | TourneDroite(); | ||
+ | delay(tempo10); | ||
+ | cmd =' | ||
+ | serialData = ' | ||
+ | arret(); | ||
+ | | ||
+ | } | ||
+ | |||
+ | else if(' | ||
+ | { | ||
+ | arret(); | ||
+ | } | ||
+ | | ||
+ | | ||
else if(' | else if(' | ||
{ | { | ||
| | ||
+ | | ||
+ | cmd =' | ||
+ | | ||
+ | | ||
+ | | ||
} | } | ||
- | } | + | else if(' |
- | + | | |
- | + | Demo(); | |
+ | | ||
+ | cmd =' | ||
+ | | ||
+ | | ||
+ | |||
+ | } | ||
+ | } | ||
void setup() | void setup() | ||
{ | { | ||
Ligne 1699: | Ligne 2131: | ||
void loop() | void loop() | ||
{ | { | ||
- | distance = SR04(Trig, | + | |
HC05(); //Call the Bluetooth car control function | HC05(); //Call the Bluetooth car control function | ||
} | } | ||
- | </ | + | </ |
+ | |||
+ | |||
+ | ===== Cablage Robot Mecanum ===== | ||
+ | |||
+ | {{ : | ||
===== Cablage SR04 ===== | ===== Cablage SR04 ===== | ||
Ligne 1710: | Ligne 2148: | ||
{{ : | {{ : | ||
+ | |||
+ | |||
+ | ======= Robot Mecanum commandé via PS2 sans fil ======= | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | |||
+ | ==== programme1 test mecanum PS2 ==== | ||
+ | |||
+ | |||
+ | |||
+ | <code c mecanum-test001.ino> | ||
+ | |||
+ | //programme en cours de test par GL le 13/12/2022 | ||
+ | #include < | ||
+ | #include " | ||
+ | |||
+ | //#include " | ||
+ | |||
+ | FaBoPWM faboPWM; | ||
+ | int pos = 0; | ||
+ | int MAX_VALUE = 2000; // motor Motor_PWM | ||
+ | int MIN_VALUE = 300; | ||
+ | |||
+ | // | ||
+ | #define PS2_DAT | ||
+ | #define PS2_CMD | ||
+ | #define PS2_SEL | ||
+ | #define PS2_CLK | ||
+ | |||
+ | //MOTOR CONTROL Pin | ||
+ | #define DIRA1 0 | ||
+ | #define DIRA2 1 | ||
+ | #define DIRB1 2 | ||
+ | #define DIRB2 3 | ||
+ | #define DIRC1 4 | ||
+ | #define DIRC2 5 | ||
+ | #define DIRD1 6 | ||
+ | #define DIRD2 7 | ||
+ | |||
+ | char speed; | ||
+ | // #define pressures | ||
+ | #define pressures | ||
+ | // #define rumble | ||
+ | #define rumble | ||
+ | |||
+ | PS2X ps2x; // create PS2 Controller Class | ||
+ | |||
+ | //right now, the library does NOT support hot pluggable controllers, | ||
+ | //you must always either restart your Arduino after you connect the controller, | ||
+ | //or call config_gamepad(pins) again after connecting the controller. | ||
+ | |||
+ | int error = 0; | ||
+ | byte type = 0; | ||
+ | byte vibrate = 0; | ||
+ | |||
+ | void (* resetFunc) (void) = 0; | ||
+ | |||
+ | // | ||
+ | #define MOTORA_FORWARD(pwm) | ||
+ | #define MOTORA_STOP(x) | ||
+ | #define MOTORA_BACKOFF(pwm) | ||
+ | |||
+ | #define MOTORB_FORWARD(pwm) | ||
+ | #define MOTORB_STOP(x) | ||
+ | #define MOTORB_BACKOFF(pwm) | ||
+ | |||
+ | #define MOTORC_FORWARD(pwm) | ||
+ | #define MOTORC_STOP(x) | ||
+ | #define MOTORC_BACKOFF(pwm) | ||
+ | |||
+ | #define MOTORD_FORWARD(pwm) | ||
+ | #define MOTORD_STOP(x) | ||
+ | #define MOTORD_BACKOFF(pwm) | ||
+ | |||
+ | #define SERIAL | ||
+ | |||
+ | //#define SERIAL | ||
+ | |||
+ | #define LOG_DEBUG | ||
+ | |||
+ | #ifdef LOG_DEBUG | ||
+ | #define M_LOG SERIAL.print | ||
+ | #else | ||
+ | #define M_LOG | ||
+ | #endif | ||
+ | |||
+ | //PWM参数 | ||
+ | #define MAX_PWM | ||
+ | #define MIN_PWM | ||
+ | |||
+ | int Motor_PWM = 1900; | ||
+ | int Motor_PWM_mod = Motor_PWM - 400; | ||
+ | |||
+ | // | ||
+ | // ↑A-----B↑ | ||
+ | // | ||
+ | // | ||
+ | // ↑C-----D↑ | ||
+ | void ADVANCE(uint8_t pwm_A, | ||
+ | { | ||
+ | MOTORA_FORWARD(Motor_PWM_mod); | ||
+ | MOTORB_FORWARD(Motor_PWM); | ||
+ | MOTORC_FORWARD(Motor_PWM_mod); | ||
+ | MOTORD_FORWARD(Motor_PWM); | ||
+ | } | ||
+ | // | ||
+ | // ↓A-----B↓ | ||
+ | // | ||
+ | // | ||
+ | // ↓C-----D↓ | ||
+ | void BACK() | ||
+ | { | ||
+ | MOTORA_BACKOFF(Motor_PWM_mod); | ||
+ | MOTORC_BACKOFF(Motor_PWM_mod); | ||
+ | } | ||
+ | // | ||
+ | // =B-----A↑ | ||
+ | // | ||
+ | // | ↖ | | ||
+ | // ↑C-----D= | ||
+ | void LEFT_1() | ||
+ | { | ||
+ | MOTORA_FORWARD(Motor_PWM); | ||
+ | MOTORC_FORWARD(Motor_PWM); | ||
+ | } | ||
+ | // | ||
+ | // | ||
+ | // | ||
+ | // ↓A-----B↑ | ||
+ | // | ||
+ | // | ||
+ | // ↑C-----D↓ | ||
+ | void LEFT_2() | ||
+ | { | ||
+ | MOTORA_BACKOFF(Motor_PWM); | ||
+ | MOTORC_FORWARD(Motor_PWM); | ||
+ | } | ||
+ | // | ||
+ | // | ||
+ | // | ||
+ | // ↓A-----B= | ||
+ | // | ↙ | | ||
+ | // | ||
+ | // =C-----D↓ | ||
+ | void LEFT_3() | ||
+ | { | ||
+ | MOTORA_BACKOFF(Motor_PWM); | ||
+ | MOTORC_STOP(Motor_PWM); | ||
+ | } | ||
+ | // | ||
+ | // ↑A-----B= | ||
+ | // | ↗ | | ||
+ | // | ||
+ | // =C-----D↑ | ||
+ | void RIGHT_1() | ||
+ | { | ||
+ | MOTORA_FORWARD(Motor_PWM); | ||
+ | MOTORC_STOP(Motor_PWM); | ||
+ | } | ||
+ | // | ||
+ | // ↑A-----B↓ | ||
+ | // | ||
+ | // | ||
+ | // ↓C-----D↑ | ||
+ | void RIGHT_2() | ||
+ | { | ||
+ | MOTORA_FORWARD(Motor_PWM); | ||
+ | MOTORC_BACKOFF(Motor_PWM); | ||
+ | } | ||
+ | // | ||
+ | // =A-----B↓ | ||
+ | // | ||
+ | // | ↘ | | ||
+ | // ↓C-----D= | ||
+ | void RIGHT_3() | ||
+ | { | ||
+ | MOTORA_STOP(Motor_PWM); | ||
+ | MOTORC_BACKOFF(Motor_PWM); | ||
+ | } | ||
+ | // | ||
+ | // ↑A-----B↓ | ||
+ | // | ↗ ↘ | | ||
+ | // | ↖ ↙ | | ||
+ | // ↑C-----D↓ | ||
+ | void rotate_1() | ||
+ | { | ||
+ | MOTORA_FORWARD(Motor_PWM); | ||
+ | MOTORC_FORWARD(Motor_PWM); | ||
+ | } | ||
+ | // | ||
+ | // ↓A-----B↑ | ||
+ | // | ↙ ↖ | | ||
+ | // | ↘ ↗ | | ||
+ | // ↓C-----D↑ | ||
+ | void rotate_2() | ||
+ | { | ||
+ | MOTORA_BACKOFF(Motor_PWM); | ||
+ | MOTORC_BACKOFF(Motor_PWM); | ||
+ | } | ||
+ | // | ||
+ | // =A-----B= | ||
+ | // | ||
+ | // | ||
+ | // =C-----D= | ||
+ | void STOP() | ||
+ | { | ||
+ | MOTORA_STOP(Motor_PWM); | ||
+ | MOTORC_STOP(Motor_PWM); | ||
+ | } | ||
+ | // | ||
+ | |||
+ | void UART_Control() | ||
+ | { | ||
+ | char Uart_Date=0; | ||
+ | if(SERIAL.available()) | ||
+ | { | ||
+ | Uart_Date = SERIAL.read(); | ||
+ | } | ||
+ | switch(Uart_Date) | ||
+ | { | ||
+ | case ' | ||
+ | case ' | ||
+ | case ' | ||
+ | case ' | ||
+ | case ' | ||
+ | case ' | ||
+ | case ' | ||
+ | case ' | ||
+ | case ' | ||
+ | case ' | ||
+ | case ' | ||
+ | case ' | ||
+ | case ' | ||
+ | case ' | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void IO_init() | ||
+ | { | ||
+ | STOP(); | ||
+ | } | ||
+ | |||
+ | void setup() | ||
+ | { | ||
+ | | ||
+ | | ||
+ | if(faboPWM.begin()) | ||
+ | { | ||
+ | Serial.println(" | ||
+ | faboPWM.init(300); | ||
+ | } | ||
+ | faboPWM.set_hz(50); | ||
+ | SERIAL.print(" | ||
+ | |||
+ | | ||
+ | //CHANGES for v1.6 HERE!!! **************PAY ATTENTION************* | ||
+ | |||
+ | //setup pins and settings: GamePad(clock, | ||
+ | error = ps2x.config_gamepad(PS2_CLK, | ||
+ | |||
+ | if (error == 0) { | ||
+ | Serial.print(" | ||
+ | Serial.print(" | ||
+ | if (pressures) | ||
+ | Serial.println(" | ||
+ | else | ||
+ | Serial.println(" | ||
+ | Serial.print(" | ||
+ | if (rumble) | ||
+ | Serial.println(" | ||
+ | else | ||
+ | Serial.println(" | ||
+ | Serial.println(" | ||
+ | Serial.println(" | ||
+ | Serial.println(" | ||
+ | } | ||
+ | else if (error == 1) | ||
+ | { | ||
+ | Serial.println(" | ||
+ | resetFunc(); | ||
+ | | ||
+ | } | ||
+ | |||
+ | else if (error == 2) | ||
+ | Serial.println(" | ||
+ | |||
+ | else if (error == 3) | ||
+ | Serial.println(" | ||
+ | |||
+ | // Serial.print(ps2x.Analog(1), | ||
+ | |||
+ | type = ps2x.readType(); | ||
+ | switch (type) { | ||
+ | case 0: | ||
+ | Serial.print(" | ||
+ | break; | ||
+ | case 1: | ||
+ | Serial.print(" | ||
+ | break; | ||
+ | case 2: | ||
+ | Serial.print(" | ||
+ | break; | ||
+ | case 3: | ||
+ | Serial.print(" | ||
+ | break; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | void loop() | ||
+ | { | ||
+ | // UART_Control(); | ||
+ | // | ||
+ | /* You must Read Gamepad to get new values and set vibration values | ||
+ | ps2x.read_gamepad(small motor on/off, larger motor strenght from 0-255) | ||
+ | if you don't enable the rumble, use ps2x.read_gamepad(); | ||
+ | You should call this at least once a second | ||
+ | */ | ||
+ | if (error == 1) //skip loop if no controller found | ||
+ | return; | ||
+ | |||
+ | if (type == 2) { //Guitar Hero Controller | ||
+ | return; | ||
+ | } | ||
+ | else { //DualShock Controller | ||
+ | ps2x.read_gamepad(false, | ||
+ | |||
+ | |||
+ | // | ||
+ | if (ps2x.Button(PSB_START)) | ||
+ | Serial.println(" | ||
+ | ADVANCE(500, | ||
+ | |||
+ | |||
+ | } | ||
+ | |||
+ | if (ps2x.Button(PSB_PAD_UP)) { | ||
+ | Serial.println(" | ||
+ | | ||
+ | } | ||
+ | |||
+ | |||
+ | if (ps2x.Button(PSB_PAD_DOWN)) { | ||
+ | Serial.print(" | ||
+ | BACK(); | ||
+ | } | ||
+ | |||
+ | |||
+ | if (ps2x.Button(PSB_PAD_LEFT)) { | ||
+ | Serial.println(" | ||
+ | LEFT_2(); | ||
+ | } | ||
+ | |||
+ | |||
+ | if (ps2x.Button(PSB_PAD_RIGHT)) { | ||
+ | Serial.println(" | ||
+ | RIGHT_2(); | ||
+ | } | ||
+ | // Stop | ||
+ | if (ps2x.Button(PSB_SELECT)) { | ||
+ | Serial.println(" | ||
+ | STOP(); | ||
+ | } | ||
+ | // 左平移 | ||
+ | if (ps2x.Button(PSB_PINK)) { | ||
+ | Serial.println(" | ||
+ | LEFT_1(); | ||
+ | } | ||
+ | |||
+ | if (ps2x.Button(PSB_RED)) { | ||
+ | Serial.println(" | ||
+ | RIGHT_1(); | ||
+ | } | ||
+ | delay(20); | ||
+ | |||
+ | } | ||
+ | if (ps2x.Button(PSB_L1) || ps2x.Button(PSB_R1)) { //print stick values if either is TRUE | ||
+ | Serial.print(" | ||
+ | Serial.print(ps2x.Analog(PSS_LY), | ||
+ | Serial.print("," | ||
+ | Serial.print(ps2x.Analog(PSS_LX), | ||
+ | Serial.print("," | ||
+ | Serial.print(ps2x.Analog(PSS_RY), | ||
+ | Serial.print("," | ||
+ | Serial.println(ps2x.Analog(PSS_RX), | ||
+ | |||
+ | int LY = ps2x.Analog(PSS_LY); | ||
+ | int LX = ps2x.Analog(PSS_LX); | ||
+ | int RY = ps2x.Analog(PSS_RY); | ||
+ | int RX = ps2x.Analog(PSS_RX); | ||
+ | |||
+ | if (LY < 127) | ||
+ | { | ||
+ | |||
+ | // Motor_PWM = 1.5 * (127 - LY); | ||
+ | ADVANCE(500, | ||
+ | //Motor_PWM = 1.5 * (127 - LX); | ||
+ | delay(20); | ||
+ | Serial.print(" | ||
+ | } | ||
+ | |||
+ | if (LY > 127) | ||
+ | { | ||
+ | //Motor_PWM = 1.5 * (LY - 128); | ||
+ | BACK(); | ||
+ | delay(20); | ||
+ | Serial.print(" | ||
+ | } | ||
+ | | ||
+ | if (LX < 128) | ||
+ | { | ||
+ | //Motor_PWM = 1.5 * (127 - LX); | ||
+ | LEFT_2(); | ||
+ | delay(20); | ||
+ | Serial.print(" | ||
+ | } | ||
+ | | ||
+ | if (LX > 128) | ||
+ | { | ||
+ | //Motor_PWM = 1.5 * (LX - 128); | ||
+ | RIGHT_2(); | ||
+ | delay(20); | ||
+ | Serial.print(" | ||
+ | } | ||
+ | | ||
+ | if (LY == 127 && LX == 128) | ||
+ | { | ||
+ | STOP(); | ||
+ | delay(20); | ||
+ | } | ||
+ | |||
+ | } | ||
+ | } | ||
+ | </ |
/home/chanteri/www/fablab37110/data/pages/start/arduino/robots/mecanum.txt · Dernière modification : 2023/02/25 12:06 de gerardadmin