Servo
Move servos and read them. Positions normally run from 1 to 180, kept inside each servo's minimum and maximum limits. Velocity sets how fast a servo moves to its next position and acceleration how gently it starts; release lets a servo go limp. Servos on an EZB's d0 to d23 ports and virtual ports v0 and up (used by servo driver robot skills such as Dynamixel) are moved the same way.
Where to find it: type Servo. in a JavaScript script, or open the ARCx API view of the script editor and expand Servo
Commands
| Command | What it does |
|---|---|
| Servo.decrement | Moves a servo down by a number of positions from the last position it was told to move to. |
| Servo.getAcceleration | Gets the last acceleration set for a servo. |
| Servo.getFineTuneOffset | Gets the fine tune offset of a servo, which is added to every position sent to it. |
| Servo.getPosition | Gets the last position a servo was told to move to. |
| Servo.getPositionRealtime | Asks a servo for its actual position, for servos that can report it (such as smart servos driven by a robot skill). |
| Servo.getVelocity | Gets the last velocity (speed) set for a servo, where 0 is fastest. |
| Servo.increment | Moves a servo up by a number of positions from the last position it was told to move to. |
| Servo.isReleased | Checks whether a servo is released (not holding a position). |
| Servo.release | Releases a servo so it stops holding its position and goes limp. |
| Servo.releaseAll | Releases every servo on the first EZB, including virtual ones, so they stop holding their positions and go limp. |
| Servo.setAcceleration | Sets how quickly a servo speeds up and slows down, for servo drivers that support it (such as smart servo robot skills). |
| Servo.setFineTuneOffset | Sets a fine tune offset for a servo, which is added to every position sent to it to correct small mounting errors. |
| Servo.setMaxPositionLimit | Sets the highest position a servo is allowed to go. |
| Servo.setMinPositionLimit | Sets the lowest position a servo is allowed to go. |
| Servo.setPosition | Moves a servo to a position. |
| Servo.setPositionRandom | Moves a servo to a random position from lowPosition to highPosition, both included, trying not to repeat the last random number. |
| Servo.setVelocity | Sets how fast a servo moves to its next positions. |
| Servo.waitForMove | Pauses the script until a servo is told to move to a different position than it had when this was called, checking every 100 ms. |
| Servo.waitForPositionEquals | Pauses the script until a servo's last commanded position equals the given position, checking every 100 ms. |
| Servo.waitForPositionHigher | Pauses the script until a servo's last commanded position is higher than the given position, checking every 100 ms. |
| Servo.waitForPositionLower | Pauses the script until a servo's last commanded position is lower than the given position, checking every 100 ms. |
Details
Servo.decrement
Moves a servo down by a number of positions from the last position it was told to move to. The move is kept inside the servo's limits and the script does not wait for it to arrive.
Servo.decrement(port, count)
Servo.decrement(port, count, ezbIndex)
| Value | Type | What it is |
|---|---|---|
port |
number | The servo port, such as d0 or v0. |
count |
number | How many positions to subtract, such as 5. |
ezbIndex |
number | Optional. Which EZB to use, 0 being the first one. |
Gives back: number. The position that was asked for, before the servo's limits are applied.
Servo.getAcceleration
Gets the last acceleration set for a servo.
Servo.getAcceleration(port)
Servo.getAcceleration(port, ezbIndex)
| Value | Type | What it is |
|---|---|---|
port |
number | The servo port, such as d0 or v0. |
ezbIndex |
number | Optional. Which EZB to use, 0 being the first one. |
Gives back: number. The last acceleration set, or -1 if none has been set since the EZB connected.
Servo.getFineTuneOffset
Gets the fine tune offset of a servo, which is added to every position sent to it.
Servo.getFineTuneOffset(port)
Servo.getFineTuneOffset(port, ezbIndex)
| Value | Type | What it is |
|---|---|---|
port |
number | The servo port, such as d0 or v0. |
ezbIndex |
number | Optional. Which EZB to use, 0 being the first one. |
Gives back: number. The fine tune offset, or 0 when none is set.
Servo.getPosition
Gets the last position a servo was told to move to. This is remembered by ARCx, not read from the servo, so it is 0 if the servo has not been moved since the EZB connected.
Servo.getPosition(port)
Servo.getPosition(port, ezbIndex)
| Value | Type | What it is |
|---|---|---|
port |
number | The servo port, such as d0 or v0. |
ezbIndex |
number | Optional. Which EZB to use, 0 being the first one. |
Gives back: number. The last position the servo was moved to, or 0 if it has not been moved yet.
Servo.getPositionRealtime
Asks a servo for its actual position, for servos that can report it (such as smart servos driven by a robot skill). Other servos give the last position they were told to move to.
Servo.getPositionRealtime(port)
Servo.getPositionRealtime(port, ezbIndex)
| Value | Type | What it is |
|---|---|---|
port |
number | The servo port, such as d0 or v0. |
ezbIndex |
number | Optional. Which EZB to use, 0 being the first one. |
Gives back: number. The servo's actual position, or its last commanded position when it cannot be read.
Servo.getVelocity
Gets the last velocity (speed) set for a servo, where 0 is fastest.
Servo.getVelocity(port)
Servo.getVelocity(port, ezbIndex)
| Value | Type | What it is |
|---|---|---|
port |
number | The servo port, such as d0 or v0. |
ezbIndex |
number | Optional. Which EZB to use, 0 being the first one. |
Gives back: number. The last velocity set, or -1 if none has been set since the EZB connected.
Servo.increment
Moves a servo up by a number of positions from the last position it was told to move to. The move is kept inside the servo's limits and the script does not wait for it to arrive.
Servo.increment(port, count)
Servo.increment(port, count, ezbIndex)
| Value | Type | What it is |
|---|---|---|
port |
number | The servo port, such as d0 or v0. |
count |
number | How many positions to add, such as 5. |
ezbIndex |
number | Optional. Which EZB to use, 0 being the first one. |
Gives back: number. The position that was asked for, before the servo's limits are applied.
Servo.isReleased
Checks whether a servo is released (not holding a position). Servos start released when the EZB connects and stop being released once they are moved.
Servo.isReleased(port)
Servo.isReleased(port, ezbIndex)
| Value | Type | What it is |
|---|---|---|
port |
number | The servo port, such as d0 or v0. |
ezbIndex |
number | Optional. Which EZB to use, 0 being the first one. |
Gives back: boolean. Whether the servo is released.
Servo.release
Releases a servo so it stops holding its position and goes limp. Moving it again makes it hold its position again.
Servo.release(port)
Servo.release(port, ezbIndex)
| Value | Type | What it is |
|---|---|---|
port |
number | The servo port, such as d0 or v0. |
ezbIndex |
number | Optional. Which EZB to use, 0 being the first one. |
Servo.releaseAll
Releases every servo on the first EZB, including virtual ones, so they stop holding their positions and go limp.
Servo.releaseAll()
Servo.releaseAll(ezbIndex)
| Value | Type | What it is |
|---|---|---|
ezbIndex |
number | Optional. Which EZB to use, 0 being the first one. |
Servo.setAcceleration
Sets how quickly a servo speeds up and slows down, for servo drivers that support it (such as smart servo robot skills). Standard servos on an EZB's d0 to d23 ports ignore it.
Servo.setAcceleration(port, acceleration)
Servo.setAcceleration(port, acceleration, ezbIndex)
| Value | Type | What it is |
|---|---|---|
port |
number | The servo port, such as d0 or v0. |
acceleration |
number | The acceleration; its range depends on the servo driver, and -1 is ignored. |
ezbIndex |
number | Optional. Which EZB to use, 0 being the first one. |
Servo.setFineTuneOffset
Sets a fine tune offset for a servo, which is added to every position sent to it to correct small mounting errors. Does not move the servo; it takes effect on the next move.
Servo.setFineTuneOffset(port, offset)
Servo.setFineTuneOffset(port, offset, ezbIndex)
| Value | Type | What it is |
|---|---|---|
port |
number | The servo port, such as d0 or v0. |
offset |
number | How many positions to shift by, negative or positive, such as -3 or 2. |
ezbIndex |
number | Optional. Which EZB to use, 0 being the first one. |
Servo.setMaxPositionLimit
Sets the highest position a servo is allowed to go. Later moves above it stop at this limit; the servo is not moved now.
Servo.setMaxPositionLimit(port, position)
Servo.setMaxPositionLimit(port, position, ezbIndex)
| Value | Type | What it is |
|---|---|---|
port |
number | The servo port, such as d0 or v0. |
position |
number | The highest allowed position, such as 150. |
ezbIndex |
number | Optional. Which EZB to use, 0 being the first one. |
Servo.setMinPositionLimit
Sets the lowest position a servo is allowed to go. Later moves below it stop at this limit; the servo is not moved now.
Servo.setMinPositionLimit(port, position)
Servo.setMinPositionLimit(port, position, ezbIndex)
| Value | Type | What it is |
|---|---|---|
port |
number | The servo port, such as d0 or v0. |
position |
number | The lowest allowed position, such as 30. |
ezbIndex |
number | Optional. Which EZB to use, 0 being the first one. |
Servo.setPosition
Moves a servo to a position. The script carries on straight away without waiting for the servo to arrive, and the position is kept inside the servo's min and max limits.
Servo.setPosition(port, position)
Servo.setPosition(port, position, ezbIndex)
| Value | Type | What it is |
|---|---|---|
port |
number | The servo port, such as d0 or v0. |
position |
number | The position to move to, normally 1 to 180 (the project's max servo position). |
ezbIndex |
number | Optional. Which EZB to use, 0 being the first one. |
Servo.setPositionRandom
Moves a servo to a random position from lowPosition to highPosition, both included, trying not to repeat the last random number. The script does not wait for the servo to arrive.
Servo.setPositionRandom(servo, lowPosition, highPosition)
Servo.setPositionRandom(servo, lowPosition, highPosition, ezbIndex)
| Value | Type | What it is |
|---|---|---|
servo |
number | The servo port, such as d0 or v0. |
lowPosition |
number | The lowest position that can be chosen. |
highPosition |
number | The highest position that can be chosen. |
ezbIndex |
number | Optional. Which EZB to use, 0 being the first one. |
Gives back: number. The random position that was chosen.
Servo.setVelocity
Sets how fast a servo moves to its next positions. For servos on an EZB's d0 to d23 ports, 0 is fastest and 20 is slowest; other servo types pass the value to their own driver.
Servo.setVelocity(port, velocity)
Servo.setVelocity(port, velocity, ezbIndex)
| Value | Type | What it is |
|---|---|---|
port |
number | The servo port, such as d0 or v0. |
velocity |
number | The speed, 0 being fastest; 0 to 20 for servos on d0 to d23, and -1 is ignored. |
ezbIndex |
number | Optional. Which EZB to use, 0 being the first one. |
Servo.waitForMove
Pauses the script until a servo is told to move to a different position than it had when this was called, checking every 100 ms.
Servo.waitForMove(port)
Servo.waitForMove(port, ezbIndex)
| Value | Type | What it is |
|---|---|---|
port |
number | The servo port, such as d0 or v0. |
ezbIndex |
number | Optional. Which EZB to use, 0 being the first one. |
Gives back: number. The servo's new position, or -1 if the script was stopped while waiting.
Servo.waitForPositionEquals
Pauses the script until a servo's last commanded position equals the given position, checking every 100 ms. Also returns if the script is stopped while waiting.
Servo.waitForPositionEquals(port, position)
Servo.waitForPositionEquals(port, position, ezbIndex)
| Value | Type | What it is |
|---|---|---|
port |
number | The servo port, such as d0 or v0. |
position |
number | The position to wait for. |
ezbIndex |
number | Optional. Which EZB to use, 0 being the first one. |
Servo.waitForPositionHigher
Pauses the script until a servo's last commanded position is higher than the given position, checking every 100 ms. It watches the position servos are told to go to, not a reading from the servo.
Servo.waitForPositionHigher(port, position)
Servo.waitForPositionHigher(port, position, ezbIndex)
| Value | Type | What it is |
|---|---|---|
port |
number | The servo port, such as d0 or v0. |
position |
number | The position the servo has to go above. |
ezbIndex |
number | Optional. Which EZB to use, 0 being the first one. |
Gives back: number. The servo's position once it is higher, or -1 if the script was stopped while waiting.
Servo.waitForPositionLower
Pauses the script until a servo's last commanded position is lower than the given position, checking every 100 ms. It watches the position servos are told to go to, not a reading from the servo.
Servo.waitForPositionLower(port, position)
Servo.waitForPositionLower(port, position, ezbIndex)
| Value | Type | What it is |
|---|---|---|
port |
number | The servo port, such as d0 or v0. |
position |
number | The position the servo has to go below. |
ezbIndex |
number | Optional. Which EZB to use, 0 being the first one. |
Gives back: number. The servo's position once it is lower, or -1 if the script was stopped while waiting.