Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added combine commands #27

Merged
merged 5 commits into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/boardsDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
// #define MZERO_WITH_ZERO_BOOTLOADER

// Common version number
const uint8_t firmwareVersion[3] = {1,2,6};
const uint8_t firmwareVersion[3] = {1,3,0};

#ifdef STEP400_R1
#define PRODUCT_NAME "STEP400"
Expand Down
4 changes: 2 additions & 2 deletions src/loadConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void loadConfig() {
{
sdInitializeSucceeded = SD.begin(PIN_SD_CS);
}
File file = SD.open(filename);
File file = SD.open(filename, FILE_READ);
configFileOpenSucceeded = (file != false);
// Allocate a temporary JsonDocument
// Don't forget to change the capacity to match your requirements.
Expand All @@ -29,7 +29,7 @@ void loadConfig() {
}
configFileParseSucceeded = (error == DeserializationError::Ok);
file.close();
SD.end();
// SD.end();
#endif

// Information
Expand Down
180 changes: 150 additions & 30 deletions src/oscListeners.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ void OSCMsgReceive()
bMsgRouted |= msgIN.route("/run", run);
bMsgRouted |= msgIN.route("/runRaw", runRaw);

// combined
bMsgRouted |= msgIN.route("/combine/move", combinedMove);
bMsgRouted |= msgIN.route("/combine/goTo", combinedGoTo);
bMsgRouted |= msgIN.route("/combine/goToDir", combinedGoToDir);
bMsgRouted |= msgIN.route("/combine/run", combinedRun);
bMsgRouted |= msgIN.route("/combine/runRaw", combinedRunRaw);
bMsgRouted |= msgIN.route("/combine/hardHiZ", combinedHardHiZ);
bMsgRouted |= msgIN.route("/combine/hardStop", combinedHardStop);
bMsgRouted |= msgIN.route("/combine/softHiZ", combinedSoftHiZ);
bMsgRouted |= msgIN.route("/combine/softStop", combinedSoftStop);

// motion
bMsgRouted |= msgIN.route("/move", move);
bMsgRouted |= msgIN.route("/goTo", goTo);
Expand Down Expand Up @@ -2333,12 +2344,8 @@ void getMark(OSCMessage &msg, int addrOffset)
}
}

void run(OSCMessage &msg, int addrOffset)
void run(uint8_t motorID, float absSpeed, bool dir)
{
uint8_t motorID = getInt(msg, 0);
float stepsPerSec = getFloat(msg, 1);
float absSpeed = fabsf(stepsPerSec);
boolean dir = stepsPerSec > 0.0f;
if (isCorrectMotorId(motorID))
{
motorID -= MOTOR_ID_FIRST;
Expand All @@ -2358,13 +2365,28 @@ void run(OSCMessage &msg, int addrOffset)
}
}
}

void runRaw(OSCMessage &msg, int addrOffset)
void run(OSCMessage &msg, int addrOffset)
{
uint8_t motorID = getInt(msg, 0);
int32_t speed = getInt(msg, 1);
boolean dir = speed > 0;
speed = abs(speed);
float stepsPerSec = getFloat(msg, 1);
float absSpeed = fabsf(stepsPerSec);
boolean dir = stepsPerSec > 0.0f;
run(motorID, absSpeed, dir);
}

void combinedRun(OSCMessage &msg, int addrOffset)
{
uint8_t motorID[2];
motorID[0] = getInt(msg, 0);
motorID[1] = getInt(msg, 1);
float stepsPerSec = getFloat(msg, 2);
float absSpeed = fabsf(stepsPerSec);
boolean dir = stepsPerSec > 0.0f;
run(motorID[0], absSpeed, dir);
run(motorID[1], absSpeed, dir);
}
void runRaw(uint8_t motorID, bool dir, int32_t speed)
{
if (isCorrectMotorId(motorID))
{
motorID -= MOTOR_ID_FIRST;
Expand All @@ -2385,12 +2407,29 @@ void runRaw(OSCMessage &msg, int addrOffset)
}
}

void move(OSCMessage &msg, int addrOffset)
void runRaw(OSCMessage &msg, int addrOffset)
{
uint8_t motorID = getInt(msg, 0);
int32_t steps = getInt(msg, 1);
boolean newDir = steps > 0;
steps = abs(steps);
int32_t speed = getInt(msg, 1);
bool dir = speed > 0;
speed = abs(speed);

runRaw(motorID, dir, speed);
}
void combinedRunRaw(OSCMessage &msg, int addrOffset)
{
uint8_t motorID[2];
motorID[0] = getInt(msg, 0);
motorID[1] = getInt(msg, 1);
int32_t speed = getInt(msg, 2);
bool dir = speed > 0;
speed = abs(speed);
runRaw(motorID[0], dir, speed);
runRaw(motorID[1], dir, speed);
}

void move(uint8_t motorID, bool newDir, int32_t steps)
{
if (isCorrectMotorId(motorID))
{
motorID -= MOTOR_ID_FIRST;
Expand All @@ -2410,7 +2449,25 @@ void move(OSCMessage &msg, int addrOffset)
}
}
}
void move(OSCMessage &msg, int addrOffset)
{
uint8_t motorID = getInt(msg, 0);
int32_t steps = getInt(msg, 1);
bool newDir = steps > 0;
steps = abs(steps);
move(motorID, newDir, steps);
}

void combinedMove(OSCMessage &msg, int addrOffset)
{
uint8_t motorID[2] = { getInt(msg, 0), getInt(msg, 1) };
int32_t steps = getInt(msg, 2);
bool newDir = steps > 0;
steps = abs(steps);
move(motorID[0], newDir, steps);
move(motorID[1], newDir, steps);

}
// Try to clear BUSY flag and return TRUE if succeeded.
// GOTO and GOTO_DIR is only executable when not in BUSY state
// So clear the BUSY with RUN command first.
Expand All @@ -2428,10 +2485,8 @@ bool clearBusyForGoTo(uint8_t motorId)
return true;
}
}
void goTo(OSCMessage &msg, int addrOffset)
void goTo(uint8_t motorID, int32_t pos)
{
uint8_t motorID = getInt(msg, 0);
int32_t pos = getInt(msg, 1);
bool newDir = 0;
if (isCorrectMotorId(motorID))
{
Expand Down Expand Up @@ -2466,11 +2521,22 @@ void goTo(OSCMessage &msg, int addrOffset)
}
}
}
void goToDir(OSCMessage &msg, int addrOffset)
void goTo(OSCMessage &msg, int addrOffset)
{
uint8_t motorID = getInt(msg, 0);
boolean dir = getBool(msg, 1);
int32_t pos = getInt(msg, 1);
goTo(motorID, pos);
}
void combinedGoTo(OSCMessage &msg, int addrOffset)
{
uint8_t motorID[2] = { getInt(msg, 0), getInt(msg, 1) };
int32_t pos = getInt(msg, 2);
goTo(motorID[0], pos);
goTo(motorID[1], pos);
}

void goToDir(uint8_t motorID, bool dir, int32_t pos)
{
if (isCorrectMotorId(motorID))
{
uint8_t motorId = motorID - MOTOR_ID_FIRST;
Expand Down Expand Up @@ -2504,7 +2570,21 @@ void goToDir(OSCMessage &msg, int addrOffset)
}
}
}

void goToDir(OSCMessage &msg, int addrOffset)
{
uint8_t motorID = getInt(msg, 0);
boolean dir = getBool(msg, 1);
int32_t pos = getInt(msg, 2);
goToDir(motorID, dir, pos);
}
void combinedGoToDir(OSCMessage &msg, int addrOffset)
{
uint8_t motorID[2] = { getInt(msg, 0), getInt(msg, 1) };
boolean dir = getBool(msg, 2);
int32_t pos = getInt(msg, 3);
goToDir(motorID[0], dir, pos);
goToDir(motorID[1], dir, pos);
}
void homing(uint8_t motorId)
{
if (bHoming[motorId])
Expand Down Expand Up @@ -2751,10 +2831,8 @@ void resetPos(OSCMessage &msg, int addrOffset)
}
}
}

void softStop(OSCMessage &msg, int addrOffset)
void softStop(uint8_t motorID)
{
uint8_t motorID = getInt(msg, 0);
if (isCorrectMotorId(motorID))
{
uint8_t motorId = motorID - MOTOR_ID_FIRST;
Expand All @@ -2772,9 +2850,19 @@ void softStop(OSCMessage &msg, int addrOffset)
}
}
}
void hardStop(OSCMessage &msg, int addrOffset)
void softStop(OSCMessage &msg, int addrOffset)
{
uint8_t motorID = getInt(msg, 0);
softStop(motorID);
}
void combinedSoftStop(OSCMessage &msg, int addrOffset)
{
uint8_t motorID[2] = { getInt(msg, 0), getInt(msg, 1) };
softStop(motorID[0]);
softStop(motorID[1]);
}
void hardStop(uint8_t motorID)
{
if (isCorrectMotorId(motorID))
{
uint8_t motorId = motorID - MOTOR_ID_FIRST;
Expand All @@ -2792,8 +2880,19 @@ void hardStop(OSCMessage &msg, int addrOffset)
}
}
}
void hardStop(OSCMessage &msg, int addrOffset)
{
uint8_t motorID = getInt(msg, 0);
hardStop(motorID);
}
void combinedHardStop(OSCMessage &msg, int addrOffset)
{
uint8_t motorID[2] = { getInt(msg, 0), getInt(msg, 1) };
hardStop(motorID[0]);
hardStop(motorID[1]);

void softHiZ(uint8_t motorId)
}
void executeSoftHiZ(uint8_t motorId)
{
isServoMode[motorId] = false;
clearHomingStatus(motorId);
Expand All @@ -2816,25 +2915,35 @@ void softHiZ(uint8_t motorId)
stepper[motorId].softHiZ();
}
}
void softHiZ(OSCMessage &msg, int addrOffset)
void softHiZ(uint8_t motorID)
{
uint8_t motorID = getInt(msg, 0);
if (isCorrectMotorId(motorID))
{
motorID -= MOTOR_ID_FIRST;
softHiZ(motorID);
executeSoftHiZ(motorID);
}
else if (motorID == MOTOR_ID_ALL)
{
for (uint8_t i = 0; i < NUM_OF_MOTOR; i++)
{
softHiZ(i);
executeSoftHiZ(i);
}
}
}
void hardHiZ(OSCMessage &msg, int addrOffset)
void softHiZ(OSCMessage &msg, int addrOffset)
{
uint8_t motorID = getInt(msg, 0);
softHiZ(motorID);
}
void combinedSoftHiZ(OSCMessage &msg, int addrOffset)
{
uint8_t motorID[2] = { getInt(msg, 0), getInt(msg, 1) };
softHiZ(motorID[0]);
softHiZ(motorID[1]);

}
void hardHiZ(uint8_t motorID)
{
if (isCorrectMotorId(motorID))
{
uint8_t motorId = motorID - MOTOR_ID_FIRST;
Expand Down Expand Up @@ -2871,6 +2980,17 @@ void hardHiZ(OSCMessage &msg, int addrOffset)
}
}
}
void hardHiZ(OSCMessage &msg, int addrOffset)
{
uint8_t motorID = getInt(msg, 0);
hardHiZ(motorID);
}
void combinedHardHiZ(OSCMessage &msg, int addrOffset)
{
uint8_t motorID[2] = { getInt(msg, 0), getInt(msg, 1) };
hardHiZ(motorID[0]);
hardHiZ(motorID[1]);
}

#ifdef HAVE_BRAKE
void activate(uint8_t motorId, bool state)
Expand Down
9 changes: 9 additions & 0 deletions src/oscListeners.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,15 @@ void hardHiZ(OSCMessage& msg, int addrOffset);
void activate(OSCMessage& msg, int addrOffset);
void free(OSCMessage& msg, int addrOffset);
#endif
void combinedRun(OSCMessage& msg, int addrOffset);
void combinedRunRaw(OSCMessage& msg, int addrOffset);
void combinedMove(OSCMessage& msg, int addrOffset);
void combinedGoTo(OSCMessage& msg, int addrOffset);
void combinedGoToDir(OSCMessage& msg, int addrOffset);
void combinedSoftStop(OSCMessage& msg, int addrOffset);
void combinedHardStop(OSCMessage& msg, int addrOffset);
void combinedSoftHiZ(OSCMessage& msg, int addrOffset);
void combinedHardHiZ(OSCMessage& msg, int addrOffset);

// servo_commands_osc_listener
void setTargetPosition(OSCMessage& msg, int addrOffset);
Expand Down
2 changes: 1 addition & 1 deletion step-series-universal-firmware/boardsDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
// #define MZERO_WITH_ZERO_BOOTLOADER

// Common version number
const uint8_t firmwareVersion[3] = {1,2,6};
const uint8_t firmwareVersion[3] = {1,3,0};

#ifdef STEP400_R1
#define PRODUCT_NAME "STEP400"
Expand Down
4 changes: 2 additions & 2 deletions step-series-universal-firmware/loadConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void loadConfig() {
{
sdInitializeSucceeded = SD.begin(PIN_SD_CS);
}
File file = SD.open(filename);
File file = SD.open(filename, FILE_READ);
configFileOpenSucceeded = (file != false);
// Allocate a temporary JsonDocument
// Don't forget to change the capacity to match your requirements.
Expand All @@ -29,7 +29,7 @@ void loadConfig() {
}
configFileParseSucceeded = (error == DeserializationError::Ok);
file.close();
SD.end();
// SD.end();
#endif

// Information
Expand Down
Loading