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édente | ||
| start:arduino:robots:mecanum [2022/08/22 17:49] – [Robot Mecanum Version 4 modifié par GL] gerardadmin | start:arduino:robots:mecanum [2023/02/25 12:06] (Version actuelle) – [Robot à roues Mecanum] gerardadmin | ||
|---|---|---|---|
| Ligne 2: | Ligne 2: | ||
| [[https:// | [[https:// | ||
| + | |||
| + | [[https:// | ||
| ==== Qu' | ==== Qu' | ||
| Ligne 1781: | Ligne 1783: | ||
| //Avec compensation vitesse moteur gauche ( M1 et M2 ) | //Avec compensation vitesse moteur gauche ( M1 et M2 ) | ||
| /* | /* | ||
| + | ^ | ||
| | | ||
| | | | | ||
| Ligne 2147: | Ligne 2150: | ||
| {{ : | {{ : | ||
| + | |||
| + | |||
| + | ======= 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/attic/start/arduino/robots/mecanum.1661183393.txt.gz · Dernière modification : (modification externe)
