final project  1
open_interface.h
1 /*
2  * open_interface.h
3  *
4  * Contains all functionality to interface with the IRobot Create V2
5  * Communication over UART4 at 115200
6  *
7  * @author Noah Bergman
8  * @date 03/11/2016
9  *
10  *
11  *
12  */
13 
14 #ifndef OPEN_INTERFACE_H_
15 #define OPEN_INTERFACE_H_
16 
17 #define M_PI 3.14159265358979323846
18 
20 typedef struct {
21  //Boolean sensor values
22  uint32_t wheelDropLeft : 1;
23  uint32_t wheelDropRight : 1;
24  uint32_t bumpLeft : 1;
25  uint32_t bumpRight : 1;
26  uint32_t cliffLeft : 1;
27  uint32_t cliffFrontLeft : 1;
28  uint32_t cliffFrontRight : 1;
29  uint32_t cliffRight : 1;
30 
31  uint32_t lightBumperRight : 1;
32  uint32_t lightBumperFrontRight : 1;
33  uint32_t lightBumperCenterRight : 1;
34  uint32_t lightBumperCenterLeft : 1;
35  uint32_t lightBumperFrontLeft : 1;
36  uint32_t lightBumperLeft : 1;
37 
38  uint32_t wallSensor : 1;
39  uint32_t virtualWall : 1;
40 
41  uint32_t overcurrentLeftWheel : 1;
42  uint32_t overcurrentRightWheel : 1;
43  uint32_t overcurrentMainBrush : 1;
44  uint32_t overcurrentSideBrush : 1;
45 
46  uint32_t buttonClock : 1;
47  uint32_t buttonSchedule : 1;
48  uint32_t buttonDay : 1;
49  uint32_t buttonHour : 1;
50  uint32_t buttonMinute : 1;
51  uint32_t buttonDock : 1;
52  uint32_t buttonSpot : 1;
53  uint32_t buttonClean : 1;
54 
55  //Cliff sensors
56  uint16_t cliffLeftSignal;
57  uint16_t cliffFrontLeftSignal;
58  uint16_t cliffFrontRightSignal;
59  uint16_t cliffRightSignal;
60 
61  //Light bump sensors
62  uint16_t lightBumpLeftSignal;
63  uint16_t lightBumpFrontLeftSignal;
64  uint16_t lightBumpCenterLeftSignal;
65  uint16_t lightBumpCenterRightSignal;
66  uint16_t lightBumpFrontRightSignal;
67  uint16_t lightBumpRightSignal;
68 
69  //Misc sensors
70  uint16_t wallSignal;
71  uint8_t dirtDetect;
72 
73  //Power
74  int16_t leftMotorCurrent;
75  int16_t rightMotorCurrent;
76  int16_t mainBrushMotorCurrent;
77  int16_t sideBrushMotorCurrent;
78 
79  //Motion sensors
80  int16_t distance;
81  int16_t angle;
82  int8_t requestedVelocity;
83  int8_t requestedRadius;
84  int16_t requestedRightVelocity;
85  int16_t requestedLeftVelocity;
86  uint16_t leftEncoderCount; //here the encoder counts were made unsigned
87  uint16_t rightEncoderCount; //made unsigned
88 
89  //Information from the infrared beacon sensors
90  char infraredCharOmni;
91  char infraredCharLeft;
92  char infraredCharRight;
93 
94  //Battery information
95  uint8_t chargingState;
96  uint8_t chargingSourcesAvailable;
97  uint16_t batteryVoltage;
98  int16_t batteryCurrent;
99  uint8_t batteryTemperature;
100  uint16_t batteryCharge;
101  uint16_t batteryCapacity;
102 
103  //Music
104  uint8_t songNumber;
105  uint8_t songPlaying;
106 
107  //Misc
108  uint8_t oiMode;
109  uint8_t numberOfStreamPackets;
110  uint8_t stasis;
111 
112 } oi_t;
113 
114 
116 oi_t * oi_alloc();
117 
119 void oi_free(oi_t *self);
120 
121 
123 void oi_init(oi_t *self);
124 
125 void oi_close();
126 
128 void oi_update(oi_t *self);
129 
135 void oi_setLeds(uint8_t play_led, uint8_t advance_led, uint8_t power_color, uint8_t power_intensity);
136 
140 void oi_setWheels(int16_t right_wheel, int16_t left_wheel);
141 
142 
148 void oi_loadSong(int song_index, int num_notes, unsigned char *notes, unsigned char *duration);
149 
152 void oi_play_song(int index);
153 
156 void go_charge(void);
157 
158 char* oi_checkFirmware();
159 
160 //initializes interrupt and gpio to handle button press to end OI
161 void oi_shutoff_init(void);
162 
163 //used to handle interrupt to shut off OI
164 void GPIOF_Handler(void);
165 
166 //used to get the current moved degrees from encoder count
167 int getDegrees(oi_t *self);
168 
169 #endif /* OPEN_INTERFACE_H_ */
iRobot Create Sensor Data