Communication for reciever
Dependencies: Fork_Boss_Communication_Robot
Dependents: BEAR_Motion BEAR_Motion_Editing4Betago
Fork of BEAR_Protocol by
Receiver.cpp
- Committer:
- b0ssiz
- Date:
- 2016-01-16
- Revision:
- 7:a0ea8c127611
- Parent:
- 6:f6529ad2a70d
- Child:
- 8:2d34916ac178
File content as of revision 7:a0ea8c127611:
#include "mbed.h" #include "Receiver.h" DigitalOut rs485_dirc(RS485_DIRC); Bear_Receiver::Bear_Receiver(PinName tx,PinName rx,int baudrate) { com = new COMMUNICATION(tx,rx,baudrate); } uint8_t Bear_Receiver::ReceiveCommand(uint8_t ID,uint8_t* data_array) { ANDANTE_PROTOCOL_PACKET package; rs485_dirc=0; wait_us(RS485_DELAY); uint8_t status = com->receiveCommunicatePacket(&package); if(status == ANDANTE_ERRBIT_NONE) { ID = package.robotId; data_array = package.parameter; } return status; } void Bear_Receiver::FloatSep(float input_float,uint8_t *int_data_array,uint8_t *float_data_array) { float float_buffer; float int_buffer; int16_t integer; int16_t floating_point; float_buffer=modf(input_float,&int_buffer); float_buffer*=FLOAT_CONVERTER; integer=(int16_t)int_buffer; floating_point=(int16_t)float_buffer; Utilities::ConvertInt16ToUInt8Array(integer,int_data_array); Utilities::ConvertInt16ToUInt8Array(floating_point,float_data_array); } uint8_t Bear_Receiver::sendMotorPos(uint8_t id,float up_angle,float low_angle) { uint8_t IntUpAngle[2],FloatUpAngle[2]; uint8_t IntLowAngle[2],FloatLowAngle[2]; FloatSep(up_angle,IntUpAngle,FloatUpAngle); FloatSep(low_angle,IntLowAngle,FloatLowAngle); ANDANTE_PROTOCOL_PACKET package; package.robotId = id; package.length = 10; package.instructionErrorId = WRITE_DATA; package.parameter[0]=IntUpAngle[0]; package.parameter[1]=IntUpAngle[1]; package.parameter[2]=FloatUpAngle[0]; package.parameter[3]=FloatUpAngle[1]; package.parameter[4]=IntLowAngle[0]; package.parameter[5]=IntLowAngle[1]; package.parameter[6]=FloatLowAngle[0]; package.parameter[7]=FloatLowAngle[1]; rs485_dirc=1; wait_us(RS485_DELAY); return com->sendCommunicatePacket(&package); } uint8_t Bear_Receiver::sendUpMotorKpKiKd(uint8_t id,float Kp,float Ki,float Kd) { uint8_t IntKp[2],FloatKp[2]; uint8_t IntKi[2],FloatKi[2]; uint8_t IntKd[2],FloatKd[2]; FloatSep(Kp,IntKp,FloatKp); FloatSep(Ki,IntKi,FloatKi); FloatSep(Kd,IntKd,FloatKd); ANDANTE_PROTOCOL_PACKET package; package.robotId = id; package.length = 14; package.instructionErrorId = WRITE_DATA; package.parameter[0]=IntKp[0]; package.parameter[1]=IntKp[1]; package.parameter[2]=FloatKp[0]; package.parameter[3]=FloatKp[1]; package.parameter[4]=IntKi[0]; package.parameter[5]=IntKi[1]; package.parameter[6]=FloatKi[0]; package.parameter[7]=FloatKi[1]; package.parameter[8]=IntKd[0]; package.parameter[9]=IntKd[1]; package.parameter[10]=FloatKd[0]; package.parameter[11]=FloatKd[1]; rs485_dirc=1; wait_us(RS485_DELAY); return com->sendCommunicatePacket(&package); } uint8_t Bear_Receiver::sendLowMotorKpKiKd(uint8_t id,float Kp,float Ki,float Kd) { uint8_t IntKp[2],FloatKp[2]; uint8_t IntKi[2],FloatKi[2]; uint8_t IntKd[2],FloatKd[2]; FloatSep(Kp,IntKp,FloatKp); FloatSep(Ki,IntKi,FloatKi); FloatSep(Kd,IntKd,FloatKd); ANDANTE_PROTOCOL_PACKET package; package.robotId = id; package.length = 14; package.instructionErrorId = WRITE_DATA; package.parameter[0]=IntKp[0]; package.parameter[1]=IntKp[1]; package.parameter[2]=FloatKp[0]; package.parameter[3]=FloatKp[1]; package.parameter[4]=IntKi[0]; package.parameter[5]=IntKi[1]; package.parameter[6]=FloatKi[0]; package.parameter[7]=FloatKi[1]; package.parameter[8]=IntKd[0]; package.parameter[9]=IntKd[1]; package.parameter[10]=FloatKd[0]; package.parameter[11]=FloatKd[1]; rs485_dirc=1; wait_us(RS485_DELAY); return com->sendCommunicatePacket(&package); }