Control the Pololu SMC02B
Diff: SMC02B.cpp
- Revision:
- 0:33043894c6cb
- Child:
- 4:420e977e37b6
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SMC02B.cpp Mon Oct 11 18:38:26 2010 +0000 @@ -0,0 +1,75 @@ +/** +* Includes +*/ +#include "SMC02B.h" + + SMC02B::SMC02B(PinName tx, PinName rx, PinName pin) : _rst(pin) + { + _SMC02B = new Serial( tx, rx); + _rst = 1; + } + + void SMC02B::SMC02B_RST(void) + { + _rst = 1; + wait(0.1); + _rst = 0; + wait(0.1); + _rst = 1; + wait(0.1); + } + + // Set Motor movement + // motor + // motor ID + // direction + // 0 - Reverse + // 1 - Forward + // speed + // 0 - 127 ( 0x7F ) + void SMC02B::SMC02B_MOTOR_SET( char motor, char direction, char speed ) + { + char motor_ = motor << 1; + _SMC02B -> putc( SMC02B_START_BYTE ); + _SMC02B -> putc( SMC02B_DEVICE_ID ); + _SMC02B -> putc( motor_ | direction ); + _SMC02B -> putc( speed ); + } + + // OFF Backward -> Brake + void SMC02B::SMC02B_MOTOR_BRAKE( char motor ) + { + char motor_ = motor << 1; + _SMC02B -> putc( SMC02B_START_BYTE ); + _SMC02B -> putc( SMC02B_DEVICE_ID ); + _SMC02B -> putc( motor_ | 0x00 ); + _SMC02B -> putc( 0x00 ); + } + + // OFF Forward -> Coasting + void SMC02B::SMC02B_MOTOR_COAST( char motor ) + { + char motor_ = motor << 1; + _SMC02B -> putc( SMC02B_START_BYTE ); + _SMC02B -> putc( SMC02B_DEVICE_ID ); + _SMC02B -> putc( motor_ | 0x01 ); + _SMC02B -> putc( 0x00 ); + } + + // Config + // mode + // 0 - 2 Motors + // 1 - 1 Motor + // motor + // 0 - 63 ( 0x3F ) First motor number + void SMC02B::SMC02B_CONFIG( char mode, char motor ) + { + char mode_ = mode << 6; + char motor_ = motor & 0x3F; + _SMC02B -> putc( SMC02B_START_BYTE ); + _SMC02B -> putc( SMC02B_CONFIG_BYTE ); + _SMC02B -> putc(mode_ | motor_ ); + } + + +