Pan and Tilt head + bodyIK

so far i have compiled code to my atom for a pan and tilt head.

[code];[Head Tracking]
HeadTracking:

;Return to the middle position
HeadPanAngle=0
IF (ABS(TravelLengthX)>TravelDeadZone | ABS(TravelLengthZ)>TravelDeadZone | ABS(TravelRotationY2)>TravelDeadZone) THEN
;Calculate walking direction X and Z
TravelLengthXZ = SQR((TravelLengthX * TravelLengthX) + TravelLengthZ * TravelLengthZ)
HeadPanAngle = TOINT(FACOS(TOFLOAT(TravelLengthZ) / TOFLOAT(TravelLengthXZ)) * 180.0 / 3.141592)-180
;Add sign depending on the direction of X
HeadPanAngle = HeadPanAngle * (TravelLengthX/ABS(TravelLengthX))
ENDIF
;Calculate body angle depending on rotation
IF ABS(TravelRotationY
2)>TravelDeadZone & ABS(TravelRotationY3) > ABS(HeadPanAngle) THEN
HeadPanAngle = -TravelRotationY
3 ; Rotation max = 166 to get max range of 90 deg.
ENDIF
;----------------
HeadTiltAngle=0
IF (ABS(TravelLengthZ)>TravelDeadZone | ABS(TravelLengthX)>TravelDeadZone | ABS(TravelRotationY
2)>TravelDeadZone) THEN
;Calculate walking direction X and Z
TravelLengthXZ = SQR((TravelLengthZ * TravelLengthZ) + TravelLengthX * TravelLengthX)
HeadTiltAngle = TOINT(FACOS(TOFLOAT(TravelLengthX) / TOFLOAT(TravelLengthXZ)) * 180.0 / 3.141592)-180
;Add sign depending on the direction of X
HeadTiltAngle = HeadTiltAngle * (TravelLengthZ/ABS(TravelLengthZ))
ENDIF
;Calculate body angle depending on rotation
IF ABS(TravelRotationY2)>TravelDeadZone & ABS(TravelRotationY3) > ABS(HeadTiltAngle) THEN
HeadTiltAngle = -TravelRotationY3 ; Rotation max = 166 to get max range of 90 deg.
ENDIF

return[/code]
*
so far its doing this:*
Left JStick:
when walking forward, the head looks up,
when walking backwards, the head looks down,
when walking to the right, the head looks right,
when walking to the left, the head looks left,

and

Right JStick:
when rotating left, the head looks left,
when rotating right, the head look right,

But,

im trying to STOP the head from doing this:

Left JStick:
when walking forward, the head looks up,
when walking backwards, the head looks down,

and get the head to DO this:

Left JStick:
when walking to the right, the head looks right,
when walking to the left, the head looks left,

and

Right JStick:
when rotating left, the head looks left,
when rotating right, the head look right,
and
when pushing the stick up, the head looks up,
when pushing the stick down, the head looks down,

Also i would like the head to pan and tilt when using body IK, which its not currently doing in the code.

iv tried to make this simple to understand. hopefully it is?
any help?

Just to make sure I understand, the code you posted is code you’ve gotten or used for something else. You didn’t expect it to work as posted, and what you are looking for is suggestions for code to do the other things you’ve mentioned. Correct?

At 1st I thought you were just thinking you had a small bug in the posted code. But more I look at it, I think you need a different code block altogether, primarily switching your various inputs.

What does pushing up/down on your right stick currently do? (More specifically, what input variables does it affect?)

This code is written in accordance with Xans phoenix code.
are you familiar??
This project is for a hexapod with a pan & tilt head!

The code works as explained but i wish to only stop the head from moving up and down when i move the Left stick up and down, and making the right stick up and down move the head up and down.
*
I don’t want to primarily switch inputs i just like to used up and down on right stick for head movements and not left stick.*
Using the right stick’s (up and down) at the moment does nothing to the head. while walking it also does nothing… but when performing** body IK moves** it raises and lowers the body.

here is the section for that function:

[code] BodyYShift = 0
IF (DualShock(2).bit2 = 0) THEN ;L1 Button test

  BodyRotY = (Dualshock(3) - 128)/6
  BodyYShift = (-(Dualshock(4) - 128)/2)MIN-(BodyPosY-10)

;--------
ELSEIF (DualShock(2).bit0 = 0) ;L2 Button test

  BodyRotY = (Dualshock(3) - 128)/6
  BodyYShift = (-(Dualshock(4) - 128)/2)MIN-(BodyPosY-10)

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

  TravelRotationY = -(Dualshock(3) - 128)/4
ENDIF[/code]

at the moment the head does nothing when doing body moves. i would also like this to happen. i have tried changing TravelLength for *TravelRotationY * and BodyPosY but nothing.

Hope this explains it a bit more.

I’m familiar with you, Xan, and the phoenix project from reading the forums. I’m a big fan actually and have learned a lot. I’m not familiar with the code you are referring to specifically and I don’t have an atom myself, but I can read and understand the basic code you posted.

What I meant by “needing to switching the inputs” is that currently your right stick doesn’t do anything. (I’m ignoring the IK movement for now). So said another way, there is no “input variable” that corresponds to the right stick position. At least not in the original code you posted. The current code moves the head up down directly as the result of the TravelLengthXZ variable, …which is indirectly calculated from the left stick input. Correct?

So, to make the head move up and down via right stick, you’d need to calculate HeadTiltAngle as some function of a right stick input variable. And if you wanted to do it via your IK movement, then you could probably calculate your HeadTiltAngle as the result of the BodyYShift variable you posted in second code block.

At a high level that seems obvious though…so it’s more likely that I’m simply missing the point of your question. Hopefully with some replies under your post you’ll now get more eye balls looking at it and I’ve least been a partially helpful in that way though. :wink:

the right stick does control rotation of the body (left and right) but nothing for up and down, while walking. and yes you are correct about the code moving the head up down directly as the result of the TravelLengthXZ.

once i get time to hook up the atom again i will run some more test and put this one to sleep.
thanks for your help.

its simple i know but its always the simplest things that make us think more. or is that just me?

cheers.
Jonny.

Also to not spread this thread all over the forum i have another question regarding P&T for a hex.

I would like to select a mode were the hexapod will stop walking, only making head movements avalible:
so when moving the J/Sticks only the head moves in its normal fasion:

im not currently at my desk so i cannot confirm this line of code, but any views on this:

[code]
IF (DualShock(2).bit6 = 0) THEN ;Cross Button test
IF TravelLengthX=0 & TravelLengthZ=0 & TravelRotationY=0 THEN

BodyPosX = 0
BodyPosZ = 0
BodyRotX = 0
BodyRotY = 0
BodyRotZ = 0
ELSE
Gosub Headtracking

 ENDIF
ENDIF[/code]

ok here is a snippet of the P&T code using right j/Stick.

the code works when using L1 and L2 body moves
only one prob…
when walking normally the head tilts to the right when pushing up, and left when pushing down. :confused:

[code]
HeadPanAngle=0
IF (ABS(BodyRotY)>TravelDeadZone | ABS(BodyRotY)>TravelDeadZone | ABS(TravelRotationY*2)>TravelDeadZone) THEN
;Calculate direction X and Z
HeadPanAngle = SQR((BodyRotY * BodyRotY) + BodyYShift * BodyYShift)

;Add sign depending on the direction of X
HeadPanAngle = HeadPanAngle * (BodyRotY/ABS(BodyRotY))

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

[code] HeadTiltAngle=0
IF (ABS(BodyYShift)>TravelDeadZone | ABS(BodyRotY)>TravelDeadZone | ABS(TravelRotationY2)>TravelDeadZone) THEN
;Calculate direction Z and X
HeadTiltAngle = SQR((BodyYShift * BodyYShift) + BodyRotY
BodyRotY)

;Add sign depending on the direction of Z
HeadTiltAngle = HeadTiltAngle * (BodyYShift/ABS(BodyYShift))

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