Xan's Phoenix Code

Im doing some work on getting a servo (say for a camera “pan”) to face the forward direction of a robot as it walk around.

Using the idea of leg control i thought that maybe adding servos and code for the Z and X axis i could also add other servos eg, Tibia + Femur on Z axis and a Coxa on X axis.

[code]Coxa_PulseMin con 600
Coxa_PulseMax con 2400
Femur_PulseMin con 600
Femur_PulseMax con 2400
Tibia_PulseMin con 600
Tibia_PulseMax con 2400

Coxa con P1
Femur con P2
Tibia con P2

CoxaAngle_Min con 108 ;numbers to be confirmed in setup.
CoxaAngle_Max con 108
FemurAngle_Min con 108
FemurAngle_Max con 108
TibiaAngle_Min con 108
TibiaAngle_Max con 108

Coxa_Pulse var word
Femur_Pulse var word
Tibia_Pulse var word

TravelLengthX var sword
TravelLengthZ var sword

:-------------------------------------------------------------
Coxa= (((Coxa_PulseMax - Coxa_PulseMin) * ((TravelLengthZ + 64 ) & $7F) |
/ 127 + Coxa_PulseMax) min Coxa_PulseMin) max Coxa_PulseMax

	 Femur=  (((Femur_PulseMax - Femur_PulseMin) * ((TravelLengthX + 64 ) & $7F) |
	/ 127 + Femur_PulseMax) min Femur_PulseMin) max Femur_PulseMax
	
	Tibia=  (((Tibia_PulseMax - Tibia_PulseMin) * ((TravelLengthX + 64 ) & $7F) |
	/ 127 + Tibia_PulseMax) min Tibia_PulseMin) max Tibia_PulseMax[/code]

would this work just the same…?

Take my suggestion with a grain of salt, as I’m still learning but that seems like an awful lot of code for something so simple wouldn’t you just read the input’s of your controller “ps2 or RC” and have it output those left right movements to a single servo? or 2…

ehh ehh? or am I horribly wrong? heheh

–Aaron

Hi Innerbreed,

You lost me…

Your story tells me you want a servo (with cam) to follow the horizontal walking direction. So if you walk forward, look forward. If you walk to the left, look to the left. Your confusing me with the coxa, femur and tibia terms in your code…

If you want to add a pan function you could do something like this:

Pan = arctan(TravelLengthX/TravelLengthZ)


note: z = y on the drawing.

You need to build something around it to tell the servo what to do when both values are 0. Like return to the home position or something.

You could also put the remote input from the joystick directly into the function. This way it also moves when doing body rotation/translation.

Let me know if this is what you had in mind.

Xan

Any ETA on Xan’s code on a CHR-3?

I’ve got plenty of other things to do in the meantime. I’m just curious.

The tutorial is in the queue. You can make the adjustments to the code yourself. I don’t know how long till they’re working on it.

sorry for confusion… wouldnt be the first time iv confused everyone.
the idea for making a leg move realtime came from morking on a camera pan.

using the same programming but for a coxa servo, femur and tibia.

when the right Jstick is moved to the right the horizontal servo will rotate to the right… same with the left too.

now… add two vertical servos for Femur and Tibia.

the Femur will be controlled by the right Jstick forward and back, making the Femur go up and down. and the Tibia will go up and down using the Left Jstick’s forward and back!

does this explain it better?

No worries – thanks for the update.

I’m using the BAPro and serial control on my CHR-3 right now. It’s tied-into a single-board linux machine that sends it movement commands.

It will be a few weeks before I get those four ping sensors looking in all four directions for obstacle detection. I’ve got the linux machine sending the second BAPro board a signal to scan with the ping sensor and the sensor’s readings make it back to the linux pc as well.

I think I’m going to download turbocad and layout a replacement to the second tier of your hexapod deck. I’d like to make a larger deck that can hold four complete pan/tilt servos. I know a machine shop that would knock it right out for me.

Thanks again!

I had it working just fine on a CHR-3. What I did was to run powerpod set it for the CHR and for the right type of legs and then generated a basic program. This defines most of the offsets in the file. I did use a tape measure as well to double check it. The only problems I ran into was the initial position which I used PEP to give me a gues. Also ran into one or two variables that overflowed and I converted those from a byte to a word…

Kurt

with regards to the (SSCTime)
does anyone know what these times relate to in seconds?
100=?
200=?
300=?
and so on…

also what is the limit?
example:

[code] IF (DualShock(1).bit3 = 0) and LastButton(0).bit3 THEN ;Start Button test
IF(QuadOn) THEN
'Turn off
Sound P9,[100\500,80\4500,100\4000]
BodyPosX = 0
BodyPosY = 0
BodyPosZ = 0
BodyRotX = 0
BodyRotY = 0
BodyRotZ = 0
TravelLengthX = 0
TravelLengthZ = 0
TravelRotationY = 0

  SSCTime = 600
  GOSUB ServoDriver
  QuadOn = FALSE
ELSE
  'Turn on
  Sound P9,[60\400,80\4500,100\5000]
  SSCTime = 200      ;This changes the servos speed directly.
  QuadOn = TRUE	
ENDIF

ENDIF[/code]

I couldn’t help myself but try and answer your question,

SSCtime = 150, the 150 means Ms

I Found that in the atom pro manual pdf that’s free.

Here’s the info I found.


serout tpin,baudmode,{pace,}[OutputData]

pace is an optional variable or constant (0 to 65535) that tells 
SEROUT how many milliseconds to wait between 
transmitting bytes. If pace is omitted, there will be no delay 
between bytes. Flow control is preferable to fixed output 
timing: pace is provided for use with peripherals that don't 
support flow control. Normally either flow control or delay is 
used, not both.

Hope that helps!

so im looking at ssomething like this:

150 = 1.5sec
200 = 2.0sec
310 = 3.10sec

150mS = 0,15 sec :wink:

thanks… that could have been worse… whops, nearly puhed that magic “programming” button.

I’d just like to jump in here…
how are these numbers given (where do we get these numbers from, are they degrees or a linial measurement?

Hi Guys,

Sorry for my late reaction. It’s very busy over here lately…

I’ll try to pickup where I left so let me know if I overlooked something. :wink:

About placing the cam on a leg discussion:

I doubt if this will give you the wanted end result. A cam is normally combined with a few servos which make it possible to look around. This makes one servo to look left/right and one for up/down. This makes it possible to change the angle of the cam. The leg IK makes it possible to control the position of the feet. Not the angle. So if you connect the cam to the tip of the tibia. Both angle and position will change. But you control the position, the changing angle is just a result…

What you should do is hook up a single leg and try to do some “bodyâ€

thanks Xan this does help.

Initialization values

[code] 'Feet Positions
RFPosX = 53 ;Start positions of the Right Front leg
RFPosY = 25
RFPosZ = -91

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

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

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

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

LRPosX = 53 ;Start positions of the Left Rear leg
LRPosY = 25
LRPosZ = 91[/code]

is this Initialization/Home position … …

Yepp :wink:

i am installing a servo, e.g, the tibia servo “upside down (opposite way round) than in tutorial’s”.

how can i change this in the code so that the leg will react in the normal way, as opposed to reverse!? code 1.3v

Hi Innerbreed,

There are multiple places where you could do this. Personally I always want things output things as close to the output as possible. So I should change the “+ / -“ sign for the XXTibiaAngle. In the original version you see that I did the same with left and right.

[code];[SERVO DRIVER] Updates the positions of the servos
ServoDriver:
;Front Right leg
serout SSC_OUT,SSC_BAUTE,"#",dec RFCoxaPin,“P”,dec TOINT(TOFLOAT(-RFCoxaAngle +90)/0.10588238)+650]
serout SSC_OUT,SSC_BAUTE,"#",dec RFFemurPin,“P”,dec TOINT(TOFLOAT(-RFFemurAngle+90)/0.10588238)+650]
serout SSC_OUT,SSC_BAUTE,"#",dec RFTibiaPin,“P”,dec TOINT(TOFLOAT(-RFTibiaAngle+90)/0.10588238)+650]

…

;Front Left leg
serout SSC_OUT,SSC_BAUTE,"#",dec LFCoxaPin,“P”,dec TOINT(TOFLOAT(LFCoxaAngle +90)/0.10588238)+650]
serout SSC_OUT,SSC_BAUTE,"#",dec LFFemurPin,“P”,dec TOINT(TOFLOAT(LFFemurAngle+90)/0.10588238)+650]
serout SSC_OUT,SSC_BAUTE,"#",dec LFTibiaPin ,“P”,dec TOINT(TOFLOAT(LFTibiaAngle+90)/0.10588238)+650]

…

;Send
serout SSC_OUT,SSC_BAUTE,“T”,dec SSCTime,13]

PrevSSCTime = SSCTime
Return[/code]

I hope it helps!

Xan