<< Previous | Next >> | |
|
int servo_move_to( int which, long pos, long ticks, long accel_ticks, long final_v );
Description
- Move to new position, pos. Assumes current position is "cmd" and current velocity is "vcmd" (with the values of these read from the control structure at beginning of routine).
- Each "tick" represents the time interval between loop updates. This routine measures time intervals in units of ticks.
- accel_ticks (<= ticks) is the number of ticks allocated to acceleration/deceleration phase of movement. The remaining part of the movement is performed at constant velocity. Acceleration and deceleration are computed to be of the same magnitude at beginning and end of motion (but may be opposite signs). final_v is the velocity to be achieved at end of movement. This routine returns as soon as the necessary command list is installed for execution by the ISR. The movement will not be completed until "ticks" ISR executions.
- NB: if the average velocity (vt) required to complete the movement is greater than +/-16k counts per tick, then the movement is stretched to a longer time interval so as to make the peak velocity equal to the +/- 8k counts/tick (which is higher than any physical motor can follow). accel_ticks is set to 16384 if it is over that (since rounding errors can accumulate over long periods of low acceleration).
- If this routine is called again before the previous motion is completed, then the previous motion will be overridden by the new motion. This routine uses floating point, since the mathematics are quite complex. It takes several milliseconds to execute, so should not be called to perform motions which complete in less than, say, 50ms.
- This routine does not attempt to control rate of change of acceleration ("jerk" or d^3x/dt^3). It approximates the required movement profile as parabolic (constant acceleration) and linear (constant velocity) segments.
Parameters
- which
- Servo (0 or 1).
- pos
- Position to be achieved at end of movement.
- ticks
- Number of ISR executions (loop update rate) over which to complete the movement. If less than 1, it is set to 1.
- accel_ticks
- Number of ticks over which acceleration is to be applied. The remainder of the interval, ticks - accel_ticks, is performed at constant velocity. If greater than "ticks", it is set equal to "ticks".
- final_v
- Final velocity to be achieved at end of movement.
Return Value
- 0: OK.
1: computed velocity is "extremely high": time interval stretched to make velocity fit within allowable fixed-point limits (i.e. 8192 encoder counts per sample).Library
- SERVO.LIB
See Also
- servo_set_vel, servo_set_pos, servo_millirpm2vcmd
Dynamic C Functions | << Previous | Next >> | rabbit.com |