Motor driver library for the AP1017.
AKM Development Platform
AP1017 Motor Driver
Import libraryAP1017
Motor driver library for the AP1017.
Diff: AP1017.cpp
- Revision:
- 10:16d45e3f4be3
- Parent:
- 9:1ca7d16de1c4
- Child:
- 11:fe157aefa7e7
diff -r 1ca7d16de1c4 -r 16d45e3f4be3 AP1017.cpp --- a/AP1017.cpp Fri May 19 23:09:27 2017 +0000 +++ b/AP1017.cpp Wed Nov 08 21:37:24 2017 +0000 @@ -1,5 +1,4 @@ #include "AP1017.h" -#include "debug.h" /******************** Constructors & Destructors ****************************/ @@ -37,37 +36,37 @@ case DIRECTION_CW: // direction = 0x00 if(isMotorOn()) { - MSG("#AP1017.cpp: Error. Cannot change direction while motor is running.\r\n"); + MSG("#Error: Cannot change direction while motor is running.\r\n"); return ERROR_MOTORON; }else { inA->write(1); inB->write(0); - MSG("#AP1017.cpp: Direction: CCW\r\n"); + MSG("#Direction: CCW\r\n"); } break; case DIRECTION_CCW: // direction = 0x01 if(isMotorOn()) { - MSG("#AP1017.cpp: Error. Cannot change direction while motor is running.\r\n"); + MSG("#Error: Cannot change direction while motor is running.\r\n"); return ERROR_MOTORON; }else { inA->write(0); inB->write(1); - MSG("#AP1017.cpp: Direction: CW\r\n"); + MSG("#Direction: CW\r\n"); } break; case DIRECTION_BRAKE: // direction = 0x03 inA->write(1); inB->write(1); - MSG("#AP1017.cpp: Direction: Brake\r\n"); + MSG("#Direction: Brake\r\n"); break; case DIRECTION_COAST: // direction = 0x04 inA->write(0); inB->write(0); motorOn = false; - MSG("#AP1017.cpp: Direction: Coast\r\n"); + MSG("#Direction: Coast\r\n"); break; default: return ERROR_DIRECTION; @@ -79,6 +78,23 @@ AP1017::Rotation AP1017::getDirection(void) { + MSG("#Direction: "); + switch(direction){ + case DIRECTION_CW: + MSG("CW\r\n"); + break; + case DIRECTION_CCW: + MSG("CCW\r\n"); + break; + case DIRECTION_COAST: + MSG("Coast\r\n"); + break; + case DIRECTION_BRAKE: + MSG("Brake\r\n"); + break; + default: + MSG("Error: Invalid direction\r\n"); + } return direction; } @@ -90,13 +106,13 @@ dutyCycle = dc/100.0; if(motorOn == true){ - MSG("#AP1017.cpp: Changed running motor speed.\r\n"); + MSG("Speed setting not yet implemented.\r\n"); + //MSG("#Changed running motor speed: %.1f%%.\r\n", dc); } } else { dutyCycle = 0.0; - return ERROR_DUTY_CYCLE; } @@ -106,6 +122,7 @@ float AP1017::getSpeed(void) { + MSG("Speed: %.1f%%\r\n.", dutyCycle*100.0); return dutyCycle*100.0; }