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]