![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
ライブラリ化を行った後
Dependencies: QEI accelerator bit_test cyclic_io cyclic_var cylinder event_var limit mbed mecanum motor_drive pid pid_encoder rs422_put sbdbt servo
Fork of 17robo_Practice1 by
headerfile_unuse/RS422_put_.h@66:1664ee92539d, 2017-09-24 (annotated)
- Committer:
- echo_piyo
- Date:
- Sun Sep 24 05:25:03 2017 +0000
- Revision:
- 66:1664ee92539d
- Parent:
- RS422_put.h@0:bf96e953cdb8
????2??
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
echo_piyo | 0:bf96e953cdb8 | 1 | /*************** |
echo_piyo | 0:bf96e953cdb8 | 2 | RS422 master libraly |
echo_piyo | 0:bf96e953cdb8 | 3 | |
echo_piyo | 0:bf96e953cdb8 | 4 | RS422 name(tx, rx) |
echo_piyo | 0:bf96e953cdb8 | 5 | tx : mbed_tx |
echo_piyo | 0:bf96e953cdb8 | 6 | rx : mbed_rx |
echo_piyo | 0:bf96e953cdb8 | 7 | |
echo_piyo | 0:bf96e953cdb8 | 8 | put(int id, float m1_duty, float m2_duty) |
echo_piyo | 0:bf96e953cdb8 | 9 | id : 0 - 254 |
echo_piyo | 0:bf96e953cdb8 | 10 | duty : -1.0 - 1.0 |
echo_piyo | 0:bf96e953cdb8 | 11 | |
echo_piyo | 0:bf96e953cdb8 | 12 | ****************/ |
echo_piyo | 0:bf96e953cdb8 | 13 | |
echo_piyo | 0:bf96e953cdb8 | 14 | |
echo_piyo | 0:bf96e953cdb8 | 15 | #define start_signal 0b11111111 |
echo_piyo | 0:bf96e953cdb8 | 16 | #define cool_time 0.0004 |
echo_piyo | 0:bf96e953cdb8 | 17 | |
echo_piyo | 0:bf96e953cdb8 | 18 | class RS422 |
echo_piyo | 0:bf96e953cdb8 | 19 | { |
echo_piyo | 0:bf96e953cdb8 | 20 | public : |
echo_piyo | 0:bf96e953cdb8 | 21 | RS422(PinName mbed_tx, PinName mbed_rx) : Rs422(mbed_tx,mbed_rx) { |
echo_piyo | 0:bf96e953cdb8 | 22 | } |
echo_piyo | 0:bf96e953cdb8 | 23 | |
echo_piyo | 0:bf96e953cdb8 | 24 | void begin(int baudrate) { |
echo_piyo | 0:bf96e953cdb8 | 25 | Rs422.baud(baudrate); |
echo_piyo | 0:bf96e953cdb8 | 26 | timer.attach(this, &RS422::put_time, cool_time); |
echo_piyo | 0:bf96e953cdb8 | 27 | } |
echo_piyo | 0:bf96e953cdb8 | 28 | |
echo_piyo | 0:bf96e953cdb8 | 29 | void put(int id, float m1_duty, float m2_duty) { |
echo_piyo | 0:bf96e953cdb8 | 30 | if (flag == 0) { |
echo_piyo | 0:bf96e953cdb8 | 31 | ID = id; |
echo_piyo | 0:bf96e953cdb8 | 32 | if (m1_duty < 0) { |
echo_piyo | 0:bf96e953cdb8 | 33 | m1_data = 0b10000000; |
echo_piyo | 0:bf96e953cdb8 | 34 | } else { |
echo_piyo | 0:bf96e953cdb8 | 35 | m1_data = 0; |
echo_piyo | 0:bf96e953cdb8 | 36 | } |
echo_piyo | 0:bf96e953cdb8 | 37 | if (m2_duty < 0) { |
echo_piyo | 0:bf96e953cdb8 | 38 | m2_data = 0b10000000; |
echo_piyo | 0:bf96e953cdb8 | 39 | } else { |
echo_piyo | 0:bf96e953cdb8 | 40 | m2_data = 0; |
echo_piyo | 0:bf96e953cdb8 | 41 | } |
echo_piyo | 0:bf96e953cdb8 | 42 | m1_data += fabs(m1_duty) * 100; |
echo_piyo | 0:bf96e953cdb8 | 43 | m2_data += fabs(m2_duty) * 100; |
echo_piyo | 0:bf96e953cdb8 | 44 | |
echo_piyo | 0:bf96e953cdb8 | 45 | check_sum = (id + m1_data + m2_data) & 0b01111111; |
echo_piyo | 0:bf96e953cdb8 | 46 | } |
echo_piyo | 0:bf96e953cdb8 | 47 | flag = 1; |
echo_piyo | 0:bf96e953cdb8 | 48 | } |
echo_piyo | 0:bf96e953cdb8 | 49 | |
echo_piyo | 0:bf96e953cdb8 | 50 | private : |
echo_piyo | 0:bf96e953cdb8 | 51 | Serial Rs422; |
echo_piyo | 0:bf96e953cdb8 | 52 | Ticker timer; |
echo_piyo | 0:bf96e953cdb8 | 53 | |
echo_piyo | 0:bf96e953cdb8 | 54 | short flag; |
echo_piyo | 0:bf96e953cdb8 | 55 | int counter; |
echo_piyo | 0:bf96e953cdb8 | 56 | int m1_data,m2_data,check_sum; |
echo_piyo | 0:bf96e953cdb8 | 57 | int ID; |
echo_piyo | 0:bf96e953cdb8 | 58 | |
echo_piyo | 0:bf96e953cdb8 | 59 | void put_time() { |
echo_piyo | 0:bf96e953cdb8 | 60 | switch (counter) { |
echo_piyo | 0:bf96e953cdb8 | 61 | case 0 : |
echo_piyo | 0:bf96e953cdb8 | 62 | Rs422.putc(start_signal); |
echo_piyo | 0:bf96e953cdb8 | 63 | break; |
echo_piyo | 0:bf96e953cdb8 | 64 | case 1 : |
echo_piyo | 0:bf96e953cdb8 | 65 | Rs422.putc(ID); |
echo_piyo | 0:bf96e953cdb8 | 66 | break; |
echo_piyo | 0:bf96e953cdb8 | 67 | case 2 : |
echo_piyo | 0:bf96e953cdb8 | 68 | Rs422.putc(m1_data); |
echo_piyo | 0:bf96e953cdb8 | 69 | break; |
echo_piyo | 0:bf96e953cdb8 | 70 | case 3 : |
echo_piyo | 0:bf96e953cdb8 | 71 | Rs422.putc(m2_data); |
echo_piyo | 0:bf96e953cdb8 | 72 | break; |
echo_piyo | 0:bf96e953cdb8 | 73 | case 4 : |
echo_piyo | 0:bf96e953cdb8 | 74 | Rs422.putc(check_sum); |
echo_piyo | 0:bf96e953cdb8 | 75 | break; |
echo_piyo | 0:bf96e953cdb8 | 76 | default : |
echo_piyo | 0:bf96e953cdb8 | 77 | break; |
echo_piyo | 0:bf96e953cdb8 | 78 | } |
echo_piyo | 0:bf96e953cdb8 | 79 | counter ++; |
echo_piyo | 0:bf96e953cdb8 | 80 | if(counter >= 5) { |
echo_piyo | 0:bf96e953cdb8 | 81 | counter = 0; |
echo_piyo | 0:bf96e953cdb8 | 82 | flag = 0; |
echo_piyo | 0:bf96e953cdb8 | 83 | } |
echo_piyo | 0:bf96e953cdb8 | 84 | } |
echo_piyo | 0:bf96e953cdb8 | 85 | }; |