BlackWido

Hi Xan,

As you know I’ve been working with your code. But there is one known bug I would like to be solved, its the >128 BodyPosY bug. I’ve not looked into it yet, but I’ve understood that it has something to do with the sbyte? Can it be solved by using sword or is it other thing that has to be solved first?

Do you have any idea of how you/we can solve it?

Hi,

Thanks! But the credit for the looms are for Zenta though :wink:

Hmmm… :confused: I really hope that the dimensions are right this time. I didn’t had a lot of options left for the lipo. They only had 3 suitable lipos that could fit in. a 1800mAh @ 11.1V which give me about 18 min but I could buy a couple for the same amount of money :wink: The second and best option was a 3300mAh @7.4V but it wasn’t in stock and I’ve been waiting for to long already! So that left me with the last option! On the hobbycity forum they called it a Cadillac so if it is gone fit, It sure is gone give me some power!! :smiling_imp:

And that’s a good thing :wink:

I already solved that bug some time ago. I did send a PM to James to solve the bug for the Phoenix tutorial. I forgot to post in here. Sry…

But anyway, you simply need to use a sword for the variable BodyPosY.

;Body position BodyPosX var sbyte ;Global Input for the position of the body BodyPosY var sword BodyPosZ var sbyte

The other thing that I mentioned in the mail was about the PS2 control. You have to see for yourself if you find it usefull.

I placed all the gaits in a switch so it is possible to switch between gaits by simply pressing the select button. I’ve been playing with the different gaits and noticed that some gaits need a different servospeed to get a more fluent movement. I’m still running some tests on this but right now I made the servospeed adjustable with the remote so see what it does. I’m planning to merge some gaits to get a compact code and make the servospeed different for each gait. I also want to try changing the servospeed corresponding to the joy. This should make it possible to “sneakâ€

I was refering to my latest modification to the BodyIK subroutine, I posted some info about in my Phoenix thread.

BTW, about your code. Maybe we should have one thread only dedicated for your code. I was thinking it would be easier for everyone to add and see all examples and suggestions for modifications? Just a thought… :unamused:

Oh, so that solved it all! :laughing:
Now your Phoenix can walk with a very high rised body, cool! Have to try it later to day.

Hi Zenta,

I know :wink:

I suppose that this thread formally was meant to discuss the code. But since my code isn’t just BlackWido’s code anymore it should be a good idea to start a new “phoenix codeâ€

hmm :confused: This didn’t solve the bug for me. All legs pumps right up twice when the BodyPosY value reached about 138. Strange… any idea? It also happens when I’m doing body rotating at high angle.

The problem with the BodyPosY was that if it reached 128 (which is the max of the byte) and add a number (+1) it will overflow to -127 (min value of the sbyte). Changing this value to a sword will increase the range to -32767 to 32768. When I did this, the bug was solved…

What do you mean by twice?

Xan

If it is near 128 you might be overflowing BodyPosX or BodyPosZ as these are sbyte and at 128 you are actually going negative… Can you simply change this to sword instead?

Kurt

Hi Kurt,

That’s what I thought in the beginning. BodyPosZ is dimensioned right after BodyPosY so if the Y overflows, it will overflow in Z. But I’ve tested it and 128 + 1 really makes -127 if you use a sbyte. :slight_smile:

thanks for participating in this!

Xan

Hi Xan and Kurt,

For the past 2 hours I’ve almost gone crazy about a mysterious bug. I had my Futaba RC receiver connected to P12,13,14,15 (RCch01,02,03,04).
Here is the code for the RCinput sub:

[code]RCInput:

pulsin RCch01,0, pwmInput01
pwmInput01  = (pwmInput01  min RCpwmMIN) max RCpwmMAX
BodyRotZ = (pwmInput01 -1500)/15
'TravelLengthX = (ZpwmInput -1500)/4	

pulsin RCch03,0, pwmInput03
pwmInput03  = (pwmInput03  min RCpwmMIN) max RCpwmMAX	
BodyPosY = (pwmInput03 -1150)/4	

pulsin RCch02,0, pwmInput02
pwmInput02  = (pwmInput02  min RCpwmMIN) max RCpwmMAX	
BodyRotX = -(pwmInput02 -1500)/15

pulsin RCch04,0, pwmInput04
pwmInput04  = (pwmInput04  min RCpwmMIN) max RCpwmMAX	
TravelRotationY = (pwmInput04 -1500)/14

return	[/code]

After some debugging I found that when the BodyPosY reached above the value 136, P12 and P14 (RCch01 and RCch03) suddenly returned the value 0. Very strange! :confused: :open_mouth:

I connected the RC receiver to pin P0,P1,P2 and P3 and I had no problem at all! And the BodyPosY could be as high as it wanted.

How can the BodyPosY affect the pin P12 and P14 :question:
Is it a bug in the code or a bug in the AtomPro?
Or are the P12 and P14 dedicated for only certain tasks? :unamused:
BTW I tried both my AtomPro 24 and 28, same bug.

If you want I can post the whole code/program.

Any idea what’s causing this?

Welcome to the world of embedded programming :slight_smile: I’ve got these kind of thing very often! Sry, I’m smiling right now because I’m not the only one struggling with this right now. Really I know how you feel! :slight_smile:

Maybe a stupid question but did you searched for P12 and P14 in the code to be sure that there are not used anywhere else. They are also used in the PS2 remote input…

Both the Atom 24 pro and 28 pro are based on the Hitatchi H8/3664F chip. I know that P14 is for the HSERIAL RXD (Interrupt driven serial). If you look at the end of the manual you see which pin is connected to which pin of the H8 (Page 187). You also could check that you didn’t use a wrote the total output block D to 0. (I’m just thinking out loud…) If you want to know more you need to check the manual of the H8 chip.
documentation.renesas.com/eng/pr … h83664.pdf
documentation.renesas.com/eng/pr … h8300h.pdf

If something will come up, I’ll let you know…

Xan

Welcome to BAP I/O programming. At least you got it figured out. It’s more fun when a seemingly arbitrary assignment for which I/O pin to use resets the controller for you. Been there, done that, put the t-shirt in the bottom of the toy drawer. GL moving forward, but at least you know it’s something to look out for.

Hi Xan and Zenta,

I have been following this thread all along. Would love to contribute more, but have been busy with house building. We now voluntered to do all of the interior wood finishing. 1 coat of benite, 2-3 coats of profin on all of the base boards, windows, doors and trim, etc. All while trying to dodge all of the subs… What little free time I have I have been playing with a propeller board and in the process of putting it on my rover. But back to to topic.

Not sure yet. I assume you are running the correct version of the IDE (8.0.1.7). Every other release since 8.0.0.0 had major problems with HSERVO, IO pins, Interupts, etc. This current one has been reasonsable. It might help to have the whole program to look at. I don’t have a phoenix yet (I should probably break down and get the pieces and temporarily steal the pieces from my main hex),

So not sure if I can help fully debug, but maybe could help localize down. I wonder how well this code would run on a different HEX? I could probably get my main hex working again. Need to put it’s brain back on… I also don’t have the futaba RC but do have the hitec one…

I think Xan mentioned most of the main points to look at. Things like do you have HSERIAL enabled? Do you have HSERVO enabled, etc. If the problem persists, it would be good if you could extract a minimal amount of code and put it into as simple a test program that demonstrates the problem. That helps to eliminate other possiblities and makes it easier for others to debug including AcidTech of basicmicro.

Got to run (more baseboards to work on)

Kurt

Hi EddieB,
:blush: Yep I’m a newbee when it comes to more advanced programming.
Everything that at first view looks logical and straight forward seem not to be that always :wink:

So what you are telling is that I’ve to stay away from these two pins? :unamused:

BTW, I didn’t understand “GL”… :confused:

Hi,

Thanks to you all for your support!

Ok, here is the complete code. This code works perfectly. But if you set the RCch01 -04 to P12 - P15, the BodyPosY bug starts:

[code];Project Lynxmotion Phoenix
;Description: “Phoenix” style bot controlled by a wii remote
;Software version: V1.1
;Date: 25-06-2008
;Programmer: Jeroen Janssen (aka Xan)
;
;Hardware setup: ABB2 with ATOM 28 Pro, SSC32, BlueSmirf (See further for connections)
;
;NEW IN V1.1
; - 6 steps Ripple Gait
; - Lynxmotion PS2 controller support
;
;KNOWN BUGS:
; - Synchronisation PS2 controller (for more information see: http://www.lynxmotion.net/viewtopic.php?t=3979&postdays=0&postorder=asc&start=0)
; - Maximum height of the body. If BodyY > 128 it will overflow and gets a negative value which causes the hex to drop down with the legs in the air.
;
;TODO:
; - Include Deadzone on the controls
; - Replace sin, cos, atan with a byte table to improve calculating speed
; - Replace All Floats with sword * 1000 to improve calculating speed and free some memory
; - Implement 12 steps Gait
; - Run some synchronisation tests
; - Include balance calculations
;
;--------------------------------------------------------------------
;[CONSTANDS]
TRUE con 1
FALSE con 0

BUTTON_DOWN con 0
BUTTON_UP con 1
;--------------------------------------------------------------------
;[SERIAL CONNECTIONS]
SSC_OUT con P11 ;Output pin for (SSC32 RX) on BotBoard (Yellow)
SSC_IN con P10 ;Input pin for (SSC32 TX) on BotBoard (Blue)
SSC_BAUTE con i38400 ;SSC32 Baute rate

;--------------------------------------------------------------------
;[RC Controller]
RCch01 con P0
RCch02 con P1
RCch03 con P2
RCch04 con P3

RCpwmMAX con 1850
RCpwmMIN con 1150

;--------------------------------------------------------------------
;[PIN NUMBERS]
RFCoxaPin con P8 ;Front Right leg Hip Horizontal
RFFemurPin con P9 ;Front Right leg Hip Vertical
RFTibiaPin con P10 ;Front Right leg Knee

RMCoxaPin con P4 ;Middle Right leg Hip Horizontal
RMFemurPin con P5 ;Middle Right leg Hip Vertical
RMTibiaPin con P6 ;Middle Right leg Knee

RRCoxaPin con P0 ;Rear Right leg Hip Horizontal
RRFemurPin con P1 ;Rear Right leg Hip Vertical
RRTibiaPin con P2 ;Rear Right leg Knee

LFCoxaPin con P24 ;Front Left leg Hip Horizontal
LFFemurPin con P25 ;Front Left leg Hip Vertical
LFTibiaPin con P26 ;Front Left leg Knee

LMCoxaPin con P20 ;Middle Left leg Hip Horizontal
LMFemurPin con P21 ;Middle Left leg Hip Vertical
LMTibiaPin con P22 ;Middle Left leg Knee

LRCoxaPin con P16 ;Rear Left leg Hip Horizontal
LRFemurPin con P17 ;Rear Left leg Hip Vertical
LRTibiaPin con P18 ;Rear Left leg Knee
;--------------------------------------------------------------------
;[SERVO Offsets]
RFCoxaOffset con 733 ;Front Right leg Hip Horizontal ;650+83
RFFemurOffset con 617 ;Front Right leg Hip Vertical ;650-33
RFTibiaOffset con 644 ;Front Right leg Knee ;650-6

RMCoxaOffset con 623 ;Middle Right leg Hip Horizontal ;650-27
RMFemurOffset con 629 ;Middle Right leg Hip Vertical ;650-21
RMTibiaOffset con 696 ;Middle Right leg Knee ;650+46

RRCoxaOffset con 649 ;Rear Right leg Hip Horizontal ;650-1
RRFemurOffset con 627 ;Rear Right leg Hip Vertical ;650-23
RRTibiaOffset con 619 ;Rear Right leg Knee ;650-31

LFCoxaOffset con 699 ;Front Left leg Hip Horizontal ;650+49
LFFemurOffset con 665 ;Front Left leg Hip Vertical ;650+15
LFTibiaOffset con 655 ;Front Left leg Knee ;650+5

LMCoxaOffset con 639 ;Middle Left leg Hip Horizontal ;650-11
LMFemurOffset con 599 ;Middle Left leg Hip Vertical ;650-51
LMTibiaOffset con 634 ;Middle Left leg Knee ;650-16

LRCoxaOffset con 593 ;Rear Left leg Hip Horizontal ;650-57
LRFemurOffset con 613 ;Rear Left leg Hip Vertical ;650-37
LRTibiaOffset con 614 ;Rear Left leg Knee ;650-36
;--------------------------------------------------------------------
;[MIN/MAX ANGLES]
RFCoxa_MIN con -90 ;Mechanical limits of the Right Front Leg
RFCoxa_MAX con 80
RFFemur_MIN con -92
RFFemur_MAX con 92
RFTibia_MIN con -104
RFTibia_MAX con 74

RMCoxa_MIN con -58 ;Mechanical limits of the Right Middle Leg
RMCoxa_MAX con 96
RMFemur_MIN con -92
RMFemur_MAX con 95
RMTibia_MIN con -105
RMTibia_MAX con 72

RRCoxa_MIN con -100 ;Mechanical limits of the Right Rear Leg
RRCoxa_MAX con 52
RRFemur_MIN con -96
RRFemur_MAX con 95
RRTibia_MIN con -96
RRTibia_MAX con 82

LFCoxa_MIN con -80 ;Mechanical limits of the Left Front Leg
LFCoxa_MAX con 95
LFFemur_MIN con -97
LFFemur_MAX con 96
LFTibia_MIN con -81
LFTibia_MAX con 104

LMCoxa_MIN con -95 ;Mechanical limits of the Left Middle Leg
LMCoxa_MAX con 58
LMFemur_MIN con -94
LMFemur_MAX con 96
LMTibia_MIN con -81
LMTibia_MAX con 102

LRCoxa_MIN con -100 ;Mechanical limits of the Left Rear Leg
LRCoxa_MAX con 50
LRFemur_MIN con -96
LRFemur_MAX con 94
LRTibia_MIN con -82
LRTibia_MAX con 100
;--------------------------------------------------------------------
;[BODY DIMENSIONS]
CoxaLength con 29 ;Length of the Coxa [mm]
FemurLength con 76 ;Length of the Femur [mm]
TibiaLength con 106 ;Lenght of the Tibia [mm]

RFOffsetX con -43 ;Distance X from center of the body to the Right Front coxa
RFOffsetZ con -82 ;Distance Z from center of the body to the Right Front coxa
RMOffsetX con -63 ;Distance X from center of the body to the Right Middle coxa
RMOffsetZ con 0 ;Distance Z from center of the body to the Right Middle coxa
RROffsetX con -43 ;Distance X from center of the body to the Right Rear coxa
RROffsetZ con 82 ;Distance Z from center of the body to the Right Rear coxa

LFOffsetX con 43 ;Distance X from center of the body to the Left Front coxa
LFOffsetZ con -82 ;Distance Z from center of the body to the Left Front coxa
LMOffsetX con 63 ;Distance X from center of the body to the Left Middle coxa
LMOffsetZ con 0 ;Distance Z from center of the body to the Left Middle coxa
LROffsetX con 43 ;Distance X from center of the body to the Left Rear coxa
LROffsetZ con 82 ;Distance Z from center of the body to the Left Rear coxa
;--------------------------------------------------------------------
;Start height const
StartYPos con 0
;Trip inhibit
TripInhibit con 3
;--------------------------------------------------------------------
;[ANGLES]
RFCoxaAngle var sword ;Actual Angle of the Right Front Leg
RFFemurAngle var sword
RFTibiaAngle var sword

RMCoxaAngle var sword ;Actual Angle of the Right Middle Leg
RMFemurAngle var sword
RMTibiaAngle var sword

RRCoxaAngle var sword ;Actual Angle of the Right Rear Leg
RRFemurAngle var sword
RRTibiaAngle var sword

LFCoxaAngle var sword ;Actual Angle of the Left Front Leg
LFFemurAngle var sword
LFTibiaAngle var sword

LMCoxaAngle var sword ;Actual Angle of the Left Middle Leg
LMFemurAngle var sword
LMTibiaAngle var sword

LRCoxaAngle var sword ;Actual Angle of the Left Rear Leg
LRFemurAngle var sword
LRTibiaAngle var sword
;--------------------------------------------------------------------
;[POSITIONS]
RFPosX var sword ;Actual Position of the Right Front Leg
RFPosY var sword
RFPosZ var sword

RMPosX var sword ;Actual Position of the Right Middle Leg
RMPosY var sword
RMPosZ var sword

RRPosX var sword ;Actual Position of the Right Rear Leg
RRPosY var sword
RRPosZ var sword

LFPosX var sword ;Actual Position of the Left Front Leg
LFPosY var sword
LFPosZ var sword

LMPosX var sword ;Actual Position of the Left Middle Leg
LMPosY var sword
LMPosZ var sword

LRPosX var sword ;Actual Position of the Left Rear Leg
LRPosY var sword
LRPosZ var sword
;--------------------------------------------------------------------
;[INPUTS]
butA var bit
butB var bit
butC var bit

prev_butA var bit
prev_butB var bit
prev_butC var bit
;--------------------------------------------------------------------
;[OUTPUTS]
LedA var bit ;Red
LedB var bit ;Green
LedC var bit ;Orange
;--------------------------------------------------------------------
;[VARIABLES]
Index var byte ;Index used for freeing the servos
SSCDone var byte ;Char to check if SSC is done

;GetSinCos
AngleDeg var float ;Input Angle in degrees
ABSAngleDeg var float ;Absolute value of the Angle in Degrees
AngleRad var float ;Angle in Radian
sinA var float ;Output Sinus of the given Angle
cosA var float ;Output Cosinus of the given Angle
sinB var float ;Output Sinus of the given Angle
cosB var float ;Output Cosinus of the given Angle
sinG var float ;Output Sinus of the given Angle
cosG var float ;Output Cosinus of the given Angle

sinINT var word
cosINT var word
;GetBoogTan
BoogTanX var sword ;Input X
BoogTanY var sword ;Input Y
BoogTan var float ;Output BOOGTAN2(X/Y)

;Body position
BodyPosX var sword ;Global Input for the position of the body
BodyPosY var sword
BodyPosZ var sword

;Body Inverse Kinematics
BodyRotX var sword ;Global Input pitch of the body
BodyRotY var sword ;Global Input rotation of the body
BodyRotZ var sword ;Global Input roll of the body
PosX var sword ;Input position of the feet X
PosZ var sword ;Input position of the feet Z
PosY var sword ;Input position of the feet Y
RotationY var sbyte ;Input for rotation of a single feet for the gait
BodyOffsetX var sbyte ;Input Offset betweeen the body and Coxa X
BodyOffsetZ var sbyte ;Input Offset betweeen the body and Coxa Z
PitchY var sword ;PitchY offset, needs to be added to the BodyPosY
RollY var sword ;RollY offset, needs to be added to the BodyPosY
TotalX var sword ;Total X distance between the center of the body and the feet
TotalZ var sword ;Total Z distance between the center of the body and the feet
DistCenterBodyFeet var float ;Total distance between the center of the body and the feet
AngleCenterBodyFeetX var float ;Angle between the center of the body and the feet
BodyIKPosX var sword ;Output Position X of feet with Rotation
BodyIKPosY var sword ;Output Position Y of feet with Rotation
BodyIKPosZ var sword ;Output Position Z of feet with Rotation

;Leg Inverse Kinematics
IKFeetPosX var sword ;Input position of the Feet X
IKFeetPosY var sword ;Input position of the Feet Y
IKFeetPosZ var sword ;Input Position of the Feet Z
IKFeetPosXZ var sword ;Length between the coxa and feet
IKSW var float ;Length between shoulder and wrist
IKA1 var float ;Angle between SW line and the ground in rad
IKA2 var float ;?
IKSolution var bit ;Output true if the solution is possible
IKSolutionWarning var bit ;Output true if the solution is NEARLY possible
IKSolutionError var bit ;Output true if the solution is NOT possible
IKFemurAngle var sword ;Output Angle of Femur in degrees
IKTibiaAngle var sword ;Output Angle of Tibia in degrees
IKCoxaAngle var sword ;Output Angle of Coxa in degrees

;--------------------------------------------------------------------
;[GP player]
GPByte0 var Byte
GPByte1 var Byte
GPByte2 var Byte
GPByte3 var Byte
GPModeON var bit
GPIsPlaying var bit
;--------------------------------------------------------------------
;RC variable
pwmInput01 var word
pwmInput02 var word
pwmInput03 var word
pwmInput04 var word

RCtemp var sbyte
;[TEMP]
DebugOn var bit
;gait
LegLiftHeight var byte ;Current Travel height
TravelLengthX var sbyte ;Current Travel length X
TravelLengthZ var sbyte ;Current Travel length Z
TravelRotationY var sbyte ;Current Travel Rotation Y

GaitSpeed var nib ;Speed (Time) multiply factor
GaitStep var nib ;Global Input Gait step
GaitLegNr var nib ;Input Number of the leg
TravelMulti var sbyte ;Multiplier for the length of the step
Lastleg var bit ;True when it’s the last leg in one gait step
TLDivFactor var nib ;Travellength divide by factor depends of number of travelspteps in gait
NmbrOfStepInGait var nib ;Number of steps in one gait cycle
GaitMethod var bit ;Toogle between 6 step tripod and 9 step quadripple, so far just a bit

RFGaitLegNr var nib ;Gait number for leg in upper end position
RFGaitPosX var sbyte ;Relative position corresponding to the Gait
RFGaitPosY var sbyte
RFGaitPosZ var sbyte
RFGaitRotY var sbyte ;Relative rotation corresponding to the Gait

RMGaitLegNr var nib
RMGaitPosX var sbyte
RMGaitPosY var sbyte
RMGaitPosZ var sbyte
RMGaitRotY var sbyte

RRGaitLegNr var nib
RRGaitPosX var sbyte
RRGaitPosY var sbyte
RRGaitPosZ var sbyte
RRGaitRotY var sbyte

LFGaitLegNr var nib
LFGaitPosX var sbyte
LFGaitPosY var sbyte
LFGaitPosZ var sbyte
LFGaitRotY var sbyte

LMGaitLegNr var nib
LMGaitPosX var sbyte
LMGaitPosY var sbyte
LMGaitPosZ var sbyte
LMGaitRotY var sbyte

LRGaitLegNr var nib
LRGaitPosX var sbyte
LRGaitPosY var sbyte
LRGaitPosZ var sbyte
LRGaitRotY var sbyte

GaitPosX var sbyte ;In-/Output Pos X of feet
GaitPosY var sbyte ;In-/Output Pos Y of feet
GaitPosZ var sbyte ;In-/Output Pos Z of feet
GaitRotY var sbyte ;In-/Output Rotation Y of feet

;--------------------------------------------------------------------

;[INIT]
;Turning off all the leds
LedA = 0
LedB = 0
LedC = 0

'Feet Positions
RFPosX = 53 ;Start positions of the Right Front leg
RFPosY = StartYPos
RFPosZ = -91

RMPosX = 105 ;Start positions of the Right Middle leg
RMPosY = StartYPos
RMPosZ = 0

RRPosX = 53 ;Start positions of the Right Rear leg
RRPosY = StartYPos
RRPosZ = 91

LFPosX = 53 ;Start positions of the Left Front leg
LFPosY = StartYPos
LFPosZ = -91

LMPosX = 105 ;Start positions of the Left Middle leg
LMPosY = StartYPos
LMPosZ = 0

LRPosX = 53 ;Start positions of the Left Rear leg
LRPosY = StartYPos
LRPosZ = 91

;Body Positions
BodyPosX = 0
BodyPosY = 0
BodyPosZ = 0

;Body Rotations
BodyRotX = 0
BodyRotY = 0
BodyRotZ = 0

;Gait
LegLiftHeight = 50
GaitStep = 1
GaitSpeed = 5

;Initate with a 9 step quadripple gait
'GaitMethod = TRUE
TLDivFactor = 6
NmbrOfStepInGait = 9
LRGaitLegNr = 1
RFGaitLegNr = 2
LMGaitLegNr = 4
RRGaitLegNr = 5
LFGaitLegNr = 7
RMGaitLegNr = 8
;Initate 6 step tripod gait
'TLDivFactor = 3
'NmbrOfStepInGait = 6
'LRGaitLegNr = 4
'RFGaitLegNr = 1
'LMGaitLegNr = 1
'RRGaitLegNr = 1
'LFGaitLegNr = 4
'RMGaitLegNr = 4

;GP mode
GPModeON = FALSE
GPIsPlaying = FALSE

;--------------------------------------------------------------------
;[MAIN]
main:

gosub ReadButtons
gosub WriteLeds
gosub RCInput

if GPModeON=FALSE then
;Calculate Gait positions
LastLeg = FALSE
gosub Gait [LRGaitLegNr, LRGaitPosX, LRGaitPosY, LRGaitPosZ, LRGaitRotY]
LRGaitPosX = GaitPosX
LRGaitPosY = GaitPosY
LRGaitPosZ = GaitPosZ
LRGaitRotY = GaitRotY

gosub Gait [RFGaitLegNr, RFGaitPosX, RFGaitPosY, RFGaitPosZ, RFGaitRotY]
RFGaitPosX = GaitPosX
RFGaitPosY = GaitPosY
RFGaitPosZ = GaitPosZ
RFGaitRotY = GaitRotY
		
gosub Gait [LMGaitLegNr, LMGaitPosX, LMGaitPosY, LMGaitPosZ, LMGaitRotY]
LMGaitPosX = GaitPosX
LMGaitPosY = GaitPosY
LMGaitPosZ = GaitPosZ
LMGaitRotY = GaitRotY
	
gosub Gait [RRGaitLegNr, RRGaitPosX, RRGaitPosY, RRGaitPosZ, RRGaitRotY]
RRGaitPosX = GaitPosX
RRGaitPosY = GaitPosY
RRGaitPosZ = GaitPosZ
RRGaitRotY = GaitRotY
	
gosub Gait [LFGaitLegNr, LFGaitPosX, LFGaitPosY, LFGaitPosZ, LFGaitRotY]
LFGaitPosX = GaitPosX
LFGaitPosY = GaitPosY
LFGaitPosZ = GaitPosZ
LFGaitRotY = GaitRotY

LastLeg = TRUE
gosub Gait [RMGaitLegNr, RMGaitPosX, RMGaitPosY, RMGaitPosZ, RMGaitRotY]
RMGaitPosX = GaitPosX
RMGaitPosY = GaitPosY
RMGaitPosZ = GaitPosZ
RMGaitRotY = GaitRotY

'DebugOn = TRUE
;Right Front leg
gosub BodyIK -RFPosX+BodyPosX+RFGaitPosX, RFPosZ+BodyPosZ+RFGaitPosZ,RFPosY+BodyPosY+RFGaitPosY, RFOffsetX, RFOffsetZ, RFGaitRotY]
gosub LegIK [RFPosX-BodyPosX+BodyIKPosX-RFGaitPosX, RFPosY+BodyPosY-BodyIKPosY+RFGaitPosY, RFPosZ+BodyPosZ-BodyIKPosZ+RFGaitPosZ]	
RFCoxaAngle  = IKCoxaAngle + 60 ;60 degree for the basic setup for the front leg	
RFFemurAngle = IKFemurAngle
RFTibiaAngle = IKTibiaAngle
'DebugOn = False


;Right Middle leg
gosub BodyIK -RMPosX+BodyPosX+RMGaitPosX, RMPosZ+BodyPosZ+RMGaitPosZ,RMPosY+BodyPosY+RMGaitPosY, RMOffsetX, RMOffsetZ, RMGaitRotY]
gosub LegIK [RMPosX-BodyPosX+BodyIKPosX-RMGaitPosX, RMPosY+BodyPosY-BodyIKPosY+RMGaitPosY, RMPosZ+BodyPosZ-BodyIKPosZ+RMGaitPosZ]
RMCoxaAngle  = IKCoxaAngle
RMFemurAngle = IKFemurAngle
RMTibiaAngle = IKTibiaAngle	

;Right Rear leg
gosub BodyIK -RRPosX+BodyPosX+RRGaitPosX, RRPosZ+BodyPosZ+RRGaitPosZ,RRPosY+BodyPosY+RRGaitPosY, RROffsetX, RROffsetZ, RRGaitRotY]
gosub LegIK [RRPosX-BodyPosX+BodyIKPosX-RRGaitPosX, RRPosY+BodyPosY-BodyIKPosY+RRGaitPosY, RRPosZ+BodyPosZ-BodyIKPosZ+RRGaitPosZ]
RRCoxaAngle  = IKCoxaAngle - 60 ;60 degree for the basic setup for the front leg	
RRFemurAngle = IKFemurAngle
RRTibiaAngle = IKTibiaAngle

;Left Front leg
gosub BodyIK [LFPosX-BodyPosX+LFGaitPosX, LFPosZ+BodyPosZ+LFGaitPosZ,LFPosY+BodyPosY+LFGaitPosY, LFOffsetX, LFOffsetZ, LFGaitRotY]
gosub LegIK [LFPosX+BodyPosX-BodyIKPosX+LFGaitPosX, LFPosY+BodyPosY-BodyIKPosY+LFGaitPosY, LFPosZ+BodyPosZ-BodyIKPosZ+LFGaitPosZ]
LFCoxaAngle  = IKCoxaAngle + 60 ;60 degree for the basic setup for the front leg	
LFFemurAngle = IKFemurAngle
LFTibiaAngle = IKTibiaAngle

;Left Middle leg
gosub BodyIK [LMPosX-BodyPosX+LMGaitPosX, LMPosZ+BodyPosZ+LMGaitPosZ,LMPosY+BodyPosY+LMGaitPosY, LMOffsetX, LMOffsetZ, LMGaitRotY]
gosub LegIK [LMPosX+BodyPosX-BodyIKPosX+LMGaitPosX, LMPosY+BodyPosY-BodyIKPosY+LMGaitPosY, LMPosZ+BodyPosZ-BodyIKPosZ+LMGaitPosZ]
LMCoxaAngle  = IKCoxaAngle
LMFemurAngle = IKFemurAngle
LMTibiaAngle = IKTibiaAngle
		
;Left Rear leg
gosub BodyIK [LRPosX-BodyPosX+LRGaitPosX, LRPosZ+BodyPosZ+LRGaitPosZ,LRPosY+BodyPosY+LRGaitPosY, LROffsetX, LROffsetZ, LRGaitRotY]
gosub LegIK [LRPosX+BodyPosX-BodyIKPosX+LRGaitPosX, LRPosY+BodyPosY-BodyIKPosY+LRGaitPosY, LRPosZ+BodyPosZ-BodyIKPosZ+LRGaitPosZ]
LRCoxaAngle  = IKCoxaAngle - 60 ;60 degree for the basic setup for the front leg	
LRFemurAngle = IKFemurAngle
LRTibiaAngle = IKTibiaAngle

gosub CheckAngles
gosub ServoDriver

LedC = IKSolutionWarning
LedA = IKSolutionError

else
gosub GPPlayer
endif

goto main
;--------------------------------------------------------------------
;[ReadButtons] Reading input buttons from the ABB
ReadButtons:
input P4
input P5
input P6

prev_butA = butA
prev_butB = butB
prev_butC = butC

butA = IN4
butB = IN5
butC = IN6

return
;--------------------------------------------------------------------
;[WriteLEDs] Updates the state of the leds
WriteLEDs:
if ledA = 1 then
low p4
endif
if ledB = 1 then
low p5
endif
if ledC = 1 then
low p6
endif
return
;--------------------------------------------------------------------
;Read RC pulses and converts them to travellengths
;
RCInput:

pulsin RCch01,0, pwmInput01
pwmInput01  = (pwmInput01  min RCpwmMIN) max RCpwmMAX
BodyRotZ = (pwmInput01 -1500)/15
'TravelLengthX = (ZpwmInput -1500)/4	

pulsin RCch03,0, pwmInput03
pwmInput03  = (pwmInput03  min RCpwmMIN) max RCpwmMAX	
BodyPosY = (pwmInput03 -1150)/4	

pulsin RCch02,0, pwmInput02
pwmInput02  = (pwmInput02  min RCpwmMIN) max RCpwmMAX	
BodyRotX = -(pwmInput02 -1500)/15

pulsin RCch04,0, pwmInput04
pwmInput04  = (pwmInput04  min RCpwmMIN) max RCpwmMAX	
TravelRotationY = (pwmInput04 -1500)/14

'serout s_out, i9600, "BodyPosY=", sdec BodyPosY," TLZ=", sdec TravelLengthZ," TLX=", sdec TravelLengthX," TRY=", sdec TravelRotationY, 13]	
'serout s_out, i9600, "BodyPosY=", sdec BodyPosY," BodyRotZ=", sdec BodyRotZ," BodyRotX=", sdec BodyRotX," TRY=", sdec TravelRotationY, 13]	
'serout s_out, i9600, "CH01=", sdec pwmInput01," CH02=", sdec pwmInput02," CH03=", sdec pwmInput03," CH04=", sdec pwmInput04, 13]	

return
;--------------------------------------------------------------------
;[GAIT]
Gait [GaitLegNr, GaitPosX, GaitPosY, GaitPosZ, GaitRotY]

;Up start position:
IF (GaitStep=GaitLegNr+1) & ((ABS(TravelLengthX)>TripInhibit) | (ABS(TravelLengthZ)>TripInhibit) | (ABS(GaitPosX)>TripInhibit) | (ABS(GaitPosZ)>TripInhibit) | (ABS(GaitRotY)>TripInhibit)) THEN
  GaitPosX = TravelLengthX/2
  GaitPosY = -LegLiftHeight
  GaitPosZ = TravelLengthZ/2
  GaitRotY = TravelRotationY/2
ELSE
  ;Up end position:
  IF (GaitStep=GaitLegNr) & ((ABS(TravelLengthX)>TripInhibit) | (ABS(TravelLengthZ)>TripInhibit) | (ABS(GaitPosX)>TripInhibit) | (ABS(GaitPosZ)>TripInhibit) | (ABS(GaitRotY)>TripInhibit)) THEN
  GaitPosX = -TravelLengthX/2
  GaitPosY = -LegLiftHeight
  GaitPosZ = -TravelLengthZ/2
  GaitRotY = -TravelRotationY/2
  ELSE  
	;Down start position:
	IF (GaitStep=GaitLegNr+2 | GaitStep=GaitLegNr-7) & GaitPosY<0 THEN
	GaitPosX = TravelLengthX/2
	GaitPosY = 0
	GaitPosZ = TravelLengthZ/2
	GaitRotY = TravelRotationY/2

 	;just walk:   
	ELSE
	  GaitPosX = GaitPosX - (TravelLengthX/TLDivFactor)     
	  GaitPosY = 0
	  GaitPosZ = GaitPosZ - (TravelLengthZ/TLDivFactor)
	  GaitRotY = GaitRotY - (TravelRotationY/TLDivFactor)
	ENDIF	
  ENDIF
ENDIF 

;serout S_OUT, i9600, “GaitStep=”, sdec GaitStep, " LegNr=", sdec GaitLegNr, " TLZ=", sdec TravelLengthZ," Z=", sdec GaitPosZ, " TLX=", sdec TravelLengthX, " X=", sdec GaitPosX, " Y=", sdec GaitPosY,13]

;Advance to the next step
IF LastLeg THEN ;the last leg in this step (RM leg)
GaitStep = GaitStep+1
IF GaitStep>NmbrOfStepInGait THEN
GaitStep = 1
ENDIF
ENDIF

return
;--------------------------------------------------------------------
;[GETSINCOS] Get the sinus and cosinus from the angle +/- multiple circles
;AngleDeg - Input Angle in degrees
;sinA - Output Sinus of AngleDeg
;cosA - Output Cosinus of AngleDeg
GetSinCos [AngleDeg]

;Get the absolute value of AngleDeg
IF AngleDeg < 0.0 THEN
  ABSAngleDeg = AngleDeg *-1.0
ELSE
  ABSAngleDeg = AngleDeg
ENDIF

;Shift rotation to a full circle of 360 deg -> AngleDeg // 360
IF AngleDeg < 0.0 THEN	;Negative values
	AngleDeg = 360.0-(ABSAngleDeg-TOFLOAT(360*(TOINT(ABSAngleDeg/360.0))))
ELSE				;Positive values
	AngleDeg = ABSAngleDeg-TOFLOAT(360*(TOINT(ABSAngleDeg/360.0)))
ENDIF

IF AngleDeg < 180.0 THEN	;Angle between 0 and 180
	;Subtract 90 to shift range
	AngleDeg = AngleDeg -90.0
	;Convert degree to radials
	AngleRad = (AngleDeg*3.141592)/180.0
	
	sinA = FCOS(AngleRad)		;Sin o to 180 deg = cos(Angle Rad - 90deg)
	cosA = -FSIN(AngleRad)	;Cos 0 to 180 deg = -sin(Angle Rad - 90deg)
	
ELSE	;Angle between 180 and 360
	;Subtract 270 to shift range
	AngleDeg = AngleDeg -270.0
	;Convert degree to radials
	AngleRad = (AngleDeg*3.141592)/180.0
	
	sinA = -FCOS(AngleRad)		;Sin 180 to 360 deg = -cos(Angle Rad - 270deg)
	cosA = FSIN(AngleRad)	;Cos 180 to 360 deg = sin(Angle Rad - 270deg)
ENDIF

return
;--------------------------------------------------------------------
;[BOOGTAN2] Gets the Inverse Tangus from X/Y with the where Y can be zero or negative
;BoogTanX - Input X
;BoogTanY - Input Y
;BoogTan - Output BOOGTAN2(X/Y)
GetBoogTan [BoogTanX, BoogTanY]
IF(BoogTanX = 0) THEN ; X=0 -> 0 or PI
IF(BoogTanY >= 0) THEN
BoogTan = 0.0
ELSE
BoogTan = 3.141592
ENDIF
ELSE

	IF(BoogTanY = 0) THEN	; Y=0 -> +/- Pi/2
		IF(BoogTanX > 0) THEN
			BoogTan = 3.141592 / 2.0
		ELSE
			BoogTan = -3.141592 / 2.0
		ENDIF
	ELSE
		
		IF(BoogTanY > 0) THEN	;BOOGTAN(X/Y)
			BoogTan = FATAN(TOFLOAT(BoogTanX) / TOFLOAT(BoogTanY))
		ELSE	
			IF(BoogTanX > 0) THEN	;BOOGTAN(X/Y) + PI	
				BoogTan = FATAN(TOFLOAT(BoogTanX) / TOFLOAT(BoogTanY)) + 3.141592
			ELSE					;BOOGTAN(X/Y) - PI	
				BoogTan = FATAN(TOFLOAT(BoogTanX) / TOFLOAT(BoogTanY)) - 3.141592
			ENDIF
		ENDIF
	ENDIF
ENDIF

return
;--------------------------------------------------------------------
;[BODY INVERSE KINEMATICS]
;BodyRotX - Global Input pitch of the body
;BodyRotY - Global Input rotation of the body
;BodyRotZ - Global Input roll of the body
;RotationY - Input Rotation for the gait
;PosX - Input position of the feet X
;PosZ - Input position of the feet Z
;BodyOffsetX - Input Offset betweeen the body and Coxa X
;BodyOffsetZ - Input Offset betweeen the body and Coxa Z
;RollY - RollY offset, needs to be added to the BodyPosY
;PitchY - PitchY offset, needs to be added to the BodyPosY
;BodyIKPosX - Output Position X of feet with Rotation
;BodyIKPosY - Output Position Y of feet with Rotation
;BodyIKPosZ - Output Position Z of feet with Rotation
BodyIK [PosX, PosZ, PosY, BodyOffsetX, BodyOffsetZ, RotationY]

;Calculating totals from center of the body to the feet
TotalZ = BodyOffsetZ+PosZ
TotalX = BodyOffsetX+PosX
;PosY are equal to a “TotalY”

;Successive global rotation matrix:
;Math shorts for rotation: Alfa (A) = Xrotate, Beta (B) = Zrotate, Gamma (G) = Yrotate
;Sinus Alfa = sinA, cosinus Alfa = cosA. and so on…

;First calculate sinus and cosinus for each rotation:
gosub GetSinCos [TOFLOAT(BodyRotX)]
sinG = sinA
cosG = cosA
gosub GetSinCos [TOFLOAT(BodyRotZ)]
sinB = sinA
cosB = cosA
gosub GetSinCos [TOFLOAT(BodyRotY+RotationY)]

;Calcualtion of rotation matrix:
BodyIKPosX = TotalX-TOINT(TOFLOAT(TotalX)cosAcosB - TOFLOAT(TotalZ)cosBsinA + TOFLOAT(PosY)sinB)
BodyIKPosZ = TotalZ-TOINT(TOFLOAT(TotalX)cosGsinA + TOFLOAT(TotalX)cosAsinB
sinG +TOFLOAT(TotalZ)cosAcosG-TOFLOAT(TotalZ)sinAsinBsinG-TOFLOAT(PosY)cosBsinG)
BodyIKPosY = PosY - TOINT(TOFLOAT(TotalX)sinAsinG - TOFLOAT(TotalX)cosAcosG
sinB + TOFLOAT(TotalZ)cosAsinG + TOFLOAT(TotalZ)cosGsinA*sinB + TOFLOAT(PosY)cosBcosG)

return
;--------------------------------------------------------------------
;[LEG INVERSE KINEMATICS] Calculates the angles of the tibia and femur for the given position of the feet
;IKFeetPosX - Input position of the Feet X
;IKFeetPosY - Input position of the Feet Y
;IKFeetPosZ - Input Position of the Feet Z
;IKSolution - Output true if the solution is possible
;IKSolutionWarning - Output true if the solution is NEARLY possible
;IKSolutionError - Output true if the solution is NOT possible
;IKFemurAngle - Output Angle of Femur in degrees
;IKTibiaAngle - Output Angle of Tibia in degrees
;IKCoxaAngle - Output Angle of Coxa in degrees
LegIK [IKFeetPosX, IKFeetPosY, IKFeetPosZ]
;Reset all Solution options
IKSolution = FALSE
IKSolutionWarning = FALSE
IKSolutionError = FALSE

;Length between the Coxa and Feet
IKFeetPosXZ = TOINT(FSQRT(TOFLOAT((IKFeetPosX*IKFeetPosX)+(IKFeetPosZ*IKFeetPosZ))))

;IKSW - Length between shoulder and wrist
IKSW = FSQRT(TOFLOAT(((IKFeetPosXZ-CoxaLength)*(IKFeetPosXZ-CoxaLength))+(IKFeetPosY*IKFeetPosY)))
	
;IKA1 - Angle between SW line and the ground in rad
gosub GetBoogTan [IKFeetPosXZ-CoxaLength, IKFeetPosY]
IKA1 = BoogTan

;IKA2 - ?
IKA2 = FACOS((TOFLOAT((FemurLength*FemurLength) - (TibiaLength*TibiaLength)) + (IKSW*IKSW)) / (TOFLOAT(2*Femurlength) * IKSW))

;IKFemurAngle
IKFemurAngle = (TOINT(((IKA1 + IKA2) * 180.0) / 3.141592)*-1)+90

;IKTibiaAngle
IKTibiaAngle = (90-TOINT(((FACOS((TOFLOAT((FemurLength*FemurLength) + (TibiaLength*TibiaLength)) - (IKSW*IKSW)) / TOFLOAT(2*Femurlength*TibiaLength)))*180.0) / 3.141592)) * -1

;IKCoxaAngle
gosub GetBoogTan [IKFeetPosZ, IKFeetPosX]
IKCoxaAngle = TOINT((BoogTan*180.0) / 3.141592)
	
;Set the Solution quality	
IF(IKSW < TOFLOAT(FemurLength+TibiaLength-30)) THEN
	IKSolution = TRUE
ELSE
	IF(IKSW < TOFLOAT(FemurLength+TibiaLength)) THEN
		IKSolutionWarning = TRUE
	ELSE
		IKSolutionError = TRUE	
	ENDIF
ENDIF		

return
;--------------------------------------------------------------------
;[CHECK ANGLES] Checks the mechanical limits of the servos
CheckAngles:
RFCoxaAngle = (RFCoxaAngle min RFCoxa_MIN) max RFCoxa_MAX
RFFemurAngle = (RFFemurAngle min RFFemur_MIN) max RFFemur_MAX
RFTibiaAngle = (RFTibiaAngle min RFTibia_MIN) max RFTibia_MAX

RMCoxaAngle = (RMCoxaAngle min RMCoxa_MIN) max RMCoxa_MAX
RMFemurAngle = (RMFemurAngle min RMFemur_MIN) max RMFemur_MAX
RMTibiaAngle = (RMTibiaAngle min RMTibia_MIN) max RMTibia_MAX

RRCoxaAngle = (RRCoxaAngle min RRCoxa_MIN) max RRCoxa_MAX
RRFemurAngle = (RRFemurAngle min RRFemur_MIN) max RRFemur_MAX
RRTibiaAngle = (RRTibiaAngle min RRTibia_MIN) max RRTibia_MAX

LFCoxaAngle = (LFCoxaAngle min LFCoxa_MIN) max LFCoxa_MAX
LFFemurAngle = (LFFemurAngle min LFFemur_MIN) max LFFemur_MAX
LFTibiaAngle = (LFTibiaAngle min LFTibia_MIN) max LFTibia_MAX

LMCoxaAngle = (LMCoxaAngle min LMCoxa_MIN) max LMCoxa_MAX
LMFemurAngle = (LMFemurAngle min LMFemur_MIN) max LMFemur_MAX
LMTibiaAngle = (LMTibiaAngle min LMTibia_MIN) max LMTibia_MAX

LRCoxaAngle = (LRCoxaAngle min LRCoxa_MIN) max LRCoxa_MAX
LRFemurAngle = (LRFemurAngle min LRFemur_MIN) max LRFemur_MAX
LRTibiaAngle = (LRTibiaAngle min LRTibia_MIN) max LRTibia_MAX
return
;--------------------------------------------------------------------
;[SERVO DRIVER] Updates the positions of the servos
ServoDriver:

;Wait for previous commands to be completed
SSCWait:
serout SSC_OUT,SSC_BAUTE,“Q”,13]
serin SSC_IN, SSC_BAUTE,[SSCDone]
IF SSCDone <> “.” THEN
goto SSCWait
ENDIF

serout SSC_OUT,SSC_BAUTE,"#",dec RFCoxaPin,“P”,dec TOINT(TOFLOAT(-RFCoxaAngle +90)/0.10588238)+RFCoxaOffset, |
“#”,dec RFFemurPin,“P”,dec TOINT(TOFLOAT(-RFFemurAngle+90)/0.10588238)+RFFemurOffset,|
“#”,dec RFTibiaPin,“P”,dec TOINT(TOFLOAT(-RFTibiaAngle+90)/0.10588238)+RFTibiaOffset,|
“#”,dec RMCoxaPin,“P”,dec TOINT(TOFLOAT(-RMCoxaAngle +90)/0.10588238)+RMCoxaOffset,|
“#”,dec RMFemurPin,“P”,dec TOINT(TOFLOAT(-RMFemurAngle+90)/0.10588238)+RMFemurOffset,|
“#”,dec RMTibiaPin,“P”,dec TOINT(TOFLOAT(-RMTibiaAngle+90)/0.10588238)+RMTibiaOffset,|
“#”,dec RRCoxaPin,“P”,dec TOINT(TOFLOAT(-RRCoxaAngle +90)/0.10588238)+RRCoxaOffset,|
“#”,dec RRFemurPin,“P”,dec TOINT(TOFLOAT(-RRFemurAngle+90)/0.10588238)+RRFemurOffset,|
“#”,dec RRTibiaPin,“P”,dec TOINT(TOFLOAT(-RRTibiaAngle+90)/0.10588238)+RRTibiaOffset,|
“#”,dec LFCoxaPin,“P”,dec TOINT(TOFLOAT(LFCoxaAngle +90)/0.10588238)+LFCoxaOffset,|
“#”,dec LFFemurPin,“P”,dec TOINT(TOFLOAT(LFFemurAngle+90)/0.10588238)+LFFemurOffset,|
“#”,dec LFTibiaPin ,“P”,dec TOINT(TOFLOAT(LFTibiaAngle+90)/0.10588238)+LFTibiaOffset,|
“#”,dec LMCoxaPin,“P”,dec TOINT(TOFLOAT(LMCoxaAngle +90)/0.10588238)+LMCoxaOffset,|
“#”,dec LMFemurPin,“P”,dec TOINT(TOFLOAT(LMFemurAngle+90)/0.10588238)+LMFemurOffset,|
“#”,dec LMTibiaPin,“P”,dec TOINT(TOFLOAT(LMTibiaAngle+90)/0.10588238)+LMTibiaOffset,|
“#”,dec LRCoxaPin,“P”,dec TOINT(TOFLOAT(LRCoxaAngle +90)/0.10588238)+LRCoxaOffset,|
“#”,dec LRFemurPin,“P”,dec TOINT(TOFLOAT(LRFemurAngle+90)/0.10588238)+LRFemurOffset,|
“#”,dec LRTibiaPin,“P”,dec TOINT(TOFLOAT(LRTibiaAngle+90)/0.10588238)+LRTibiaOffset,|
“T”,dec 40*GaitSpeed,13]

;debug:
;serout S_OUT, i9600, "RFCoxa = ",sdec RFCoxaAngle, " RMcoxa= “, sdec RMCoxaAngle,” pwm: “,dec TOINT(TOFLOAT(-RMCoxaAngle +90)/0.10588238)+650+RMCoxaOffset,” RRCoxa = ",sdec RRCoxaAngle,13]
;serout S_OUT, i9600, “LFCoxa = “,sdec LFCoxaAngle, " LMcoxa= “, sdec LMCoxaAngle,” pwm: " ,dec TOINT(TOFLOAT(LMCoxaAngle +90)/0.10588238)+650+LMCoxaOffset,” LRCoxa = “,sdec LRCoxaAngle,13]
return
;--------------------------------------------------------------------
;[FREE SERVOS] Frees all the servos
FreeServos
for Index = 0 to 31
serout SSC_OUT,SSC_BAUTE,”#”,DEC Index,“P0”]
next
serout SSC_OUT,SSC_BAUTE,[13]
return
;--------------------------------------------------------------------
;GP player
GPPlayer

if GPIsPlaying = FALSE then
serout SSC_OUT,SSC_BAUTE,“PL0 SQ0 SM100 IX0 PA0 ONCE”,13]
GPIsPlaying = TRUE
else
serout SSC_OUT,SSC_BAUTE,“QPL0”,13]
serin SSC_IN, SSC_BAUTE,[GPByte0,GPByte1,GPByte2,GPByte3]
;debug:
serout S_OUT, i9600, "SQPlayed: “,dec GPByte0,” IX: “, dec GPByte1,” -> “,dec GPByte2,” Remaining time: ",dec GPByte3, 13]
IF GPByte0 = 255 THEN
GPIsPlaying = FALSE
GPModeON = FALSE
endif
endif
return

[/code]

No (almost :wink: ) questions are stupid. Yes I did that. The PS2 code are removed too. But maybe you’ll see what I’m doing wrong when you’re looking at my/your code.

Thanks Xan!

One part of me wants to check out this part. But to be honest I think its a timekiller for me. So after finding a way around it I think I’ll work with the fun part. If you know what I mean :wink:

I can’t say this enough: RC control are simply AWESOME :smiling_imp:

Yes, I’m running 8.0.1.7

Xan’s code would probably work with any hex, because you can define all body and leg dimensions. A Hitec radio would probably work fine. Before you connect the RC receiver its smart to check on a oscilloscop in what order the receiver sends out the pwm pulses on each channel. If the receiver send a puls on CH01, then on CH02 and so on, the most time effective way is first to read CH01 and CH03 and then CH02 and then CH04.

I think probably your programming skills are fine. I forgot the minor language jump might make my sarcasm directed towards the BAP not so apparent. Sorry for that. :frowning:
What I am indirectly suggesting is if code you write can be broken down to its simplest form and makes sense logically then do not hesitate to try using another different I/O pin. There is little formal guidance as to what works and why other than trying to replicate what others have managed to make work. Unfortunately if you wind up using different pins than their example it is entirely possible you may get different results.

“GL” is a chat abbreviation for Good Luck, much like LOL is Laugh Out Loud.

Hi all,

I started a new thread which will be fully dedicated to my code. This keeps all questions, answers and modifications on one central point. So please feel free to participate!

Hi Brian,

Welcome on this forum! Great looking Hex! I like the round tibia parts! But to be honest, I don’t like you hijacking my thread :s And I also think that your crawler definitely deserves to have his own thread! :wink:

I completely agree with the Kurt’s answer. Be sure that you’ve got the latest compiler. If the error keeps appearing let me know :wink:

Hi Zenta,

I know exactly what you mean! I looked at the code that you’ve posted but I can’t find anything odd by just looking over it. I can’t debug it because I don’t have the same awesome hardware as you’ve got :frowning: I’m sorry that I can’t help you with this bug at the moment…

Please stop poking me! I can’t take it any longer :wink:

I totally agree! The only thing that is hardcode in my code is the basic coxa setup of 60 deg. I will move this to the part where you define the bodydimensions.

Xan

Xan,
I downloaded the updated compiler, haven’t used it as yet - busy weekend. Sorry for Hi-jacking your thread, won’t happen again. Your newest hex looks great. Guess I’ll get all my “ducks in a row” and get report back when my bot actually gets up and crawls around some. Thanks.
Brian

Hi Xan,

Assuming you might have missed the post in my thread, I thought to drop it in the relevant thread :slight_smile:

youtube.com/watch?v=NMtifBKX … re=related

I need the following details about this video :slight_smile:

1- What is the servo time used in the sequences? is it 200 or some value larger?

2- Is this a 6 step ripple gait or a 12 step ripple gait?

3- How high in cms(Y-direction) a leg is lifted during the gait.

4- Inside the gait, how far in cms each leg is translated in Z-direction?

5- How high in cms the bot is lifted from the ground during walking?

I am just impressed by the tranquility of the gait :slight_smile: and am quite concerned to ask what secrets lie behind this tranquility :slight_smile:

Thanks,
Umar