-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathinitio.h
214 lines (156 loc) · 6.42 KB
/
initio.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
203
204
205
206
207
208
209
210
211
212
213
214
#ifndef _4TRONIX_INITIO_H_
#define _4TRONIX_INITIO_H_
//======================================================================
//
// C library to externalise all Initio/PiRoCon specific hardware
// author: Raimund Kirner, University of Hertfordshire
// initial version: Jun.2016 (support only for PiRoCon 2.0 board)
// updated version: Aug.2016 (added support for RoboHAT 1.0 board)
//
// license: GNU LESSER GENERAL PUBLIC LICENSE
// Version 2.1, February 1999
// (for details see LICENSE file)
//
//======================================================================
#include <wiringPi.h>
#include <softPwm.h>
#include <stdint.h> // Needed for int8_t
// When compiling you must include the followinglibraries: pthread, wiringPi:
// cc -o myprog myprog.c -lwiringPi -lpthread
// All pin numbers refer to the physical pin numbers on the P1 connector
// Define a boolean data type
#ifndef BOOL
#define BOOL int8_t
#endif
#ifndef TRUE
#define TRUE (1==1)
#endif
#ifndef FALSE
#define FALSE (0==1)
#endif
// Type of connected robot control board
#define UNKNOWN_HAT 0 // unknown HAT board connected
#define PIROCON2 1 // assumed PiRoCon board 2.0 (no HAT connected)
#define ROBOHAT 2 // RoboHAT board connected (uses different pins for: motors, ultrasonic)
// Define pins for platform motors (left motor: pin 19+21; right motor: pin 24+26)
#define L1_PiRoCon 19
#define L2_PiRoCon 21
#define R1_PiRoCon 24
#define R2_PiRoCon 26
#define L1_RoboHAT 36
#define L2_RoboHAT 35
#define R1_RoboHAT 33
#define R2_RoboHAT 32
#define wheelLeft 15 // Left Wheel sensor 1 (Optional)
#define wheelRight 16 // Right Wheel sensor 1 (Optional)
// Define pins for obstacle sensors and line sensors
#define irFL 7
#define irFR 11
#define lineLeft_PiRoCon 12
#define lineLeft_RoboHat 29
#define lineRight 13
// Define Sonar Pin (same pin for both Ping and Echo)
// Note, that this can be either 8 or 23 on PiRoCon
#define sonar_PiRoCon 8 // pin on PiRoCon board
#define sonar_RoboHAT 38 // pin on RoboHAT board
// Define logical Servo pins for Pan/Tilt
// (they are mapped to Port 1 pins 18 and 22)
#define servoPan 0
#define servoTilt 1
// Define Servo pins for Pan/Tilt
#define servoPanPin 18
#define servoTiltPin 22
//======================================================================
// General Functions
// initio_identifyControlBoard():
// Returns the type of the connected robot control board used for sensors/actuators
int initio_identifyControlBoard() ;
// initio_Init():
// Initialises GPIO pins, set physical pin numbering, switches motors off, etc
void initio_Init() ;
// initio_Cleanup():
// Sets all motors off and sets GPIO pins to standard values
void initio_Cleanup() ;
// initio_Version():
// Returns current version (decimal value).
float initio_Version() ;
// General Functions
//======================================================================
//======================================================================
// Motor Functions
// initio_Stop ():
// Stops both motors
void initio_Stop () ;
// initio_DriveForward (speed):
// Sets both motors to move forward at speed. 0 <= speed <= 100
void initio_DriveForward (int8_t speed) ;
// initio_DriveReverse (speed):
// Sets both motors to reverse at speed. 0 <= speed <= 100
void initio_DriveReverse (int8_t speed) ;
// initio_SpinLeft (speed):
// Sets motors to turn opposite directions at speed. 0 <= speed <= 100
void initio_SpinLeft (int8_t speed) ;
// initio_SpinRight(speed):
// Sets motors to turn opposite directions at speed. 0 <= speed <= 100
void initio_SpinRight(int8_t speed) ;
// initio_TurnForward (leftSpeed, rightSpeed):
// Moves forwards in an arc by setting different speeds. 0 <= leftSpeed,rightSpeed <= 100
void initio_TurnForward (int8_t leftSpeed, int8_t rightSpeed) ;
// initio_TurnReverse (leftSpeed, rightSpeed):
// Moves backwards in an arc by setting different speeds. 0 <= leftSpeed,rightSpeed <= 100
void initio_TurnReverse (int8_t leftSpeed, int8_t rightSpeed) ;
// End of Motor Functions
//======================================================================
//======================================================================
// Wheel Sensor Functions
// Note that the wheel sensor functions only indicate movement of the wheel but
// bot exact position indication. This is because the implementation assumes
// only one of the two phase-shifted signals per wheel to be connected.
// initio_wheelSensorLeft ():
// Returns the status of the left wheel position sensor connected to pin(wheelLeft).
BOOL initio_wheelSensorLeft (void) ;
// initio_wheelSensorRight ():
// Returns the status of the right wheel position sensor connected to pin(wheelRight).
BOOL initio_wheelSensorRight (void) ;
// End of Wheel Sensor Functions
//======================================================================
//======================================================================
// IR Sensor Functions
// initio_IrLeft():
// Returns whether Left IR Obstacle sensor is triggered
BOOL initio_IrLeft (void) ;
// initio_IrRight():
// Returns whether Right IR Obstacle sensor is triggered
BOOL initio_IrRight (void) ;
// initio_IrAll():
// Returns TRUE if at least one of the Obstacle sensors is triggered
BOOL initio_IrAll (void) ;
// initio_IrLineLeft():
// Returns whether Left IR Line sensor is triggered
BOOL initio_IrLineLeft (void) ;
// initio_IrLineRight():
// Returns whether Right IR Line sensor is triggered
BOOL initio_IrLineRight (void) ;
// End of IR Sensor Functions
//======================================================================
//======================================================================
// UltraSonic Functions
// initio_UsGetDistance():
// Returns the distance in cm to the nearest reflecting object. 0 == no object
unsigned int initio_UsGetDistance (void) ;
// End of UltraSonic Functions
//======================================================================
//======================================================================
// Servo Functions
// initio_StartServos ():
// Initialises the servo background process
void initio_StartServos (void) ;
// initio_StopServos ():
// Terminates the servo background process
void initio_StopServos (void) ;
// initio_SetServo (servo, degrees):
// Sets the servo to position in degrees -90 to +90
void initio_SetServo (int8_t servo, int8_t degrees) ;
// End of Servo Functions
//======================================================================
#endif /* _4TRONIX_INITIO_H_ */