Skip to content

Commit 3519ab3

Browse files
committed
Start support for Turret
Starting support for turret (Pan/Tilt). Currently using right joystick in special mode (use R2 button to choose walk mode). Also fix Commander Input such that right joystick is actually right joystick, dito left. Also added code to AX12 driver, that if the robot is not walking it plays with the LEDs on the servos such that hopefully I will not forget to turn power off. Also I set Digital servo pin 7 high, that I use to enable an LED display.
1 parent f9aa1fc commit 3519ab3

File tree

5 files changed

+410
-242
lines changed

5 files changed

+410
-242
lines changed

Hex_Cfg.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@
132132
#define cLFFemurPin 3 //Front Left leg Hip Vertical
133133
#define cLFTibiaPin 5 //Front Left leg Knee
134134

135+
#define cTurretRotPin 20 // Turret Rotate Pin
136+
#define cTurretTiltPin 21 // Turret Tilt pin
135137

136138
//--------------------------------------------------------------------
137139
//[MIN/MAX ANGLES] - Start off assume same as Phoenix...
@@ -177,6 +179,11 @@
177179
#define cLFTibiaMin1 -1020
178180
#define cLFTibiaMax1 670
179181

182+
#define cTurretRotMin1 -1500
183+
#define cTurretRotMax1 1500
184+
#define cTurretTiltMin1 -125
185+
#define cTurretTiltMax1 1100
186+
180187
//--------------------------------------------------------------------
181188
//[Joint offsets]
182189
// This allows us to calibrate servos to some fixed position, and then adjust them by moving theim
@@ -293,6 +300,12 @@ extern const byte g_abHexMaxBodyY[] PROGMEM;
293300
#define cLFInitPosX CHexInitXZCos60 //Start positions of the Left Front leg
294301
#define cLFInitPosY CHexInitY
295302
#define cLFInitPosZ -CHexInitXZSin60
303+
304+
// Turret initial position
305+
#define cTurretRotInit 0
306+
#define cTurretTiltInit 0
307+
308+
296309
//--------------------------------------------------------------------
297310
//[Tars factors used in formula to calc Tarsus angle relative to the ground]
298311
#define cTarsst 720 //4DOF ONLY
@@ -302,3 +315,4 @@ extern const byte g_abHexMaxBodyY[] PROGMEM;
302315
#define cTarsFactorC 50 //4DOF ONLY
303316

304317
#endif // HEX_CFG_H
318+

_Phoenix.h

Lines changed: 89 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
//
55
//Programmer: Jeroen Janssen [aka Xan]
66
// 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!
88
//
99
// This version of the Phoenix code was ported over to the Arduino Environement
1010
//
1111
//
1212
// 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.
1414
//
1515
//
1616
// This file assumes that the main source file either directly or through include
@@ -29,17 +29,17 @@
2929
#include <stdarg.h>
3030
//#include <EEPROM.h>
3131
#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))
3434
// #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))
3838
// #define pgm_read_word_near(x) (*((short *)(x & 0xfffffffe))
3939
// #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
4343
#endif
4444

4545
#ifdef USEXBEE
@@ -50,27 +50,29 @@
5050
//[CONSTANTS]
5151
//=============================================================================
5252
#define BUTTON_DOWN 0
53-
#define BUTTON_UP 1
53+
#define BUTTON_UP 1
5454

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
5959

6060
#ifdef QUADMODE
61-
enum {cRR=0, cRF, cLR, cLF, CNT_LEGS};
61+
enum {
62+
cRR=0, cRF, cLR, cLF, CNT_LEGS};
6263
#else
63-
enum {cRR=0, cRM, cRF, cLR, cLM, cLF, CNT_LEGS};
64+
enum {
65+
cRR=0, cRM, cRF, cLR, cLM, cLF, CNT_LEGS};
6466
#endif
6567

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 //
6870
#define USEINT_TIMERAV
6971

7072

7173
// 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
7476
extern void GaitSelect(void);
7577
extern short SmoothControl (short CtrlMoveInp, short CtrlMoveOut, byte CtrlDivider);
7678

@@ -124,10 +126,10 @@ extern SoftwareSerial SSCSerial;
124126
#endif
125127
#endif
126128
#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)
131133
#endif
132134

133135

@@ -139,12 +141,13 @@ extern SoftwareSerial SSCSerial;
139141
//=============================================================================
140142
class InputController {
141143
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);
145147

146148
private:
147-
} ;
149+
}
150+
;
148151

149152
// Define a function that allows us to define which controllers are to be used.
150153
extern void RegisterInputController(InputController *pic);
@@ -155,33 +158,35 @@ typedef struct _Coord3D {
155158
long x;
156159
long y;
157160
long z;
158-
} COORD3D;
161+
}
162+
COORD3D;
159163

160164
//==============================================================================
161165
// Define Gait structure/class - Hopefully allow specific robots to define their
162166
// own gaits and/or define which of the standard ones they want.
163167
//==============================================================================
164168
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.
172176

173177
#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
179183
#endif
180-
byte GaitLegNr[CNT_LEGS]; //Init position of the leg
184+
byte GaitLegNr[CNT_LEGS]; //Init position of the leg
181185
#ifdef DISPLAY_GAIT_NAMES
182-
PGM_P pszName; // The gait name
186+
PGM_P pszName; // The gait name
183187
#endif
184-
} PHOENIXGAIT;
188+
}
189+
PHOENIXGAIT;
185190

186191
#ifdef DISPLAY_GAIT_NAMES
187192
#define GATENAME(name) ,name
@@ -195,8 +200,8 @@ typedef struct _PhoenixGait {
195200
// requested.
196201
//==============================================================================
197202
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
200205
//Body position
201206
COORD3D BodyPos;
202207
COORD3D BodyRotOffset; // Body rotation offset;
@@ -205,34 +210,41 @@ typedef struct _InControlState {
205210
COORD3D BodyRot1; // X -Pitch, Y-Rotation, Z-Roll
206211

207212
//[gait]
208-
byte GaitType; //Gait type
213+
byte GaitType; //Gait type
209214
byte GaitStep; //Actual current step in gait
210215
PHOENIXGAIT gaitCur; // Definition of the current gait
211216

212-
short LegLiftHeight; //Current Travel height
217+
short LegLiftHeight; //Current Travel height
213218
COORD3D TravelLength; // X-Z or Length, Y is rotation.
214219

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+
215226
//[Single Leg Control]
216-
byte SelectedLeg;
227+
byte SelectedLeg;
217228
COORD3D SLLeg; //
218-
boolean fSLHold; //Single leg control mode
229+
boolean fSLHold; //Single leg control mode
219230

220231

221232
//[Balance]
222233
boolean BalanceMode;
223234

224235
//[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
227238
byte ForceGaitStepCnt; // new to allow us to force a step even when not moving
228-
239+
229240
#ifdef ADJUSTABLE_LEG_ANGLES
230241
short aCoxaInitAngle1[CNT_LEGS];
231242
#endif
232243

233244
//
234-
235-
} INCONTROLSTATE;
245+
246+
}
247+
INCONTROLSTATE;
236248

237249
//==============================================================================
238250
//==============================================================================
@@ -243,32 +255,41 @@ class ServoDriver {
243255
public:
244256
void Init(void);
245257

246-
word GetBatteryVoltage(void);
258+
word GetBatteryVoltage(void);
247259

248260
#ifdef OPT_GPPLAYER
249-
inline boolean FIsGPEnabled(void) {return _fGPEnabled;};
261+
inline boolean FIsGPEnabled(void) {
262+
return _fGPEnabled;
263+
};
250264
boolean FIsGPSeqDefined(uint8_t iSeq);
251-
inline boolean FIsGPSeqActive(void) {return _fGPActive;};
265+
inline boolean FIsGPSeqActive(void) {
266+
return _fGPActive;
267+
};
252268
void GPStartSeq(uint8_t iSeq); // 0xff - says to abort...
253269
void GPPlayer(void);
254270
uint8_t GPNumSteps(void); // How many steps does the current sequence have
255271
uint8_t GPCurStep(void); // Return which step currently on...
256272
void GPSetSpeedMultiplyer(short sm) ; // Set the Speed multiplier (100 is default)
257273
#endif
258-
void BeginServoUpdate(void); // Start the update
274+
void BeginServoUpdate(void); // Start the update
259275
#ifdef c4DOF
260276
void OutputServoInfoForLeg(byte LegIndex, short sCoxaAngle1, short sFemurAngle1, short sTibiaAngle1, short sTarsAngle1);
261277
#else
262278
void OutputServoInfoForLeg(byte LegIndex, short sCoxaAngle1, short sFemurAngle1, short sTibiaAngle1);
263279
#endif
280+
#ifdef cTurretRotPin
281+
void OutputServoInfoForTurret(short sRotateAngle1, short sTiltAngle1);
282+
#endif
264283
void CommitServoDriver(word wMoveTime);
265284
void FreeServos(void);
285+
286+
void IdleTime(void); // called when the main loop when the robot is not on
266287

267-
// Allow for background process to happen...
288+
// Allow for background process to happen...
268289
#ifdef OPT_BACKGROUND_PROCESS
269290
void BackgroundProcess(void);
270291
#endif
271-
292+
272293
#ifdef OPT_TERMINAL_MONITOR
273294
void ShowTerminalCommandList(void);
274295
boolean ProcessTerminalCommand(byte *psz, byte bLen);
@@ -280,10 +301,11 @@ class ServoDriver {
280301
boolean _fGPEnabled; // IS GP defined for this servo driver?
281302
boolean _fGPActive; // Is a sequence currently active - May change later when we integrate in sequence timing adjustment code
282303
uint8_t _iSeq; // current sequence we are running
283-
short _sGPSM; // Speed multiplier +-200
304+
short _sGPSM; // Speed multiplier +-200
284305
#endif
285306

286-
} ;
307+
}
308+
;
287309

288310
//==============================================================================
289311
//==============================================================================
@@ -292,8 +314,10 @@ class ServoDriver {
292314
//==============================================================================
293315
extern ServoDriver g_ServoDriver; // our global servo driver class
294316
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
296318

297319

298320
#endif
299321

322+
323+

0 commit comments

Comments
 (0)