4
4
//
5
5
// Programmer: Jeroen Janssen [aka Xan]
6
6
// Kurt Eckhardt(KurtE) converted to C and Arduino
7
- // Kåre Halvorsen aka Zenta - Makes everything work correctly!
7
+ // K�re Halvorsen aka Zenta - Makes everything work correctly!
8
8
//
9
9
// This version of the Phoenix code was ported over to the Arduino Environement
10
10
//
11
11
//
12
12
// Phoenix.h - This is the first header file that is needed to build
13
- // a Phoenix program for a specific Hex Robot.
13
+ // a Phoenix program for a specific Hex Robot.
14
14
//
15
15
//
16
16
// This file assumes that the main source file either directly or through include
29
29
#include < stdarg.h>
30
30
// #include <EEPROM.h>
31
31
#if defined(__SAM3X8E__)
32
- #define PROGMEM
33
- #define pgm_read_byte (x ) (*((char *)x))
32
+ #define PROGMEM
33
+ #define pgm_read_byte (x ) (*((char *)x))
34
34
// #define pgm_read_word(x) (*((short *)(x & 0xfffffffe)))
35
- #define pgm_read_word (x ) ( ((*((unsigned char *)x + 1 )) << 8 ) + (*((unsigned char *)x)))
36
- #define pgm_read_byte_near (x ) (*((char *)x))
37
- #define pgm_read_byte_far (x ) (*((char *)x))
35
+ #define pgm_read_word (x ) ( ((*((unsigned char *)x + 1 )) << 8 ) + (*((unsigned char *)x)))
36
+ #define pgm_read_byte_near (x ) (*((char *)x))
37
+ #define pgm_read_byte_far (x ) (*((char *)x))
38
38
// #define pgm_read_word_near(x) (*((short *)(x & 0xfffffffe))
39
39
// #define pgm_read_word_far(x) (*((short *)(x & 0xfffffffe)))
40
- #define pgm_read_word_near (x ) ( ((*((unsigned char *)x + 1 )) << 8 ) + (*((unsigned char *)x)))
41
- #define pgm_read_word_far (x ) ( ((*((unsigned char *)x + 1 )) << 8 ) + (*((unsigned char *)x))))
42
- #define PSTR (x ) x
40
+ #define pgm_read_word_near (x ) ( ((*((unsigned char *)x + 1 )) << 8 ) + (*((unsigned char *)x)))
41
+ #define pgm_read_word_far (x ) ( ((*((unsigned char *)x + 1 )) << 8 ) + (*((unsigned char *)x))))
42
+ #define PSTR (x ) x
43
43
#endif
44
44
45
45
#ifdef USEXBEE
50
50
// [CONSTANTS]
51
51
// =============================================================================
52
52
#define BUTTON_DOWN 0
53
- #define BUTTON_UP 1
53
+ #define BUTTON_UP 1
54
54
55
- #define c1DEC 10
56
- #define c2DEC 100
57
- #define c4DEC 10000
58
- #define c6DEC 1000000
55
+ #define c1DEC 10
56
+ #define c2DEC 100
57
+ #define c4DEC 10000
58
+ #define c6DEC 1000000
59
59
60
60
#ifdef QUADMODE
61
- enum {cRR=0 , cRF, cLR, cLF, CNT_LEGS};
61
+ enum {
62
+ cRR=0 , cRF, cLR, cLF, CNT_LEGS};
62
63
#else
63
- enum {cRR=0 , cRM, cRF, cLR, cLM, cLF, CNT_LEGS};
64
+ enum {
65
+ cRR=0 , cRM, cRF, cLR, cLM, cLF, CNT_LEGS};
64
66
#endif
65
67
66
- #define WTIMERTICSPERMSMUL 64 // BAP28 is 16mhz need a multiplyer and divider to make the conversion with /8192
67
- #define WTIMERTICSPERMSDIV 125 //
68
+ #define WTIMERTICSPERMSMUL 64 // BAP28 is 16mhz need a multiplyer and divider to make the conversion with /8192
69
+ #define WTIMERTICSPERMSDIV 125 //
68
70
#define USEINT_TIMERAV
69
71
70
72
71
73
// BUGBUG: to make Dynamic first pass simpl make it a variable.
72
- extern byte NUM_GAITS;
73
- #define SmDiv 4 // "Smooth division" factor for the smooth control function, a value of 3 to 5 is most suitable
74
+ extern byte NUM_GAITS;
75
+ #define SmDiv 4 // "Smooth division" factor for the smooth control function, a value of 3 to 5 is most suitable
74
76
extern void GaitSelect (void );
75
77
extern short SmoothControl (short CtrlMoveInp, short CtrlMoveOut, byte CtrlDivider);
76
78
@@ -124,10 +126,10 @@ extern SoftwareSerial SSCSerial;
124
126
#endif
125
127
#endif
126
128
#if defined(__PIC32MX__)
127
- #if defined F
128
- #undef F
129
- #endif
130
- #define F (X ) (X)
129
+ #if defined F
130
+ #undef F
131
+ #endif
132
+ #define F (X ) (X)
131
133
#endif
132
134
133
135
@@ -139,12 +141,13 @@ extern SoftwareSerial SSCSerial;
139
141
// =============================================================================
140
142
class InputController {
141
143
public:
142
- virtual void Init (void );
143
- virtual void ControlInput (void );
144
- virtual void AllowControllerInterrupts (boolean fAllow );
144
+ virtual void Init (void );
145
+ virtual void ControlInput (void );
146
+ virtual void AllowControllerInterrupts (boolean fAllow );
145
147
146
148
private:
147
- } ;
149
+ }
150
+ ;
148
151
149
152
// Define a function that allows us to define which controllers are to be used.
150
153
extern void RegisterInputController (InputController *pic);
@@ -155,33 +158,35 @@ typedef struct _Coord3D {
155
158
long x;
156
159
long y;
157
160
long z;
158
- } COORD3D;
161
+ }
162
+ COORD3D;
159
163
160
164
// ==============================================================================
161
165
// Define Gait structure/class - Hopefully allow specific robots to define their
162
166
// own gaits and/or define which of the standard ones they want.
163
167
// ==============================================================================
164
168
typedef struct _PhoenixGait {
165
- short NomGaitSpeed; // Nominal speed of the gait
166
- byte StepsInGait; // Number of steps in gait
167
- byte NrLiftedPos; // Number of positions that a single leg is lifted [1-3]
168
- byte FrontDownPos; // Where the leg should be put down to ground
169
- byte LiftDivFactor; // Normaly: 2, when NrLiftedPos=5: 4
170
- byte TLDivFactor; // Number of steps that a leg is on the floor while walking
171
- byte HalfLiftHeight; // How high to lift at halfway up.
169
+ short NomGaitSpeed; // Nominal speed of the gait
170
+ byte StepsInGait; // Number of steps in gait
171
+ byte NrLiftedPos; // Number of positions that a single leg is lifted [1-3]
172
+ byte FrontDownPos; // Where the leg should be put down to ground
173
+ byte LiftDivFactor; // Normaly: 2, when NrLiftedPos=5: 4
174
+ byte TLDivFactor; // Number of steps that a leg is on the floor while walking
175
+ byte HalfLiftHeight; // How high to lift at halfway up.
172
176
173
177
#ifdef QUADMODE
174
- // Extra information used in the Quad balance mode
175
- word COGAngleStart1; // COG shifting starting angle
176
- word COGAngleStep1; // COG Angle Steps in degrees
177
- byte COGRadius; // COG Radius; the amount the body shifts
178
- boolean COGCCW; // COG Gait sequence runs counter clock wise
178
+ // Extra information used in the Quad balance mode
179
+ word COGAngleStart1; // COG shifting starting angle
180
+ word COGAngleStep1; // COG Angle Steps in degrees
181
+ byte COGRadius; // COG Radius; the amount the body shifts
182
+ boolean COGCCW; // COG Gait sequence runs counter clock wise
179
183
#endif
180
- byte GaitLegNr[CNT_LEGS]; // Init position of the leg
184
+ byte GaitLegNr[CNT_LEGS]; // Init position of the leg
181
185
#ifdef DISPLAY_GAIT_NAMES
182
- PGM_P pszName; // The gait name
186
+ PGM_P pszName; // The gait name
183
187
#endif
184
- } PHOENIXGAIT;
188
+ }
189
+ PHOENIXGAIT;
185
190
186
191
#ifdef DISPLAY_GAIT_NAMES
187
192
#define GATENAME (name ) ,name
@@ -195,8 +200,8 @@ typedef struct _PhoenixGait {
195
200
// requested.
196
201
// ==============================================================================
197
202
typedef struct _InControlState {
198
- boolean fRobotOn ; // Switch to turn on Phoenix
199
- boolean fPrev_RobotOn ; // Previous loop state
203
+ boolean fRobotOn ; // Switch to turn on Phoenix
204
+ boolean fPrev_RobotOn ; // Previous loop state
200
205
// Body position
201
206
COORD3D BodyPos;
202
207
COORD3D BodyRotOffset; // Body rotation offset;
@@ -205,34 +210,41 @@ typedef struct _InControlState {
205
210
COORD3D BodyRot1; // X -Pitch, Y-Rotation, Z-Roll
206
211
207
212
// [gait]
208
- byte GaitType; // Gait type
213
+ byte GaitType; // Gait type
209
214
byte GaitStep; // Actual current step in gait
210
215
PHOENIXGAIT gaitCur; // Definition of the current gait
211
216
212
- short LegLiftHeight; // Current Travel height
217
+ short LegLiftHeight; // Current Travel height
213
218
COORD3D TravelLength; // X-Z or Length, Y is rotation.
214
219
220
+ #ifdef cTurretRotPin
221
+ // Turret information
222
+ int TurretRotAngle1; // Rotation of turrent in 10ths of degree
223
+ int TurretTiltAngle1; // the tile for the turret
224
+ #endif
225
+
215
226
// [Single Leg Control]
216
- byte SelectedLeg;
227
+ byte SelectedLeg;
217
228
COORD3D SLLeg; //
218
- boolean fSLHold ; // Single leg control mode
229
+ boolean fSLHold ; // Single leg control mode
219
230
220
231
221
232
// [Balance]
222
233
boolean BalanceMode;
223
234
224
235
// [TIMING]
225
- byte InputTimeDelay; // Delay that depends on the input to get the "sneaking" effect
226
- word SpeedControl; // Adjustible Delay
236
+ byte InputTimeDelay; // Delay that depends on the input to get the "sneaking" effect
237
+ word SpeedControl; // Adjustible Delay
227
238
byte ForceGaitStepCnt; // new to allow us to force a step even when not moving
228
-
239
+
229
240
#ifdef ADJUSTABLE_LEG_ANGLES
230
241
short aCoxaInitAngle1[CNT_LEGS];
231
242
#endif
232
243
233
244
//
234
-
235
- } INCONTROLSTATE;
245
+
246
+ }
247
+ INCONTROLSTATE;
236
248
237
249
// ==============================================================================
238
250
// ==============================================================================
@@ -243,32 +255,41 @@ class ServoDriver {
243
255
public:
244
256
void Init (void );
245
257
246
- word GetBatteryVoltage (void );
258
+ word GetBatteryVoltage (void );
247
259
248
260
#ifdef OPT_GPPLAYER
249
- inline boolean FIsGPEnabled (void ) {return _fGPEnabled;};
261
+ inline boolean FIsGPEnabled (void ) {
262
+ return _fGPEnabled;
263
+ };
250
264
boolean FIsGPSeqDefined (uint8_t iSeq);
251
- inline boolean FIsGPSeqActive (void ) {return _fGPActive;};
265
+ inline boolean FIsGPSeqActive (void ) {
266
+ return _fGPActive;
267
+ };
252
268
void GPStartSeq (uint8_t iSeq); // 0xff - says to abort...
253
269
void GPPlayer (void );
254
270
uint8_t GPNumSteps (void ); // How many steps does the current sequence have
255
271
uint8_t GPCurStep (void ); // Return which step currently on...
256
272
void GPSetSpeedMultiplyer (short sm) ; // Set the Speed multiplier (100 is default)
257
273
#endif
258
- void BeginServoUpdate (void ); // Start the update
274
+ void BeginServoUpdate (void ); // Start the update
259
275
#ifdef c4DOF
260
276
void OutputServoInfoForLeg (byte LegIndex, short sCoxaAngle1 , short sFemurAngle1 , short sTibiaAngle1 , short sTarsAngle1 );
261
277
#else
262
278
void OutputServoInfoForLeg (byte LegIndex, short sCoxaAngle1 , short sFemurAngle1 , short sTibiaAngle1 );
263
279
#endif
280
+ #ifdef cTurretRotPin
281
+ void OutputServoInfoForTurret (short sRotateAngle1 , short sTiltAngle1 );
282
+ #endif
264
283
void CommitServoDriver (word wMoveTime);
265
284
void FreeServos (void );
285
+
286
+ void IdleTime (void ); // called when the main loop when the robot is not on
266
287
267
- // Allow for background process to happen...
288
+ // Allow for background process to happen...
268
289
#ifdef OPT_BACKGROUND_PROCESS
269
290
void BackgroundProcess (void );
270
291
#endif
271
-
292
+
272
293
#ifdef OPT_TERMINAL_MONITOR
273
294
void ShowTerminalCommandList (void );
274
295
boolean ProcessTerminalCommand (byte *psz, byte bLen);
@@ -280,10 +301,11 @@ class ServoDriver {
280
301
boolean _fGPEnabled; // IS GP defined for this servo driver?
281
302
boolean _fGPActive; // Is a sequence currently active - May change later when we integrate in sequence timing adjustment code
282
303
uint8_t _iSeq; // current sequence we are running
283
- short _sGPSM; // Speed multiplier +-200
304
+ short _sGPSM; // Speed multiplier +-200
284
305
#endif
285
306
286
- } ;
307
+ }
308
+ ;
287
309
288
310
// ==============================================================================
289
311
// ==============================================================================
@@ -292,8 +314,10 @@ class ServoDriver {
292
314
// ==============================================================================
293
315
extern ServoDriver g_ServoDriver; // our global servo driver class
294
316
extern InputController g_InputController; // Our Input controller
295
- extern INCONTROLSTATE g_InControlState; // State information that controller changes
317
+ extern INCONTROLSTATE g_InControlState; // State information that controller changes
296
318
297
319
298
320
#endif
299
321
322
+
323
+
0 commit comments