Skip to content

Commit

Permalink
Merge pull request #10 from ponoor/develop
Browse files Browse the repository at this point in the history
Arduino sketch folder updated
  • Loading branch information
kanta committed Mar 16, 2021
2 parents 3b7b0eb + d42ae50 commit 7687d21
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 16 deletions.
10 changes: 6 additions & 4 deletions README.md
@@ -1,5 +1,5 @@
## STEP400
![STEP400](https://ponoor.com/cms/wp-content/uploads/2021/02/step400_r100.jpg)
![STEP400](https://ponoor.com/cms/wp-content/uploads/2021/03/step400-product-version-edited.png)

STEP400 is a 4-axis stepper motor driver designed for art or design projects. STEP400 combines the following elements into one single board:

Expand All @@ -12,14 +12,17 @@ The current firmware is focused on working with [Open Sound Control](http://open

Stepper driver chips are STMicroelectronics's [powerSTEP01](https://www.st.com/en/motor-drivers/powerstep01.html) which provide most of functionalities as a stepper driver.

## Documentation
https://ponoor.com/en/docs/step400/

## Repository Contents
### Firmware
These 2 folders contain same codes.
- [/STEP400_firmware](https://github.com/ponoor/STEP400/tree/master/STEP400_firmware) : Arduino Sketch folder
- [/firmware-platformio/STEP400_firmware](https://github.com/ponoor/STEP400/tree/master/firmware-platformio/STEP400_firmware) : PlatformIO folder

### Hardware
[/hardware](https://github.com/ponoor/STEP400/tree/master/hardware) : Eagle files, BOM lists, and schematics PDFs
[/hardware](https://github.com/ponoor/STEP400/tree/master/hardware) : Eagle design files, BOM lists, and schematics PDFs

### Others
[/configTool](https://github.com/ponoor/STEP400/tree/master/configTool) : The configuration tool consists of a html and JavaScritpts.
Expand Down Expand Up @@ -54,5 +57,4 @@ https://github.com/ponoor/step-series-example-TouchDesigner

Contribution of [@loveandsheep](https://github.com/loveandsheep)

## Documentation
https://ponoor.com/en/docs/step400/

44 changes: 35 additions & 9 deletions STEP400_firmware/oscListeners.cpp
Expand Up @@ -85,6 +85,7 @@ void OSCMsgReceive() {
bMsgRouted |= msgIN.route("/reportError", reportError);
bMsgRouted |= msgIN.route("/getHomeSw", getHomeSw);
bMsgRouted |= msgIN.route("/getBusy", getBusy);
bMsgRouted |= msgIN.route("/getDir", getDir);
bMsgRouted |= msgIN.route("/getHiZ", getHiZ);
bMsgRouted |= msgIN.route("/getUvlo", getUvlo);
bMsgRouted |= msgIN.route("/getMotorStatus", getMotorStatus);
Expand Down Expand Up @@ -261,10 +262,13 @@ void getAdcVal(OSCMessage& msg, int addrOffset) {
void resetDev(OSCMessage& msg, int addrOffset) {
uint8_t motorID = getInt(msg, 0);
if(isCorrectMotorId(motorID)) {
stepper[motorID - MOTOR_ID_FIRST].resetDev();
motorID -= MOTOR_ID_FIRST;
stepper[motorID].hardHiZ();
stepper[motorID].resetDev();
}
else if (motorID == MOTOR_ID_ALL) {
for (uint8_t i = 0; i < NUM_OF_MOTOR; i++) {
stepper[i].hardHiZ();
stepper[i].resetDev();
}
}
Expand Down Expand Up @@ -451,6 +455,18 @@ void getBusy(OSCMessage& msg, int addrOffset) {
}
}
}
void getDir(OSCMessage& msg, int addrOffset) {
if (!isDestIpSet) { return; }
uint8_t motorID = getInt(msg, 0);
if(isCorrectMotorId(motorID)) {
sendTwoData("/dir", motorID, dir[motorID - MOTOR_ID_FIRST]);
}
else if (motorID == MOTOR_ID_ALL) {
for (uint8_t i = 0; i < NUM_OF_MOTOR; i++) {
sendTwoData("/dir", i + MOTOR_ID_FIRST, HiZ[i]);
}
}
}
void getHiZ(OSCMessage& msg, int addrOffset) {
if (!isDestIpSet) { return; }
uint8_t motorID = getInt(msg, 0);
Expand Down Expand Up @@ -841,19 +857,25 @@ void getDecayModeParam(uint8_t motorId) {
turnOnTXL();
}

void enableElectromagnetBrake(uint8_t motorId, bool bEnable) {
electromagnetBrakeEnable[motorId] = bEnable;
if (bEnable) {
pinMode(brakePin[motorId], OUTPUT);
} else {
digitalWrite(brakePin[motorId], LOW);
}
}
void enableElectromagnetBrake(OSCMessage& msg, int addrOffset) {
uint8_t motorID = getInt(msg, 0);
bool bEnable = getBool(msg, 1);
#ifndef PROTOTYPE_R4
if(isCorrectMotorId(motorID)) {
motorID -= MOTOR_ID_FIRST;
electromagnetBrakeEnable[motorID] = bEnable;
if (bEnable) pinMode(brakePin[motorID], OUTPUT);
enableElectromagnetBrake(motorID, bEnable);
}
else if (motorID == MOTOR_ID_ALL) {
for (uint8_t i = 0; i < NUM_OF_MOTOR; i++) {
electromagnetBrakeEnable[i] = bEnable;
if (bEnable) pinMode(brakePin[i], OUTPUT);
enableElectromagnetBrake(i, bEnable);
}
}
#endif
Expand Down Expand Up @@ -1173,8 +1195,8 @@ void getKval(uint8_t motorID) {
#pragma endregion kval_commands_osc_listener

#pragma region tval_commands_osc_listener
void setTval(uint8_t motorId, uint8_t hold, uint8_t run, uint8_t acc, uint8_t dec) { motorId -= MOTOR_ID_FIRST;
if (!isCurrentMode[motorId]) {
void setTval(uint8_t motorId, uint8_t hold, uint8_t run, uint8_t acc, uint8_t dec) {
if (isCurrentMode[motorId]) {
stepper[motorId].setHoldTVAL(hold);
stepper[motorId].setRunTVAL(run);
stepper[motorId].setAccTVAL(acc);
Expand Down Expand Up @@ -2006,6 +2028,8 @@ void activate(uint8_t motorId, bool state) {
brakeTranisitionTrigTime[motorId] = millis();
}
}
} else {
sendCommandError(motorId + MOTOR_ID_FIRST, ERROR_COMMAND_IGNORED);
}
}
void activate(OSCMessage& msg, int addrOffset) {
Expand All @@ -2028,6 +2052,8 @@ void free(uint8_t motorId) {
#endif
stepper[motorId].hardHiZ();
brakeStatus[motorId] = BRAKE_DISENGAGED;
} else {
sendCommandError(motorId + MOTOR_ID_FIRST, ERROR_COMMAND_IGNORED);
}
}
void free(OSCMessage& msg, int addrOffset) {
Expand Down Expand Up @@ -2145,7 +2171,7 @@ void getServoParam(OSCMessage& msg, int addrOffset) {
#pragma region PowerSTEP01_config_osc_listener

void setVoltageMode(uint8_t motorId) {
stepper[motorId].hardHiZ();
//stepper[motorId].hardHiZ();
stepper[motorId].setPWMFreq(PWM_DIV_1, PWM_MUL_0_75);
stepper[motorId].setHoldKVAL(kvalHold[motorId]);
stepper[motorId].setRunKVAL(kvalRun[motorId]);
Expand All @@ -2171,7 +2197,7 @@ void setVoltageMode(OSCMessage& msg, int addrOffset) {
}

void setCurrentMode(uint8_t motorId) {
stepper[motorId].hardHiZ();
//stepper[motorId].hardHiZ();
stepper[motorId].setPredictiveControl(CONFIG_PRED_ENABLE);
stepper[motorId].setSwitchingPeriod(5);
if (stepper[motorId].getStepMode() > STEP_SEL_1_16)
Expand Down
2 changes: 2 additions & 0 deletions STEP400_firmware/oscListeners.h
Expand Up @@ -47,6 +47,7 @@ void getHomeSw(uint8_t motorId);
void getLimitSw(OSCMessage& msg, int addrOffset);
void getLimitSw(uint8_t motorId);
void getBusy(OSCMessage& msg, int addrOffset);
void getDir(OSCMessage& msg, int addrOffset);
void getHiZ(OSCMessage& msg, int addrOffset);
void getUvlo(OSCMessage& msg, int addrOffset);
void getMotorStatus(OSCMessage& msg, int addrOffset);
Expand Down Expand Up @@ -77,6 +78,7 @@ void getBemfParam(uint8_t motorId);
void setDecayModeParam(OSCMessage& msg, int addrOffset);
void getDecayModeParam(OSCMessage& msg, int addrOffset);
void getDecayModeParam(uint8_t motorId);
void enableElectromagnetBrake(uint8_t motorId, bool bEnable);
void enableElectromagnetBrake(OSCMessage& msg, int addrOffset);
void setBrakeTransitionDuration(OSCMessage& msg, int addrOffset);
void getBrakeTransitionDuration(OSCMessage& msg, int addrOffset);
Expand Down
11 changes: 8 additions & 3 deletions STEP400_firmware/utils.cpp
Expand Up @@ -77,6 +77,11 @@ void resetMotorDriver(uint8_t deviceID) {
}
}

void sendWrongDataTypeError() {
if (reportErrors)
sendOneDatum(F("/error/osc"),"WrongDataType");
}

int getInt(OSCMessage &msg, uint8_t offset)
{
int msgVal = 0;
Expand All @@ -89,7 +94,7 @@ int getInt(OSCMessage &msg, uint8_t offset)
msgVal = msg.getInt(offset);
}
else {
sendOneDatum(F("/error/osc"),F("WrongDataType"));
sendWrongDataTypeError();
}
return msgVal;
}
Expand All @@ -106,7 +111,7 @@ float getFloat(OSCMessage &msg, uint8_t offset)
msgVal = msg.getInt(offset);
}
else {
sendOneDatum(F("/error/osc"),F("WrongDataType"));
sendWrongDataTypeError();
}
return msgVal;
}
Expand All @@ -127,7 +132,7 @@ bool getBool(OSCMessage &msg, uint8_t offset)
msgVal = msg.getBoolean(offset);
}
else {
sendOneDatum(F("/error/osc"),F("WrongDataType"));
sendWrongDataTypeError();
}
return msgVal;

Expand Down

0 comments on commit 7687d21

Please sign in to comment.