Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
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_fuzi by
RS422_put_.h
00001 /*************** 00002 RS422 master libraly 00003 00004 RS422 name(tx, rx) 00005 tx : mbed_tx 00006 rx : mbed_rx 00007 00008 put(int id, float m1_duty, float m2_duty) 00009 id : 0 - 254 00010 duty : -1.0 - 1.0 00011 00012 ****************/ 00013 00014 00015 #define start_signal 0b11111111 00016 #define cool_time 0.0004 00017 00018 class RS422 00019 { 00020 public : 00021 RS422(PinName mbed_tx, PinName mbed_rx) : Rs422(mbed_tx,mbed_rx) { 00022 } 00023 00024 void begin(int baudrate) { 00025 Rs422.baud(baudrate); 00026 timer.attach(this, &RS422::put_time, cool_time); 00027 } 00028 00029 void put(int id, float m1_duty, float m2_duty) { 00030 if (flag == 0) { 00031 ID = id; 00032 if (m1_duty < 0) { 00033 m1_data = 0b10000000; 00034 } else { 00035 m1_data = 0; 00036 } 00037 if (m2_duty < 0) { 00038 m2_data = 0b10000000; 00039 } else { 00040 m2_data = 0; 00041 } 00042 m1_data += fabs(m1_duty) * 100; 00043 m2_data += fabs(m2_duty) * 100; 00044 00045 check_sum = (id + m1_data + m2_data) & 0b01111111; 00046 } 00047 flag = 1; 00048 } 00049 00050 private : 00051 Serial Rs422; 00052 Ticker timer; 00053 00054 short flag; 00055 int counter; 00056 int m1_data,m2_data,check_sum; 00057 int ID; 00058 00059 void put_time() { 00060 switch (counter) { 00061 case 0 : 00062 Rs422.putc(start_signal); 00063 break; 00064 case 1 : 00065 Rs422.putc(ID); 00066 break; 00067 case 2 : 00068 Rs422.putc(m1_data); 00069 break; 00070 case 3 : 00071 Rs422.putc(m2_data); 00072 break; 00073 case 4 : 00074 Rs422.putc(check_sum); 00075 break; 00076 default : 00077 break; 00078 } 00079 counter ++; 00080 if(counter >= 5) { 00081 counter = 0; 00082 flag = 0; 00083 } 00084 } 00085 };
Generated on Mon Aug 8 2022 20:27:09 by
