ver CAN
ikarashiMDC.cpp
- Committer:
- WAT34
- Date:
- 2017-08-29
- Revision:
- 6:342e3a4f4a8d
- Parent:
- 5:b43c03ee7f8b
- Parent:
- 4:d6f0b74affd7
- Child:
- 8:626daa6d81ac
File content as of revision 6:342e3a4f4a8d:
#include "ikarashiMDC.h" ikarashiMDC::ikarashiMDC(DigitalOut* serialcontrol,uint8_t taddr,uint8_t tmotorNum,bool tmode,Serial *tserial) { serialControl = serialcontrol; serialControl->write(true); serial = tserial; addr = taddr; motorNum = tmotorNum; mode = tmode; } int ikarashiMDC::setSpeed(const double& speed) { uint8_t data[3],dataSpeed; //Limiter const double cropped_speed = -1 < speed ? 1 > speed ? speed:1 :-1; //dataspeed 0~253 neutaral 126 dataSpeed = ((cropped_speed+1.0)/2.0)*253; //printf("%d\n",dataSpeed); //set sending data data[0] = 255; //header data[1] = (addr<<5) + motorNum + (mode<<4); //address data[2] = dataSpeed; //send data for(int i=0; i<3; i++) { serial->putc(data[i]); } return 0; } void estop(Serial *serial) { for(int i = 0; i<3; i++) { serial->putc(255); } }