Basic tank-style drive robot control firmware for Freescale FRDM-K64F. Controls motors on a Dual-Full-H-Bridge with EN, like DBH-1x series, from Bluetooth serial commands
Diff: MotorDrive298.h
- Revision:
- 3:502f90649834
- Parent:
- 1:23d0a615756a
- Child:
- 4:7620d21baef3
--- a/MotorDrive298.h Sun Aug 02 18:34:12 2015 +0000 +++ b/MotorDrive298.h Thu Aug 13 17:50:28 2015 +0000 @@ -171,7 +171,7 @@ IN2.write(0); // digitalWrite(Pin.IN2, 0); EN.write(1); // digitalWrite(Pin.EN , 1); int stoppingTime = (int)ABS(_speed * _decel); -if(_msgCount>0){_msgCount--;CmdSerial.printf("%dms to stop.\r\n",stoppingTime);} +if(_msgCount>0){_msgCount--;DiagSerial.printf("%dms to stop.\r\n",stoppingTime);} _doneTime = millis() + stoppingTime; //speed=0; don't clobber command in case of direction change _mode = MOTOR_STOPPING; @@ -206,7 +206,7 @@ // done stoping, continue to STOP mode _speed = 0; _mode = MOTOR_STOPPED; -if(_msgCount>0){_msgCount--;CmdSerial.puts("stopped.\r");} +if(_msgCount>0){_msgCount--;DiagSerial.puts("stopped.\r");} case MOTOR_STOPPED : if (spdReq == 0) return; // leave in full brake stop _mode = (spdReq < 0) ? MOTOR_START_REV : MOTOR_START_FWD; @@ -216,7 +216,7 @@ EN.write(1); // digitalWrite(Pin.EN,1); // hard kick to get started _doneTime = t + _startupTime; _speedCmd = spdReq; -if(_msgCount>0){_msgCount--;CmdSerial.printf("Start %s\r\n",rev?"REV":"FWD");} +if(_msgCount>0){_msgCount--;DiagSerial.printf("Start %s\r\n",rev?"REV":"FWD");} return; case MOTOR_FWD : case MOTOR_REV : @@ -284,7 +284,7 @@ case MOTOR_STOPPED : if ((t > _doneTime) && _speedCmd) { // this was a temp stop in a direction change. Command desired speed. -if(_msgCount>0){_msgCount--;CmdSerial.printf("Restart %.3f\r\n",_speedCmd);} +if(_msgCount>0){_msgCount--;DiagSerial.printf("Restart %.3f\r\n",_speedCmd);} setSpeed(_speedCmd,t); } //else Serial.println("stopped."); @@ -297,7 +297,7 @@ case MOTOR_START_FWD : if (t > _doneTime) { -if(_msgCount>0){_msgCount--;CmdSerial.puts("moving\r\n");} +if(_msgCount>0){_msgCount--;DiagSerial.puts("moving\r\n");} setSpeed(_speedCmd,t); } return;