first

Dependents:   17robo_fuzi 17robo_tokyo_kaede

Committer:
echo_piyo
Date:
Sun Sep 24 05:24:26 2017 +0000
Revision:
0:2365b54fd0db
????2??

Who changed what in which revision?

UserRevisionLine numberNew contents of line
echo_piyo 0:2365b54fd0db 1 #include "rs422_put.h"
echo_piyo 0:2365b54fd0db 2
echo_piyo 0:2365b54fd0db 3 Rs422::Rs422(PinName mbed_tx, PinName mbed_rx) : RS422(mbed_tx,mbed_rx)
echo_piyo 0:2365b54fd0db 4 {
echo_piyo 0:2365b54fd0db 5 }
echo_piyo 0:2365b54fd0db 6
echo_piyo 0:2365b54fd0db 7 void Rs422::begin(int baudrate)
echo_piyo 0:2365b54fd0db 8 {
echo_piyo 0:2365b54fd0db 9 RS422.baud(baudrate);
echo_piyo 0:2365b54fd0db 10 timer.attach(this, &Rs422::put_time, wait_time);
echo_piyo 0:2365b54fd0db 11 }
echo_piyo 0:2365b54fd0db 12
echo_piyo 0:2365b54fd0db 13 void Rs422::put(short id, float m1_duty, float m2_duty)
echo_piyo 0:2365b54fd0db 14 {
echo_piyo 0:2365b54fd0db 15 if (flag == 0) {
echo_piyo 0:2365b54fd0db 16 ID = id;
echo_piyo 0:2365b54fd0db 17 if (m1_duty < 0) {
echo_piyo 0:2365b54fd0db 18 m1_data = 0b10000000;
echo_piyo 0:2365b54fd0db 19 } else {
echo_piyo 0:2365b54fd0db 20 m1_data = 0;
echo_piyo 0:2365b54fd0db 21 }
echo_piyo 0:2365b54fd0db 22 if (m2_duty < 0) {
echo_piyo 0:2365b54fd0db 23 m2_data = 0b10000000;
echo_piyo 0:2365b54fd0db 24 } else {
echo_piyo 0:2365b54fd0db 25 m2_data = 0;
echo_piyo 0:2365b54fd0db 26 }
echo_piyo 0:2365b54fd0db 27 m1_data += fabs(m1_duty) * 100;
echo_piyo 0:2365b54fd0db 28 m2_data += fabs(m2_duty) * 100;
echo_piyo 0:2365b54fd0db 29
echo_piyo 0:2365b54fd0db 30 check_sum = (id + m1_data + m2_data) & 0b01111111;
echo_piyo 0:2365b54fd0db 31 }
echo_piyo 0:2365b54fd0db 32 flag = 1;
echo_piyo 0:2365b54fd0db 33 }
echo_piyo 0:2365b54fd0db 34
echo_piyo 0:2365b54fd0db 35 void Rs422::put_time()
echo_piyo 0:2365b54fd0db 36 {
echo_piyo 0:2365b54fd0db 37 switch (counter) {
echo_piyo 0:2365b54fd0db 38 case 0 :
echo_piyo 0:2365b54fd0db 39 RS422.putc(start_signal);
echo_piyo 0:2365b54fd0db 40 break;
echo_piyo 0:2365b54fd0db 41 case 1 :
echo_piyo 0:2365b54fd0db 42 RS422.putc(ID);
echo_piyo 0:2365b54fd0db 43 break;
echo_piyo 0:2365b54fd0db 44 case 2 :
echo_piyo 0:2365b54fd0db 45 RS422.putc(m1_data);
echo_piyo 0:2365b54fd0db 46 break;
echo_piyo 0:2365b54fd0db 47 case 3 :
echo_piyo 0:2365b54fd0db 48 RS422.putc(m2_data);
echo_piyo 0:2365b54fd0db 49 break;
echo_piyo 0:2365b54fd0db 50 case 4 :
echo_piyo 0:2365b54fd0db 51 RS422.putc(check_sum);
echo_piyo 0:2365b54fd0db 52 break;
echo_piyo 0:2365b54fd0db 53 default :
echo_piyo 0:2365b54fd0db 54 break;
echo_piyo 0:2365b54fd0db 55 }
echo_piyo 0:2365b54fd0db 56 counter ++;
echo_piyo 0:2365b54fd0db 57 if(counter >= 5) {
echo_piyo 0:2365b54fd0db 58 counter = 0;
echo_piyo 0:2365b54fd0db 59 flag = 0;
echo_piyo 0:2365b54fd0db 60 }
echo_piyo 0:2365b54fd0db 61 }