春ロボ 2班 2017
/
asimawari
主にオムニです。
Fork of asimawari by
Revision 3:73625a6c9750, committed 2017-10-26
- Comitter:
- yuto17320508
- Date:
- Thu Oct 26 13:10:28 2017 +0000
- Parent:
- 2:0a99389df632
- Commit message:
- a
Changed in this revision
GET_position/jyairo.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 0a99389df632 -r 73625a6c9750 GET_position/jyairo.h --- a/GET_position/jyairo.h Wed Oct 25 08:54:30 2017 +0000 +++ b/GET_position/jyairo.h Thu Oct 26 13:10:28 2017 +0000 @@ -0,0 +1,53 @@ +#include "RawSerial.h" + +Serial pc(USBTX, USBRX); // tx, rx +//Serial device(p13, p14); // tx, rx +RawSerial device(p13,p14); +AnalogIn tx(p19); +AnalogIn rx(p20); +#define CAN_ID 10 +CAN can1(p30, p29); +DigitalOut led1(LED1); //check + +Ticker ticker; + +uint8_t val[15]= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; +uint8_t check_sum=0; +int16_t data_angle=0; +double angle=0; +bool protect=0; + +char send_data[8]={0,0,0,0,0,0,0,0}; + +void dev_rx () +{ + val[0]=device.getc(); + val[1]=device.getc(); + if(val[0]==170 && val[1]==0) { + for(int i=2; i<14; i++) { + val[i]=device.getc(); + check_sum+=val[i]; + } + val[14]=device.getc(); + if(check_sum==val[14]) { + if(val[4]>0x80)data_angle=((val[3]&0xFF)|((val[4]<<8)&0xFF00))-0xFFFF; + else data_angle=((val[3]&0xFF)|((val[4]<<8)&0xFF00)); + angle=data_angle/100.0; + send_data[0]=data_angle>>8; + send_data[1]=data_angle&255; + if(can1.write(CANMessage(CAN_ID,send_data,2))) { + //pc.printf("send\r\n"); + } + check_sum=0; + } + } +} + +//setting + device.baud(115200); + device.format(8,Serial::None,1); + can1.frequency(1000000); + //ticker.attach(&dev_rx,0.05); + device.attach(dev_rx, Serial::RxIrq); + int a=0; +