i have built a mecanum rover. forward and back is perfect, so is rotating clockwise and counterclockwise. but when i try to strafe it outputs the same directions as the rotate function does. for example where frontLeft, frontRight, rearLeft, rearRight, forward direction would be 1,1,1,1, rotating would be 1,0,1,0, strafe would be 1,0,0,1 i believe if i processed that correctly, however instead my motors output rotate (1,0,1,0) when it should strafe (1,0,0,1). the data from serial is sending perfect data to the arduino device (raspberry pi pico with official core). nothing in the arduino code tells it to rotate the wrong way, im simply mapping serial data (that has correct data) to accelstepper setspeed. so i assume accelstepper is flawed but maybe i am missing something? here is my arduino sketch.
#include <Servo.h>
#include <AccelStepper.h>
#include <MultiStepper.h>
#define ENABLE_L 7
#define MODE0_L 6
#define MODE1_L 5
#define MODE2_L 4
#define RESET_SLEEP_L 17
#define ENABLE_R 8
#define MODE0_R 9
#define MODE1_R 10
#define MODE2_R 11
#define RESET_SLEEP_R 16
Servo xGimbal;
Servo yGimbal;
AccelStepper MotorFL(1, 1, 0); //STEP, DIR
AccelStepper MotorFR(1, 14, 15);
AccelStepper MotorRL(1, 3, 2);
AccelStepper MotorRR(1, 12, 13);
boolean newData = false;
const byte numChars = 32;
char receivedChars[numChars];
char tempChars[numChars];
int MotorFLData = 0;
int MotorFRData = 0;
int MotorRLData = 0;
int MotorRRData = 0;
int MotorFLReceive = 15000;
int MotorFRReceive = 15000;
int MotorRLReceive = 15000;
int MotorRRReceive = 15000;
int xGimbalReceive = 90;
int yGimbalReceive = 90;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(ENABLE_L, OUTPUT);
pinMode(ENABLE_R, OUTPUT);
pinMode(MODE0_L, OUTPUT);
pinMode(MODE1_L, OUTPUT);
pinMode(MODE2_L, OUTPUT);
pinMode(MODE0_R, OUTPUT);
pinMode(MODE1_R, OUTPUT);
pinMode(MODE2_R, OUTPUT);
pinMode(RESET_SLEEP_L, OUTPUT);
pinMode(RESET_SLEEP_R, OUTPUT);
digitalWrite(ENABLE_L, LOW);
digitalWrite(ENABLE_R, LOW);
digitalWrite(MODE0_L, HIGH);
digitalWrite(MODE1_L, HIGH);
digitalWrite(MODE2_L, LOW);
digitalWrite(MODE0_R, HIGH);
digitalWrite(MODE1_R, HIGH);
digitalWrite(MODE2_R, LOW);
digitalWrite(RESET_SLEEP_L, HIGH);
digitalWrite(RESET_SLEEP_R, HIGH);
xGimbal.attach(18);
yGimbal.attach(19);
MotorFL.setMaxSpeed(12000);
MotorFR.setMaxSpeed(12000);
MotorRL.setMaxSpeed(10000);
MotorRR.setMaxSpeed(10000);
}
void loop() {
recvWithStartEndMarkers();
MotorFL.runSpeed();
MotorFR.runSpeed();
MotorRL.runSpeed();
MotorRR.runSpeed();
MotorFLData = MotorFLReceive - 20000;
MotorFRData = MotorFRReceive - 20000;
MotorRLData = MotorRLReceive - 20000;
MotorRRData = MotorRRReceive - 20000;
if (newData == true) {
strcpy(tempChars, receivedChars);
parseData();
xGimbal.write(xGimbalReceive);
yGimbal.write(yGimbalReceive);
MotorFL.setSpeed(MotorFLData);
MotorFR.setSpeed(MotorFRData);
MotorRL.setSpeed(MotorFLData);
MotorRR.setSpeed(MotorFRData);
newData = false;
}
}
void recvWithStartEndMarkers() {
static boolean recvInProgress = false;
static byte ndx = 0;
char startMarker = '<';
char endMarker = '>';
char PythonRead;
while (Serial.available() > 0 && newData == false) {
PythonRead = Serial.read();
if (recvInProgress == true) {
if (PythonRead != endMarker) {
receivedChars[ndx] = PythonRead;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
recvInProgress = false;
ndx = 0;
newData = true;
}
}
else if (PythonRead == startMarker) {
recvInProgress = true;
}
}
}
void parseData() { // split the data into its parts
char * strtokIndex; // this is used by strtok() as an index
strtokIndex = strtok(tempChars,",");
MotorFLReceive = atoi(strtokIndex);
strtokIndex = strtok(NULL, ",");
MotorFRReceive = atoi(strtokIndex);
strtokIndex = strtok(NULL, ",");
MotorRLReceive = atoi(strtokIndex);
strtokIndex = strtok(NULL, ",");
MotorRRReceive = atoi(strtokIndex);
strtokIndex = strtok(NULL, ",");
xGimbalReceive = atoi(strtokIndex);
strtokIndex = strtok(NULL, ",");
yGimbalReceive = atoi(strtokIndex);
}