-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopen_interface.h
202 lines (160 loc) · 5.15 KB
/
open_interface.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*
* open_interface.h
*
* Contains all functionality to interface with the IRobot Create V2
* Communication over UART4 at 115200
*
* @author Noah Bergman
* @date 03/11/2016
*
*
*
*/
#ifndef OPEN_INTERFACE_H_
#define OPEN_INTERFACE_H_
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include "Timer.h"
#include <inc/tm4c123gh6pm.h>
#include "lcd.h"
#define M_PI 3.14159265358979323846
#define BIT0 0x01
#define BIT1 0x02
#define BIT2 0x04
#define BIT3 0x08
#define BIT4 0x10
#define BIT5 0x20
#define BIT6 0x40
#define BIT7 0x80
/// iRobot Create Sensor Data
typedef struct {
//Boolean sensor values
uint32_t wheelDropLeft : 1;
uint32_t wheelDropRight : 1;
uint32_t bumpLeft : 1;
uint32_t bumpRight : 1;
uint32_t cliffLeft : 1;
uint32_t cliffFrontLeft : 1;
uint32_t cliffFrontRight : 1;
uint32_t cliffRight : 1;
uint32_t lightBumperRight : 1;
uint32_t lightBumperFrontRight : 1;
uint32_t lightBumperCenterRight : 1;
uint32_t lightBumperCenterLeft : 1;
uint32_t lightBumperFrontLeft : 1;
uint32_t lightBumperLeft : 1;
uint32_t wallSensor : 1;
uint32_t virtualWall : 1;
uint32_t overcurrentLeftWheel : 1;
uint32_t overcurrentRightWheel : 1;
uint32_t overcurrentMainBrush : 1;
uint32_t overcurrentSideBrush : 1;
uint32_t buttonClock : 1;
uint32_t buttonSchedule : 1;
uint32_t buttonDay : 1;
uint32_t buttonHour : 1;
uint32_t buttonMinute : 1;
uint32_t buttonDock : 1;
uint32_t buttonSpot : 1;
uint32_t buttonClean : 1;
//Cliff sensors
uint16_t cliffLeftSignal;
uint16_t cliffFrontLeftSignal;
uint16_t cliffFrontRightSignal;
uint16_t cliffRightSignal;
//Light bump sensors
uint16_t lightBumpLeftSignal;
uint16_t lightBumpFrontLeftSignal;
uint16_t lightBumpCenterLeftSignal;
uint16_t lightBumpCenterRightSignal;
uint16_t lightBumpFrontRightSignal;
uint16_t lightBumpRightSignal;
//Misc sensors
uint16_t wallSignal;
uint8_t dirtDetect;
//Power
int16_t leftMotorCurrent;
int16_t rightMotorCurrent;
int16_t mainBrushMotorCurrent;
int16_t sideBrushMotorCurrent;
//Motion sensors
double distance;
double angle;
int8_t requestedVelocity;
int8_t requestedRadius;
int16_t requestedRightVelocity;
int16_t requestedLeftVelocity;
int16_t leftEncoderCount;
int16_t rightEncoderCount;
//Information from the infrared beacon sensors
char infraredCharOmni;
char infraredCharLeft;
char infraredCharRight;
//Battery information
uint8_t chargingState;
uint8_t chargingSourcesAvailable;
uint16_t batteryVoltage;
int16_t batteryCurrent;
uint8_t batteryTemperature;
uint16_t batteryCharge;
uint16_t batteryCapacity;
//Music
uint8_t songNumber;
uint8_t songPlaying;
//Misc
uint8_t oiMode;
uint8_t numberOfStreamPackets;
uint8_t stasis;
} oi_t;
///Allocate and clear all memory for OI Struct
oi_t * oi_alloc();
///Free memory from pointer to Open Interface Struct
void oi_free(oi_t *self);
///Initialize open interface
void oi_init(oi_t *self);
void oi_close();
///Update sensor data
void oi_update(oi_t *self);
/// \brief Set the LEDS on the Create
/// \param play_led 0=off, 1=on
/// \param advance_led 0=off, 1=on
/// \param power_color (0-255), 0=green, 255=red
/// \param power_intensity (0-255) 0=off, 255=full intensity
void oi_setLeds(uint8_t play_led, uint8_t advance_led, uint8_t power_color, uint8_t power_intensity);
/// \brief Set direction and speed of the robot's wheels
/// \param linear velocity in mm/s values range from -500 -> 500 of right wheel
/// \param linear velocity in mm/s values range from -500 -> 500 of left wheel
void oi_setWheels(int16_t right_wheel, int16_t left_wheel);
/// \brief Load song sequence
/// \param An integer value from 0 - 15 that acts as a label for note sequence
/// \param An integer value from 1 - 16 indicating the number of notes in the sequence
/// \param A pointer to a sequence of notes stored as integer values
/// \param A pointer to a sequence of durations that correspond to the notes
void oi_loadSong(int song_index, int num_notes, unsigned char *notes, unsigned char *duration);
/// \brief Play song
/// \param An integer value from 0 - 15 that is a previously establish song index
void oi_play_song(int index);
/// Calls in built in demo to send the iRobot to an open home base
/// This will cause the iRobot to enter the Passive state
void go_charge(void);
char* oi_checkFirmware();
//initializes interrupt and gpio to handle button press to end OI
void oi_shutoff_init(void);
//used to handle interrupt to shut off OI
void GPIOF_Handler(void);
//used to get the current moved degrees from encoder count
static double oi_getDegrees(oi_t *self);
// Get the number of radians moved since last call
static double oi_getRadians(oi_t *self);
// Gets the distance moved since the last call to getDistance
static double oi_getDistance(oi_t *self);
// Sets the calibration factor for the motors. Defualt is 1
void oi_setMotorCalibration(double left, double right);
// Gets the encoder calibration value for the left encoder
double oi_getMotorCalibrationLeft(void);
// Gets the encoder calibration for the right encoder
double oi_getMotorCalibrationRight(void);
#endif /* OPEN_INTERFACE_H_ */