ROBOCON 2019
Revision 0:a1405cc91cca, committed 2019-07-23
- Comitter:
- Ryosei
- Date:
- Tue Jul 23 07:16:58 2019 +0000
- Commit message:
- getting to the data from linetracehub by RS485
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
| mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Tue Jul 23 07:16:58 2019 +0000
@@ -0,0 +1,90 @@
+#include "mbed.h"
+
+Serial pc(USBTX,USBRX);
+Serial linehubuart(PA_9,PA_10);
+/*
+struct linedata {
+ unsigned int flont1:1;
+ unsigned int flont2:1;
+ unsigned int flont3:1;
+ unsigned int flont4:1;
+ unsigned int flont5:1;
+ unsigned int flont6:1;
+ unsigned int back1:1;
+ unsigned int back2:1;
+ unsigned int back3:1;
+ unsigned int back4:1;
+ unsigned int back5:1;
+ unsigned int back6:1;
+ unsigned int left1:1;
+ unsigned int left2:1;
+ unsigned int left3:1;
+ unsigned int left4:1;
+ unsigned int left5:1;
+ unsigned int left6:1;
+ unsigned int right1:1;
+ unsigned int right2:1;
+ unsigned int right3:1;
+ unsigned int right4:1;
+ unsigned int right5:1;
+ unsigned int right6:1;
+ unsigned int center1:1;
+ unsigned int center2:1;
+ unsigned int center3:1;
+ unsigned int center4:1;
+ unsigned int center5:1;
+ unsigned int center6:1;
+ unsigned int center7:1;
+ unsigned int center8:1;
+};
+struct linedata Linedata;
+*/
+void lineread(char buf[6])
+{
+ if(linehubuart.readable()) {
+ for(int i=0; i<=5; i++) {
+ buf[i]=linehubuart.getc();
+ }
+ }
+}
+
+void linedatacontrol(char buf[6],bool sentaku[48])
+{
+ for(int i=0; i<=47; i++) {
+ if(i<=7) {
+ sentaku[i]=((buf[0] << i) & 0b10000000)>>7;
+ } else if(i<=15) {
+ sentaku[i]=((buf[1] << i-8) & 0b10000000)>>7;
+ } else if(i<=23) {
+ sentaku[i]=((buf[2] << i-16) & 0b10000000)>>7;
+ } else if(i<=31) {
+ sentaku[i]=((buf[3] << i-24) & 0b10000000)>>7;
+ } else if(i<=39) {
+ sentaku[i]=((buf[4] << i-32) & 0b10000000)>>7;
+ } else if(i<=39) {
+ sentaku[i]=((buf[5] << i-40) & 0b10000000)>>7;
+ }
+ }
+}
+bool sinri[48];
+char data[6];
+DigitalOut LED(D3);
+int main()
+{
+ pc.baud(38400);
+ linehubuart.baud(38400);
+ for(int i=0; i<=47; i++) {
+ sinri[i]=0;
+ }
+ while(1) {
+ LED=0;
+ lineread(data);
+
+ linedatacontrol(data,sinri);
+
+ for(int i=0; i<=47; i++) {
+ pc.printf("%d",sinri[i]);
+ }
+ pc.printf("\n");
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Jul 23 07:16:58 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file