Skip to content

Commit b731396

Browse files
committed
fixed compiling errors for Mechaduino. Added sanity checks for different hardware boards (AK)
1 parent 61cffeb commit b731396

File tree

7 files changed

+66
-16
lines changed

7 files changed

+66
-16
lines changed

firmware/stepper_nano_zero/board.h

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/**********************************************************************
12
/**********************************************************************
23
Copyright (C) 2018 MisfitTech LLC, All rights reserved.
34
@@ -56,6 +57,10 @@
5657
// comment out this next line if using the older hardware
5758
#define NEMA17_SMART_STEPPER_3_21_2017
5859

60+
#if defined(MECHADUINO_HARDWARE) && defined(NEMA17_SMART_STEPPER_3_21_2017)
61+
#error "Cannot have both MECHADUINO_HARDWARE and NEMA17_SMART_STEPPER_3_21_2017 defined in board.h"
62+
#endif
63+
5964
//The MKS Servo42 uses the A1333_Encoder
6065
// Please uncomment this line and make sure the NEMA17_SMART_STEPPER_3_21_2017 is
6166
// uncommented for the Servo42
@@ -82,7 +87,7 @@
8287
//#define ENABLE_PHASE_PREDICTION //this enables prediction of phase at high velocity to increase motor speed
8388
//as of FW0.11 it is considered development only
8489

85-
#define VERSION "FW: 0.39" //this is what prints on LCD during splash screen
90+
#define VERSION "FW: 0.40" //this is what prints on LCD during splash screen
8691

8792
//Define this to allow command out serial port, else hardware serial is debug log
8893
//#define CMD_SERIAL_PORT
@@ -91,8 +96,11 @@
9196

9297
//This section is for using the step and dir pins as serial port
9398
// when the enable pin is inactive.
99+
#ifndef MECHADUINO_HARDWARE
94100
#define USE_STEP_DIR_SERIAL
95101
#define STEP_DIR_BAUD (19200) //this is the baud rate we will use
102+
#endif
103+
96104

97105
// These are used as an attempt to use TC4 to count steps
98106
// currently this is not working.
@@ -188,6 +196,7 @@
188196
* 0.38 - fixed bug in the velocity feedback mode.
189197
* 0.39 - changed step count to TCC2, improved the dir pin setup/hold times
190198
* - added support for the MKS Servo42 (A1333 encoder)
199+
* 0.40 - fixed compiling errors for Mechaduino. Added sanity checks for different hardware boards (AK)
191200
*/
192201

193202

@@ -552,4 +561,3 @@ static inline void DelayMs(uint32_t ms)
552561
}
553562

554563
#endif//__BOARD_H__
555-

firmware/stepper_nano_zero/commands.cpp

+18-7
Original file line numberDiff line numberDiff line change
@@ -1077,9 +1077,11 @@ static int move_cmd(sCmdUart *ptrUart,int argc, char * argv[])
10771077
y=pos;
10781078
if (y>f) a=-a;
10791079

1080+
#ifndef MECHADUINO_HARDWARE
10801081
SerialUSB.println(f);
10811082
SerialUSB.println(y);
10821083
SerialUSB.println(a);
1084+
#endif
10831085

10841086
while (abs(y-f)>(2*abs(a)))
10851087
{
@@ -1499,7 +1501,7 @@ static int testcal_cmd(sCmdUart *ptrUart,int argc, char * argv[])
14991501
}
15001502

15011503

1502-
1504+
#ifndef MECHADUINO_HARDWARE
15031505

15041506
uint8_t kbhit(void)
15051507
{
@@ -1515,7 +1517,7 @@ uint8_t putch(char data)
15151517
return SerialUSB.write((uint8_t)data);
15161518
}
15171519

1518-
1520+
#endif
15191521
uint8_t kbhit_hw(void)
15201522
{
15211523
return Serial5.available();
@@ -1549,8 +1551,13 @@ uint8_t putch_step_dir(char data)
15491551

15501552
void commandsInit(void)
15511553
{
1552-
CommandInit(&UsbUart, kbhit, getChar, putch ,NULL); //set up the UART structure
1553-
1554+
1555+
#ifndef MECHADUINO_HARDWARE
1556+
CommandInit(&UsbUart, kbhit, getChar, putch ,NULL); //set up the UART structure
1557+
SerialUSB.print("\n\rPower Up\n\r");
1558+
SerialUSB.print(COMMANDS_PROMPT);
1559+
#endif
1560+
15541561
CommandInit(&HostUart, kbhit_step_dir, getChar_step_dir, putch_step_dir ,NULL); //set up the UART structure for step and dir pins
15551562

15561563
#ifdef CMD_SERIAL_PORT
@@ -1559,8 +1566,6 @@ void commandsInit(void)
15591566
Serial5.print(COMMANDS_PROMPT);
15601567
#endif
15611568

1562-
SerialUSB.print("\n\rPower Up\n\r");
1563-
SerialUSB.print(COMMANDS_PROMPT);
15641569
}
15651570

15661571
int commandsProcess(void)
@@ -1579,5 +1584,11 @@ int commandsProcess(void)
15791584
#ifdef CMD_SERIAL_PORT
15801585
CommandProcess(&SerialUart,Cmds,' ',COMMANDS_PROMPT);
15811586
#endif
1582-
return CommandProcess(&UsbUart,Cmds,' ',COMMANDS_PROMPT);
1587+
1588+
#ifndef MECHADUINO_HARDWARE
1589+
if (SerialUSB.dtr())
1590+
{
1591+
return CommandProcess(&UsbUart,Cmds,' ',COMMANDS_PROMPT);
1592+
}
1593+
#endif
15831594
}

firmware/stepper_nano_zero/nzs.cpp

+21-2
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,9 @@ void NZS::begin(void)
631631

632632
//start up the USB serial interface
633633
//TODO check for power on USB before doing this...
634+
#ifndef MECHADUINO_HARDWARE
634635
SerialUSB.begin(SERIAL_BAUD);
636+
#endif
635637

636638
//setup the serial port for syslog
637639
Serial5.begin(SERIAL_BAUD);
@@ -648,7 +650,7 @@ void NZS::begin(void)
648650
LOG("Power up!");
649651
pinMode(PIN_USB_PWR, INPUT);
650652

651-
653+
#ifndef MECHADUINO_HARDWARE
652654
if (digitalRead(PIN_USB_PWR))
653655
{
654656
//wait for USB serial port to come alive
@@ -665,6 +667,7 @@ void NZS::begin(void)
665667
{
666668
WARNING("USB Not connected");
667669
}
670+
#endif
668671

669672
validateAndInitNVMParams();
670673

@@ -701,9 +704,13 @@ void NZS::begin(void)
701704
//todo we need to handle error on LCD and through command line
702705
if (STEPCTRL_NO_POWER == stepCtrlError)
703706
{
704-
707+
#ifndef MECHADUINO_HARDWARE
705708
SerialUSB.println("Appears that there is no Motor Power");
706709
SerialUSB.println("Connect motor power!");
710+
#else
711+
Serial5.println("Appears that there is no Motor Power");
712+
Serial5.println("Connect motor power!");
713+
#endif
707714
#ifndef DISABLE_LCD
708715
Lcd.lcdShow("Waiting", "MOTOR", "POWER");
709716
#endif
@@ -716,7 +723,11 @@ void NZS::begin(void)
716723

717724
if (STEPCTRL_NO_CAL == stepCtrlError)
718725
{
726+
#ifndef MECHADUINO_HARDWARE
719727
SerialUSB.println("You need to Calibrate");
728+
#else
729+
Serial5.println("You need to Calibrate");
730+
#endif
720731
#ifndef DISABLE_LCD
721732
Lcd.lcdShow(" NOT ", "Calibrated", " ");
722733
delay(1000);
@@ -742,9 +753,15 @@ void NZS::begin(void)
742753

743754
if (STEPCTRL_NO_ENCODER == stepCtrlError)
744755
{
756+
#ifndef MECHADUINO_HARDWARE
745757
SerialUSB.println("AS5047D not working");
746758
SerialUSB.println(" try disconnecting power from board for 15+mins");
747759
SerialUSB.println(" you might have to short out power pins to ground");
760+
#else
761+
Serial5.println("AS5047D not working");
762+
Serial5.println(" try disconnecting power from board for 15+mins");
763+
Serial5.println(" you might have to short out power pins to ground");
764+
#endif
748765
#ifndef DISABLE_LCD
749766
Lcd.lcdShow("Encoder", " Error!", " REBOOT");
750767
#endif
@@ -814,7 +831,9 @@ void printLocation(void)
814831
n=stepperCtrl.getLocation(&loc);
815832
i++;
816833
}
834+
#ifndef MECHADUINO_HARDWARE
817835
SerialUSB.write(buf,len);
836+
#endif
818837

819838
//hex write
820839
// hex write is 29 bytes per tick, @ 6khz this 174000 baud

firmware/stepper_nano_zero/planner.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,12 @@ bool Planner::moveConstantVelocity(float finalAngle, float rpm)
162162
//first determine if operation is in progress
163163
if (PLANNER_NONE != currentMode)
164164
{
165+
#ifndef MECHADUINO_HARDWARE
165166
//we are in operation return false
166167
SerialUSB.println("planner operational");
168+
#else
169+
Serial5.println("planner operational");
170+
#endif
167171
exitTC3CriticalSection(state);
168172
return false;
169173
}
@@ -185,7 +189,9 @@ bool Planner::moveConstantVelocity(float finalAngle, float rpm)
185189

186190
if (startAngle>endAngle)
187191
{
192+
#ifndef MECHADUINO_HARDWARE
188193
SerialUSB.println("reverse");
194+
#endif
189195
tickIncrement=-tickIncrement;
190196
}
191197

firmware/stepper_nano_zero/stepper_controller.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -736,8 +736,11 @@ Angle StepperCtrl::sampleMeanEncoder(int32_t numSamples)
736736
x=(((int32_t)encoder.readEncoderAngle())*4);
737737
if (encoder.getError())
738738
{
739-
739+
#ifndef MECHADUINO_HARDWARE
740740
SerialUSB.println("AS5047 Error");
741+
#else
742+
Serial5.print("AS5047 Error");
743+
#endif
741744
delay(1000);
742745
return 0;
743746
}
@@ -986,7 +989,9 @@ void StepperCtrl::PrintData(void)
986989
char s[128];
987990
bool state=enterCriticalSection();
988991
sprintf(s, "%u,%u,%u", (uint32_t)numSteps,(uint32_t)getDesiredAngle(),(uint32_t)getCurrentAngle());
992+
#ifndef MECHADUINO_HARDWARE
989993
SerialUSB.println(s);
994+
#endif
990995
exitCriticalSection(state);
991996
}
992997
//this is the velocity PID feedback loop

firmware/stepper_nano_zero/syslog.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
#define NEW_LINE "\n\r"
4848

49-
Uart *ptrSerial=NULL;
49+
Stream *ptrSerial=NULL;
5050
eLogLevel SyslogLevelToWrite;
5151

5252
bool DebugUART=false;
@@ -93,14 +93,16 @@ void SysLogPuts(const char *ptrStr)
9393
{
9494
ptrSerial->write(ptrStr);
9595
}
96+
#ifndef MECHADUINO_HARDWARE
9697
if (DebugUART)
9798
{
9899
SerialUSB.write(ptrStr);
99100
}
101+
#endif
100102
}
101103

102104
int SysLogInitDone=0;
103-
void SysLogInit(Uart *ptrSerialObj, eLogLevel LevelToWrite)
105+
void SysLogInit(Stream *ptrSerialObj, eLogLevel LevelToWrite)
104106
{
105107
ptrSerial=ptrSerialObj;
106108
SyslogLevelToWrite=LevelToWrite;
@@ -239,4 +241,3 @@ void SysLog(eLogLevel priorty, const char *fmt, ...)
239241
SysLog_Enabled=previousState;
240242
return;
241243
}
242-

firmware/stepper_nano_zero/syslog.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ static inline const char * __file__( const char *filename ) {
196196
#endif
197197

198198

199-
void SysLogInit(Uart *ptrSerialObj, eLogLevel LevelToWrite);
199+
void SysLogInit(Stream *ptrSerialObj, eLogLevel LevelToWrite);
200200
int SysLogDisable(void);
201201
int SysLogEnable(void);
202202
int SysLogIsEnabled(void);

0 commit comments

Comments
 (0)