HSERVO- angles, speed, and other calcs

Hi all, new here…

New owner of ARC-32 board, and just getting my head around the HSERVO command- I’d thought I’d post some info I’ve digested for all to view/search…

So converting between angles (in deg and radians), ‘steps’ of the command, the speed value, and the limits of the servo was a lot to get sorted. Here is what I have formulated based on ver 2.0.0.15

HSERVO command uses a step postion value (I’ll cal it ‘step’- I know, I’m crazy) from -30,000 to 30,000 to output a pulse modulated signal from 0 ms to 3.0 ms with 1.5 being the center. If we describe this in servo rotation:

-90 deg = -30,000 step
90 deg = 30,00 step

-or-

333.3 step/degree or 19100 steps per Pi (radians)

Alternately, you could use a token SBTYE value (-128 to 127) in the HSERVO command (x235) with resolution of slightly less than one degree, where the value of the token value is 0.706 degrees. e.g.:

HSERVO [Px \ token*235 \ SPEED] where token is an SBYTE approx equal to 0.7 deg

Ok, what about the speed value? The CPU updates the servo position every 20ms. So If I know the total time requred for the servo to move, the speed value is calculated as:

SPEED = (Total steps)* (0.02 cycles/step-sec) / (required time)

with above it looks like:

Start angle = -30 deg (calculate steps -> -30 deg * 333 step/deg = -10000 steps)
Stop angle = 20 deg (calculate steps -> 20 deg * 333 step/deg = 6666 steps)
Time requred = 0.2 seconds

SPEED = (6666 - (-10000)) * (0.02) / (0.2) = 1667 cycles/sec

But what if I want to go as fast as possible? What value is that? The fastest SPEED value that can be used without the CPU ‘gettting ahead’ of the servo can be found by looking at the servo spec sheet. There will be a value listed like “60 deg 0.18 sec”. Use this information and plug it in:

MAX SPEED = (0.02) * (333 step/deg) * (Servo angle) / (fastest time )

For the above servo, MAXSPEED = (0.02) * (333 step/deg * (60 deg) / (0.18 second) = 2220 cycles/second. This is the largest reasonable value for this paticular servo.

Hope ths helps someone, thanks to all…
Sean

** EDIT**

In code, the variables need to be all the same type.
Since : 1/0.02=50

Position2 = desired step value
HSERVOPOS (Px) = Position1
Total_steps = ABS( Position1-Position2)
Speed_s = Total_steps/(50*requested_time) ;If requuested_time>=1 and integer values
HSERVO [Px \ Position2 \ Speed_s]

Thanks for taking the time to post this. I will make it a sticky. :smiley:

This is good information. I have one question - so should I set my stepsperdegree to 333.3 or 208.25 ?

The later number is from a suggestion that the old number of 166.6 in the biped programs written for SSC32 should be corrected by a factor of 20/16 (adjusting for the 20 Mhz vs 16 Mhz).

I am trying to get my biped to walk - modifying the auto walk code from this site but struggling with angles and movements! Wish there was some document that tells how one arrives at the angles (or servo positions) for the gait.

Thanks

Any one wants to comment ? What would be the correct steps per degree for a ARC32 ? Does it depend on the servos also ? I am using the 645MG.

Steps per degree may depend on your servos. If you have questions for your specific one, experiment. Get out a servo, try guessing what it should be. Write a simple program to go to what you think should be 45 degrees and measure it with a protractor. If it is off from where you think it should be, adjust your conversion factor and try again.

Also your previous post mentioned SSC-32? If so you are not using HSERVO and your calculations do not depend on the clock speed of your processor. It instead more logically simply calculates the pulse width in microseconds… So it does not need to change. If however you are not using an SSC-32, but are instead using an Arc32 or a Bap28 and HSERVO to control your servos, yes you do need to do a factor of 4/5 or 5/4 depending on for which processor the code was written for and which you wish to run it on…

Kurt

Yes I can experiment - but I thought people here would know something about this.

I mentioned SSC-32 only because the programs in this site use that. I use ARC 32 and someone suggested that I use a factor of 20/16 (ARC32 vs SSC32) to modify the 166 number in programs that were written for SSC32.

In this thread I see the factor of 333 - so I am wondering which one to use.

If it all depends on the servo - then how does one figure out for a robot with different servos ? I have one set for legs, a different set for torso and another for arms (as recommended in various build instructions). It would be an overkill to use high torque servos everywhere I think.

Thanks

There is lots more details up in several other threads, like: viewtopic.php?f=4&t=3224&start=17

Using Hservo on a Bap28 for programs like the brat, we used a conversion factor of 166.6 units per degree. So the simple answer for like type servos controlled by the Arc32, I would start off with a value of 166.6 * 1.25 = 208.25…

The 333 one is not correct as this creates a pulse width range of 0 to 3000us which servos do not use to give you the plus or minus 90 degrees (assuming servos that can go 180 degrees). There range is closer to 750-2250 more or less.

Note: these numbers work pretty well for analog servos. It is my understanding that you mileage may be different with digital servos. The only digital servos I have are on my Arm…

Kurt

Kurt thanks! Good advice. I will change the 333 back. I do have only analog servos on my ARC32.

Still working on getting the brat to walk correctly - as I had added a torso with 2 hip servos things have not been very pleasant!

Gopal

Using ARC32 and Hitec HS645MG Servos I found that it was 200 steps per degree

Thanks!

How did you get the 200 ? Going by the calculations the value seems to be 208.25 … small difference but I don’t know if it is significant or not!

Regards
G

hey just speculating, but why could you not use the basic micro studio, like I have and terminal channels for each lym and the different frequencies to indicate to the arc which motor you want to control, create a small program that occilates the servos in small incraments, then use the reset button to start movements over, and the connect button on the terminal windows to create the ik and then use chapture and compare command to rec ord the positions, works great for me but my computer crashed again before i got to the capture compare. pretty simple
your freind and cpolige jmjr4
p.s. i used the first few lines of code from the program that is in the library to occilate the servos but have not figured how to get them to come back up, but the arc was showing signs of repeatablity and learning. really it is.
it way more adictive than you think

oh ya, jagar again

i also fig you could use the odd parity to move a servo on the neg side, and the even prty for the posi side and the ex on and ex off to pwer the serv or turn it lyp. just like you can read srv volt . u cn send to serv.

your freind and coleige jagar4

p.s. again i guess that what it means that the arc does its own math, what about ik, gui

hum, interesting think that

hey come to think

where is there an actual datta sheet and logic for the programmable divice in the servos,

you all know
jagar4