ver CAN

ikarashiMDC.cpp

Committer:
WAT34
Date:
2017-08-07
Revision:
0:314f2bed3958
Child:
1:5e8014a1adbd

File content as of revision 0:314f2bed3958:

#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;
 }