Omni_2017_a

Dependencies:   mbed

Fork of Omni_2017_z by 広田 勇斗

Committer:
hirotayamato
Date:
Sat Aug 05 06:11:16 2017 +0000
Revision:
2:82c337a18500
Parent:
0:fd933ea5f19d
Omni_2017_a

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hirotayamato 2:82c337a18500 1 #include "2017_3_a.h"
hirotayamato 0:fd933ea5f19d 2 #include "mbed.h"
hirotayamato 0:fd933ea5f19d 3 #include <math.h>
hirotayamato 2:82c337a18500 4 #include "MD.h"
hirotayamato 0:fd933ea5f19d 5
hirotayamato 2:82c337a18500 6 Omni_3 Omni(p21, p22, p18, p17, p23, p24, p16, p15, p25, p26, p14, p13, 1);
hirotayamato 0:fd933ea5f19d 7
hirotayamato 0:fd933ea5f19d 8 Serial pc (USBTX, USBRX);
hirotayamato 0:fd933ea5f19d 9 I2CSlave slave(p9, p10);
hirotayamato 0:fd933ea5f19d 10
hirotayamato 0:fd933ea5f19d 11 DigitalOut check1(LED1);
hirotayamato 0:fd933ea5f19d 12
hirotayamato 0:fd933ea5f19d 13 union Get_data{
hirotayamato 0:fd933ea5f19d 14 char alldata[3];
hirotayamato 0:fd933ea5f19d 15 struct{
hirotayamato 0:fd933ea5f19d 16 signed int x :8;
hirotayamato 0:fd933ea5f19d 17 signed int y :8;
hirotayamato 0:fd933ea5f19d 18 signed int t :8;
hirotayamato 0:fd933ea5f19d 19 }data;
hirotayamato 0:fd933ea5f19d 20 }act;
hirotayamato 0:fd933ea5f19d 21
hirotayamato 0:fd933ea5f19d 22 int main() {
hirotayamato 0:fd933ea5f19d 23 Omni.Drive(0, 0, 0);
hirotayamato 0:fd933ea5f19d 24 float x, y, st;
hirotayamato 0:fd933ea5f19d 25
hirotayamato 0:fd933ea5f19d 26 slave.address(0x08);
hirotayamato 0:fd933ea5f19d 27 while(1) {
hirotayamato 0:fd933ea5f19d 28 int i = slave.receive();
hirotayamato 0:fd933ea5f19d 29 check1 = 0.0;
hirotayamato 0:fd933ea5f19d 30 switch (i) {
hirotayamato 0:fd933ea5f19d 31 case I2CSlave::ReadAddressed:
hirotayamato 0:fd933ea5f19d 32 check1 = check1 ^ 1;
hirotayamato 0:fd933ea5f19d 33 break;
hirotayamato 0:fd933ea5f19d 34 case I2CSlave::WriteGeneral:
hirotayamato 0:fd933ea5f19d 35 slave.read(act.alldata, 3);
hirotayamato 0:fd933ea5f19d 36 check1 = check1 ^ 1;
hirotayamato 0:fd933ea5f19d 37 break;
hirotayamato 0:fd933ea5f19d 38 case I2CSlave::WriteAddressed:
hirotayamato 0:fd933ea5f19d 39 slave.read(act.alldata, 3);
hirotayamato 0:fd933ea5f19d 40 check1 = check1 ^ 1;
hirotayamato 0:fd933ea5f19d 41 x = (float)act.data.x / 127.0;
hirotayamato 0:fd933ea5f19d 42 y = (float)act.data.y / 127.0;
hirotayamato 0:fd933ea5f19d 43 st = (float)act.data.t / 127.0 * 0.1;
hirotayamato 0:fd933ea5f19d 44 break;
hirotayamato 0:fd933ea5f19d 45 }
hirotayamato 0:fd933ea5f19d 46 Omni.Drive(x, y, st);
hirotayamato 0:fd933ea5f19d 47
hirotayamato 0:fd933ea5f19d 48 for(int i = 0; i < 3; i++) act.alldata[i] = 0;
hirotayamato 0:fd933ea5f19d 49
hirotayamato 0:fd933ea5f19d 50 }
hirotayamato 0:fd933ea5f19d 51 }
hirotayamato 2:82c337a18500 52