If i change value of the code for max motor (quantity of 4) speed to 100 steps per second max in that range or slower, the servos stay armed and kind of work like they should but still not exactly perfect. what i mean by that is if i move the servo controls too fast the servos do not react at all.
i am using a raspberry pi pico on arduino core i thought it would be fast enough to process everything as fast as i wanted. when i run the stepper motors at full speed, at up to the set 10,000 steps per second max, the servos will immediately disarm and stop working the instant i start serial control even if i have not moved the controls yet.
i have the controls updating through serial at 60 times per second in every test. even at 1,000 steps per second max the servos do not work. my question is, how can i make the servos function properly while still being able to have some speed on the stepper motors? any performance optimizations available?
will it require a better microcontroller? if so, what microcontroller is fast enough? can a raspberry pi 4 4gb with bms do it? if so, dare i ask what python3 library would be a viable replacement to accelstepper? here is the 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
AccelStepper MotorFL(1, 1, 0); //STEP, DIR
AccelStepper MotorFR(1, 14, 15);
AccelStepper MotorRL(1, 3, 2);
AccelStepper MotorRR(1, 12, 13);
Servo xGimbal;
Servo yGimbal;
boolean newData = false;
const byte numChars = 32;
char receivedChars[numChars];
char tempChars[numChars];
int xGimbalReceive = 90;
int yGimbalReceive = 90;
int MotorFLData = 0;
int MotorFRData = 0;
int MotorRLData = 0;
int MotorRRData = 0;
int MotorFLReceive = 1500;
int MotorFRReceive = 1500;
int MotorRLReceive = 1500;
int MotorRRReceive = 1500;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
xGimbal.attach(18);
yGimbal.attach(19);
xGimbal.write(90);
yGimbal.write(90);
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);
MotorFL.setMaxSpeed(10000);
MotorFR.setMaxSpeed(10000);
MotorRL.setMaxSpeed(10000);
MotorRR.setMaxSpeed(10000);
}
void loop() {
recvWithStartEndMarkers();
MotorFL.runSpeed();
MotorFR.runSpeed();
MotorRL.runSpeed();
MotorRR.runSpeed();
if (newData == true) {
strcpy(tempChars, receivedChars);
parseData();
MotorFLData = MotorFLReceive - 2000;
MotorFRData = MotorFRReceive - 2000;
MotorRLData = MotorRLReceive - 2000;
MotorRRData = MotorRRReceive - 2000;
MotorFL.setSpeed(MotorFLData);
MotorFR.setSpeed(MotorFRData);
MotorRL.setSpeed(MotorRLData);
MotorRR.setSpeed(MotorRRData);
xGimbal.write(xGimbalReceive);
yGimbal.write(yGimbalReceive);
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);
}
here is a photo of the project. at the moment i am looking for smoother spinning wheels to 3d print that dont require lots of screws and bearings. i have been told it looks like a bomb. quite a big battery wrapped in kapton tape and lots of wire i know.
