Servo Controller

The HiTechnic Servo Controller is available from Lego Education. It can control up to 6 standard PWM servos via a Sensor Port on a LEGO NXT brick.

You can view the Servo Controller service using a web browser as shown in the following diagram:

Click for larger image

Status will be 1 if servos are moving, 0 if not.

Step time can be set 0 if not used, or 1 - 15 to cause servos to synchronize so that they reach their target positions at the same time.

PWM enable must be set to 0 to enable the servos. When set to 255 (0xFF) the servos will be disabled, which is the power-up state. If there is no I2C activity for 10 seconds, then PWM enable is set to 255 to disable the servos. If you do not want a timeout, set PWM enable to 170 (0xAA).
NOTE: The way that this service works, the controller is polled based on the Polling Interval (ms) so it is unlikely that a timeout will occur. The Polling Interval can be set to a negative value to suppress polling so that the built-in timeout feature can be used.

Servo 1-6 positions range from 0-255 (0.75-2.25ms PWM signal).
NOTE: Some servos cannot rotate over this full range and will hit their internal stops which can cause them to draw excessive current.

The servo controller is initially disabled when the controller is turned on. If your servos do not seem to be moving, make sure that you have enabled the controller. There are two enabled modes that are defined in the ServoControllerMode enum:
EnabledNoTimeout (0xAA)
EnabledTimeout (0x00)

EnabledNoTimeout is the most commonly used mode. Changes to the servo positions take place immediately and the servos will hold their positions indefinitely.

EnabledTimeout will automatically disable the servo PWM signals after 10 seconds if there are no commands received by the controller. This is a safety feature that is built into the controller. However, for it to work you must set the Polling Interval to a negative value, i.e. < 0, to prevent polling from resetting the timeout.

You can set the initial servo positions in the config file or programmatically. When you enable the controller, all the servos will move to the specified positions. This allows you to configure the servos appropriately for your application. However, until the servos are enabled they will not hold their positions, i.e. they might "fall down" if there is weight applied. It depends on the stiffness of the servos.

Make sure that you know the valid range for your servo(s). Not all servos can handle 0 to 255. You should test the servo carefully, e.g. try 50, 40, ... 0 before you send a 0 position. A servo that is commanded to drive past its stop will continue to draw power. Cheap servos might even burn out if left this way for a long time.

There is a TimeStamp field in each of the Update requests. This is intended for use in Notifications and does not have to be set for a Request, i.e. it can be null.

AllServosUpdate sets all of the servos with a single write to the controller. This is as close as you can get to simultaneous. Note that the Step Time will affect how long it takes for each servo to move to its target position.

MultipleServosUpdate is just a convenient way to set the positions of more than one servo in a single request (rather than several SingleServoUpdate requests). The servos are positioned via separate writes to the controller and so they are not "simultaneous", although you might not see any difference because it is still quite fast.


It takes some time for Servo or Motor update requests to be processed. If you send requests too fast, they will queue up. This results in behavior that causes servos/motors to keep moving long after they should have reached their target. For example, this happens if you try to control servos using a joystick. To get around this problem, you can "throttle" the request. See the ServoControllerTest and MotorControllerTest VPL programs for examples of how to do this.

Sometimes the polling will interfere with update commands and there will be a communications error on the controller. This causes the LEGO Brick service to reset the controller. Unfortunately, this disables the servos. It therefore appears that the service has died. To resolve this problem temporarily, the Disable command has been removed from the initialization code.

Servo Controllers and DC Motor Controllers are designed to be daisy-chained up to 4 deep on a single NXT sensor port. The I2C bus address is determined by the position in the chain by using the voltage on one of the pins. It will be 2, 4, 6 or 8 as you move further away from the brick. This makes configuration a little complicated.
NOTE: For the first version of this service, daisy-chaining is NOT supported.

Last edited Mar 2, 2010 at 7:11 AM by TrevorTaylor, version 6


No comments yet.