ver CAN
Diff: ikarashiMDC.cpp
- Revision:
- 0:314f2bed3958
- Child:
- 1:5e8014a1adbd
diff -r 000000000000 -r 314f2bed3958 ikarashiMDC.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ikarashiMDC.cpp Mon Aug 07 22:39:44 2017 +0000 @@ -0,0 +1,39 @@ +#include "ikarashiMDC.h" + + +ikarashiMDC::ikarashiMDC() +{ + serial=NULL; + addr = 0; + motorNum = 0; +} + +int ikarashiMDC::setMotorinfo(uint8_t _addr,uint8_t _motorNum,Serial *_serial) +{ + serial = _serial; + addr = _addr; + motorNum = _motorNum; + return 0; +} + +int ikarashiMDC::setMotorSpeed(double speed) +{ + uint8_t data[3],dataSpeed; + //Limiter + if(speed > 1.0) speed = 1.0; + if(speed < -1.0) speed = -1.0; + + //dataspeed 0~253 neutaral 126 + dataSpeed = ((speed+1.0)/2.0)*253; + //set sending data + data[0] = 255; //header + data[1] = addr; //address + data[2] = dataSpeed; + + //send data + for(int i=0;i<3; i++) + { + serial->putc(data[i]); + } + return 0; + } \ No newline at end of file