Animatronic head - calculating servo values

Setup: I have an animatronic head. On each "shoulder blade" is a servo, the combination of which control the swivel of the head (up/down, tilt left/right). The servos will be controlled using x/y values from a joystick.

How would I write the algorithm to move the servos? Some examples: If I push all the way up on x, the servos should move to 0 and the head should tilt up accordingly. If I move y left, the left servo should move to 0, and the right servo should go to 180, tilting (not turning) the head left.

But what if I push up and left at the same time? Or right and down, or any combination of? How do I calculate what each servo should move to?

Where do you want the servos to move to ?

I would be inclined to determine the values empirically, ie by experimentation

I'm not a math-wiz.
I'm sure there's an equation that can do this, where I can plug in my mix/max servo degrees, and the joystick x/y values, and come up with an appropriate value for both servos.

A head can move in three directions:
Tilt the face up and down.
Tilt the top of the head toward the left or right.
Rotate the face to the left or right.

It sounds like you have servos that control at least two of the direction. Do you have a diagram of how the servos move the head?

I was not suggesting using any maths, in fact the exact opposite

empirically

adverb

  1. by means of observation or experience rather than theory or pure logic.

"empirically tested methods"

ie, try some values and adjust them until you get the correct outcome

And I am sure there is not.

Control the three servos with pots and print out what you are sending to the servos. Then make a note of the values for various start and end positions you like.

Then use the readings from your joystick to play back these pre canned moves.

I did this when I wrote this:-
https://vimeo.com/manage/videos/139202162
Back issues are still available as a free PDF download.

In fact I went one better and wrote a scripting language to allow the easy putting together of movements. It has simple syntax:-

#, Mulder wscript for a wink
move left eye, 300
go
fade steps, 2.0
left eye, 1500, 0, 0
go
delay, 0.2
left eye, 0, 0, 0
go
delay, 5.0
move left eye, 230
go
delay, 5.0

This is the interactive control screen
Mulder

And this is Mulder all lit up.

It is all written in Python but is simple enough to turn into C.