![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
sra-romi
Dependencies: BufferedSerial Matrix
Communication.cpp@4:1defb279922a, 2021-05-11 (annotated)
- Committer:
- joaopsousa99
- Date:
- Tue May 11 18:10:22 2021 +0000
- Revision:
- 4:1defb279922a
- Parent:
- 1:dc87724abce8
as.djvblaskdvj
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fabiofaria | 1:dc87724abce8 | 1 | #include "Communication.h" |
fabiofaria | 1:dc87724abce8 | 2 | #include "mbed.h" |
fabiofaria | 1:dc87724abce8 | 3 | #include "MessageBuilder.h" |
fabiofaria | 1:dc87724abce8 | 4 | |
fabiofaria | 1:dc87724abce8 | 5 | const char max_len = 30; |
fabiofaria | 1:dc87724abce8 | 6 | Serial *serial_object; |
fabiofaria | 1:dc87724abce8 | 7 | MessageBuilder bin_msg; |
fabiofaria | 1:dc87724abce8 | 8 | |
fabiofaria | 1:dc87724abce8 | 9 | void init_communication(Serial *serial_in) |
fabiofaria | 1:dc87724abce8 | 10 | { |
fabiofaria | 1:dc87724abce8 | 11 | serial_object = serial_in; |
fabiofaria | 1:dc87724abce8 | 12 | } |
fabiofaria | 1:dc87724abce8 | 13 | |
fabiofaria | 1:dc87724abce8 | 14 | void write_bytes(char *ptr, unsigned char len) |
fabiofaria | 1:dc87724abce8 | 15 | { |
fabiofaria | 1:dc87724abce8 | 16 | for(int i=0; i<len; i++) |
fabiofaria | 1:dc87724abce8 | 17 | { |
fabiofaria | 1:dc87724abce8 | 18 | serial_object->putc(ptr[i]); |
fabiofaria | 1:dc87724abce8 | 19 | } |
fabiofaria | 1:dc87724abce8 | 20 | } |
fabiofaria | 1:dc87724abce8 | 21 | |
fabiofaria | 1:dc87724abce8 | 22 | void send_odometry(int value1, int value2, int ticks_left, int ticks_right, float x, float y, float theta) |
fabiofaria | 1:dc87724abce8 | 23 | { |
fabiofaria | 1:dc87724abce8 | 24 | bin_msg.reset(); |
fabiofaria | 1:dc87724abce8 | 25 | bin_msg.add('O'); |
fabiofaria | 1:dc87724abce8 | 26 | bin_msg.add(value1); |
fabiofaria | 1:dc87724abce8 | 27 | bin_msg.add(value2); |
fabiofaria | 1:dc87724abce8 | 28 | bin_msg.add(ticks_left); |
fabiofaria | 1:dc87724abce8 | 29 | bin_msg.add(ticks_right); |
fabiofaria | 1:dc87724abce8 | 30 | bin_msg.add(x); |
fabiofaria | 1:dc87724abce8 | 31 | bin_msg.add(y); |
fabiofaria | 1:dc87724abce8 | 32 | bin_msg.add(theta); |
fabiofaria | 1:dc87724abce8 | 33 | |
fabiofaria | 1:dc87724abce8 | 34 | write_bytes(bin_msg.message, bin_msg.length()); |
fabiofaria | 1:dc87724abce8 | 35 | } |