A head for my Hexapod

Again. This is not the most polite way to ask for some help. You have to keep in mind that we don’t have your brain, we have no idea what you may have done with the code. Just posting up 20+ pages of code and saying “What did I do wrong” will get you nowhere fast. :unamused:

Maybe you could start off with a list of some of the things that you’ve changed?

I only added the code for the head and tail moving. As shown on the page before. it compiles and programms fine.

To eliminate any possible power supply issues. Please create a SIMPLE program to move a few servos . Your battery must have taken a beating while you were working on troubleshooting the short circuit problems.

Normally when a piece of code doesn’t work, it at least does the same thing every time you try. But if you ARE having a power problem it may not act the same depending on the load the servos are drawing and the positioning of the bot, etc.

Have you gone back one program revision to make double sure it’s the changes you made to the code?

I will second James(fish) here. What have you done to try to issolate the issue? If you run the unmodified code does it work OK?

Are you sure it is not a battery/power problem? Is the VS seperated from VL on both SSC-32 and BAP? Fresh 9V battery? Moving something like 22 servos can be a pretty good load on a power system.

Kurt

Disconnect all the servos except the tail and head servos and see if they work as expected. If they do, then it is probably a power issue.

It was walking and working fine untill i programmed the new code. That’s all i changed.

I used it untill an hour and a half ago. No servo problem.

There must be something in the code that makes it** reset **the board…

power issue.

well first off id like to point out that once i copied and pasted it to my ide i noticed your servo driver have been commented out!!!

…Also (non issue related) with the head code you need to add (TravelLength?/ABS(TravelLength?)
for the following, as well as just for the (HeadHAngle)

  • HeadVAngle=0
    TailHAngle=0
    TailVAngle=0*

yours looks like this and doesnt include (Travel length XYZ) for the other Vars.

[code] HeadHAngle=0
HeadVAngle=0
TailHAngle=0
TailVAngle=0

IF (ABS(TravelLengthX)>TravelDeadZone | ABS(TravelLengthZ)>TravelDeadZone | ABS(TravelRotationY*2)>TravelDeadZone) THEN

;Calculate walking direction X and Z
TravelLengthXZ = SQR((TravelLengthX * TravelLengthX) + TravelLengthZ * TravelLengthZ)
HeadHAngle = TOINT(FACOS(TOFLOAT(TravelLengthZ) / TOFLOAT(TravelLengthXZ)) * 180.0 / 3.141592)-180

;Add sign depending on the direction of X
HeadHAngle = HeadHAngle * (TravelLengthX/ABS(TravelLengthX))

ENDIF

;Calculate body angle depending on rotation
IF ABS(TravelRotationY2) >TravelDeadZone & ABS(TravelRotationY3) > ABS(HeadHAngle) THEN
HeadHAngle = -TravelRotationY3 ; Rotation max = 166 to get max range of 90 deg.
ENDIF

RETURN
goto main[/code]

so any other suggestions?

I tried pasting in the code all over again with a clean file but the same thing happens.

I really can’t find the problem…

Personally if it were me I would break this down to smaller pieces.

That is have you tried what Robot Dude suggested, and write a real simple program that simply moves all 4 of these servos and sees what happens. For example something like:

[code]
angle var long

main:
for angle = 900 to 2100 step 100 ; about -45 to 45
serout SSC_OUT, SC_BAUTE, “#28P”, dec angle, “#29P”,dec angle,"#30P", dec angle, “#31P”, dec angle, “T100”, 13]
pause 100
next
goto main[/code]

Note: I just typed this in on the fly, there may be problems, you may want to play with timings, but assuming I did this right it would imply that the servos work. You may also then wish to change the 900,2100 to the full range of the servos, to make sure that there is not some problem.

If this works then can you add a simple output to the 18 leg servos to put them all at their zero point and see if it still works, if it does then we probaly need to look more closely at the code.

Kurt

FYI - I did take a quick look through the code and do have some concerns.

As far as I can tell you are currently only playing with HeadHAngle. If it were me I would change the 4 variables HeadHAngle, HeadVAngle… to SLONG from SWORD. Here is why…

in the code you have:

 Serout SSC_OUT,SSC_BAUTE,"#",dec HeadHPin,"P",dec (HeadHAngle+60)*10000/1059+650]

Now assuming word math, you have lets say HeadHAngle at 20 degrees (actually zero may have problems as well)
Your math goes 20+60 = 80 * 10000 = 80000 which will not fit into a 16 bit value, now maybe internally it does it as 32 bit math but maybe not

Kurt

Update: This may not be a problem:

headhangle var sword
headhangle2 var slong


	for headhangle = -60 to 60 step 10
	  headhangle2 = headhangle	; move to long
	  Serout s_out,I9600,[SDEC HEADHANGLE, "=", dec (HeadHAngle+60)*10000/1059+650, " ", dec ((HeadHAngle2+60)*10000)/1059+650, 13] 
	next
	
	end

Had the output:

-60=650 650 -50=744 744 -40=838 838 -30=933 933 -20=1027 1027 -10=1122 1122 0=1216 1216 10=1311 1311 20=1405 1405 30=1499 1499 40=1594 1594 50=1688 1688 60=1783 1783

Thanx a lot! I just wanted to ask you if you can help me implement it in the coe. I don’t know where to put it… and what to remove…

I more or less had the first version there, except I did not add the defines for the SSC pin and baud. Here is a version that first walks through with only the head and tail, then after the first pass should try to set the leg servos all to 1500…

[code]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

angle var long
time var long

Sound P9,[60\4000,80\4500,100\5000]

; get them first to init position.
serout SSC_OUT, SSC_BAUTE, “#28P1500#29P1500#30P1500#31P1500”, 13]

; first time through will only move the head and tail…
main:
time = 250
for angle = 900 to 2100 step 100 ; about -45 to 45
serout SSC_OUT, SSC_BAUTE, “#28P”, dec angle, “#29P”, dec angle, “#30P”, dec angle, “#31P”, dec angle, “T”, dec time, 13]
pause time
time = 100 ; make first one move slower, longer ways to go…
next

pause 5000 ; wait a few seconds.

; now set all of the leg pins to 1500
serout SSC_OUT, SSC_BAUTE, "#00P1500 #01P1500 #02P1500 #04P1500 #05P1500 #06P1500",|
							"#08P1500 #09P1500 #10P1500 #16P1500 #17P1500 #18P1500", |
							"#20P1500 #21P1500 #22P1500 #24P1500 #25P1500 #26P1500", 13]

goto main

[/code]

This is the whole program, you simply need to create a new file, cut and paste, save and download…

Indeed! this worked fine! So what does this tell? Can we fix my problem now?

Ok, so it looks like software. Another look through the code and I think I see the problem.

Kurt.

Oh, I guess you might like to know what it is :slight_smile:
If you look at this code:

[code] ;Headtracking
GOSUB HeadTracking

GOSUB CheckAngles

LedC = IKSolutionWarning
LedA = IKSolutionError

;Read input
GOSUB Ps2Input
;GOSUB ReadButtons ;I/O used by the PS2 remote
;GOSUB WriteLeds ;I/O used by the PS2 remote

;Head Angle
HeadHAngle = (HeadHAngle min HeadHPin_MIN) max HeadHPin_MAX
HeadVAngle = (HeadVAngle min HeadVPin_MIN) max HeadVPin_MAX
TailHAngle = (TailHAngle min TailHPin_MIN) max TailHPin_MAX
TailVAngle = (TailVAngle min TailVPin_MIN) max TailVPin_MAX

;Get endtime and calculate wait time
GOSUB GetCurrentTime], lTimerEnd
CycleTime = (lTimerEnd-lTimerStart)/WTIMERTICSPERMS

IF(HexOn)THEN
;Wait for previous commands to be completed while walking
IF(ABS(TravelLengthX)>TravelDeadZone | ABS(TravelLengthZ)>TravelDeadZone | ABS(TravelRotationY*2)>TravelDeadZone) THEN

  pause (PrevSSCTime - CycleTime -50) MIN 1 ;   Min 1 ensures that there alway is a value in the pause command 
  
  IF(BalanceMode=0)THEN 
    SSCTime = NomGaitSpeed + (InputTimeDelay*2) 
 ELSE 
    SSCTime = NomGaitSpeed + (InputTimeDelay*2) + 100 
 ENDIF 

ELSE
SSCTime = 200 ;NomGaitSpeed
ENDIF

GOSUB ServoDriver

ELSE
;Turn the bot off
GOSUB FreeServos
ENDIF

HeadTracking: ;(Head Tracking)

;Return to the middle position
HeadHAngle=0
HeadVAngle=0
TailHAngle=0
TailVAngle=0

IF (ABS(TravelLengthX)>TravelDeadZone | ABS(TravelLengthZ)>TravelDeadZone | ABS(TravelRotationY*2)>TravelDeadZone) THEN

;Calculate walking direction X and Z 
TravelLengthXZ = SQR((TravelLengthX * TravelLengthX) + TravelLengthZ * TravelLengthZ) 
HeadHAngle = TOINT(FACOS(TOFLOAT(TravelLengthZ) / TOFLOAT(TravelLengthXZ)) * 180.0 / 3.141592)-180 

;Add sign depending on the direction of X 
HeadHAngle = HeadHAngle * (TravelLengthX/ABS(TravelLengthX)) 

ENDIF

;Calculate body angle depending on rotation
IF ABS(TravelRotationY2) >TravelDeadZone & ABS(TravelRotationY3) > ABS(HeadHAngle) THEN
HeadHAngle = -TravelRotationY3 ; Rotation max = 166 to get max range of 90 deg.
ENDIF

RETURN
goto main
[/code]
You placed the Head tracking subroutine in the wrong place. IE you put it in such that once you call the ServoDriver, your continues to fall through into the HeadTracking function which does a return, which corrupts the stack. What you need to do is to move the “Goto Main” line up above this subroutine, such that it goes back to top of the loop and not fall into the subroutine.

I hope that makes sense.

Kurt

Yes it does. Now i can use the bot and it will work normally. Only the head ain’t moving… :frowning:

Now it is time for you to start debugging it…
If it were me I would start off by adding some debug outputs to S_OUT to see what values I am getting.

For example:

[code];----------------------------------------------------------------------------------------------------------------
DTLX var sword ; debug
DTLZ var sword
DTRY var sword

HeadTracking: ;(Head Tracking)

;Return to the middle position
HeadHAngle=0
HeadVAngle=0
TailHAngle=0
TailVAngle=0

IF (ABS(TravelLengthX)>TravelDeadZone | ABS(TravelLengthZ)>TravelDeadZone | ABS(TravelRotationY*2)>TravelDeadZone) THEN

;Calculate walking direction X and Z 
TravelLengthXZ = SQR((TravelLengthX * TravelLengthX) + TravelLengthZ * TravelLengthZ) 
HeadHAngle = TOINT(FACOS(TOFLOAT(TravelLengthZ) / TOFLOAT(TravelLengthXZ)) * 180.0 / 3.141592)-180 

;Add sign depending on the direction of X 
HeadHAngle = HeadHAngle * (TravelLengthX/ABS(TravelLengthX)) 

ENDIF

;Calculate body angle depending on rotation
IF ABS(TravelRotationY2) >TravelDeadZone & ABS(TravelRotationY3) > ABS(HeadHAngle) THEN
HeadHAngle = -TravelRotationY3 ; Rotation max = 166 to get max range of 90 deg.
ENDIF
; debug print…
if (DTLX <> TravelLengthX) or (DTLZ <> TravelLengthZ) or (DTRY <> TravelRotationY) then
DTLX = TravelLengthX
DTLZ = TravelLengthZ
DTRY = TravelRotationY
serout s_out, i9600, "Head Track: ", sdec DTLX, " ", sdec DTLZ, " ", sdec DTRY, “->”, sdec HeadHAngle, 13]
endif

RETURN
[/code]

I did this more compilicated than maybe necessary in that it only prints if one of the main inputs changes. This keeps from having lots of debug outputs. If no outputs come out then you are not calling this function. If the inputs change but the last value for the head h angle does not change then something is wrong in the calculation. If it changes, but the head does not move, then maybe need to check to see what the values are in the servo driver to make sure they have not been updated…

Kurt

euhm… i really don’t know how to use this. I tried something but didn’t give me any info. i put the code in my bas file on the spot where you showed. At least… This goes under the “goto main” script right?

Ok and then?

Hi again,

Sorry but I don’t have much time to spend here. But I think you need to start learning how to do some of the debugging.

The Serout command outputs data to a serial port. The reserved name S_OUT goes out over the serial port that is connected to the 9 pin serial connector on your Bot Board 2. So the idea is to sprinkly debug printouts in key locations in your code to help figure out what is going on.

These can be as simple as:
serout s_out, i9600, “I got here”, 13]
which will output the simple string to the terminal followed by a CR, like you use in the other serouts.

So once you compile and download the program to your board, you leave the serial connector hooked up. You then go to the terminal 1 tab at the bottom of your basic Atom Pro IDE and select the correct comm port and the baud rate of 9600 and then click on the connect button. At this point your robot will probably reboot. Hopefully at this point you will start getting debug information to help you figure what is going on with your program.

Good Luck
Kurt

Thanx! I did what you said but i get no information at all. It does connect, and works fine . I can walk and do everything. but no feedback.

it seems like the head servo’s ar not powered. I can move them by hand.