Board Functionality - WE-Bots/ServoControl GitHub Wiki

Board Functionality

This document will outline the various functions of the board. For setting or changing any of the functions of the board through the serial interface, please see the Boards Commands document for a full outline of the all the commands that can be sent to the board.

Table of Contents

  • [Basic PWM Control](#Basic PWM Controls)
  • [Changing the PWM] (#Changing The PWM)
  • [Sequence Delays] (#Sequence Delay)
  • [Sequence Replay] (#Sequence Replay)
  • [Freeze Playback] (#Freeze Playback)
  • [Setting Start Position] (#Setting Start Position)
  • [Loading Values Into RAM](#Loading Values Into RAM)
## Basic PWM Controls

The basic function of the board is to generate a PWM signal to control a servo or similar device. The signal generate has a period of about 8 ms and an active time between 0.5ms and 1.5 ms. This allows it to control standard RC servos and motor controllers.

By sending commands the the board the PWM signal that is being generated can be changed. This will have the affect of moving the servo to the new position as fast as the servo is able to move. This is one of the more common methods of moving a servo but it works well and is easy for a beginner to use.

The position values that are sent to each servo is a number between 1 and 97. These numbers map directly to the pulse widths generated, but will not map well to positions on a physical device. This is due to the inherent non-linearity of many servo motors. Thus the mapping must be found on a case by case basis.

## Changing The PWM

By default when a new value is received by the servo board it will send the new value out to the servo as quickly as it can. This results in the servo moving to the new position quickly, starting and stopping the motion very abruptly and possibly overshooting the final intended location. In order to prevent this the board offers a feature called PWM sweep and delay that allows for the change in position to be controlled and move in a smoother motion. Note that since the pulse width can only be changed in discrete increments it will not be possible to ever have a perfectly smooth motion, but it can be approximated very well.

In order to achieve the smooth motion, there are two parameters that must be set; the PWM sweep and the PWM repeat. The sweep is the value that will be added or subtracted from the current pulse width of the signal as it moves from the starting to the final value. The repeat is the number of time intervals the same pulse width will be sent before a new one is calculated. The process is outlined in the pseudo code below.

    Every time increment
       if (increment_count == PWM_repeat)
          pulse_width = pulse_width + PWM_sweep
          increment_count = 0
          if (pulse_width overshoots target)
             pulse_width = target
          end if 
       end if 
       else
          increment_count += 1
       end else
     end
Note: pulse_width is the width of the pulse currently being output

There are only a few values that sweep and repeat can hold, but these encompass most of the common applications. If a greater number of possible sweeps are required it would necessitate a change to the firmware of the board. The board will not wait for a current sweep to complete before changing the target position if a new command was sent which can result in unusual behavior. If new values for the PWM sweep or PWM repeat are received by the board while it is in a sweep motion it will result in undefined behavior.

## Sequence Delay

A sequence delay is used when there are a number of positions either being sent to the board, or being replayed by the board after being stored there. The delay sets the number of seconds between two subsequent positions in the sequence. This is primary used to allow a robot to 'settle' or regain its balance after a particularly tricky motion or to allow for a slow sweep operation to finish before moving the the next target position.

There is a set number of values that the delay can take, as it must fit in an unsigned nibble. This means that you can have a delay from 1 to 15 s. There is no 0 length delay as it would not result in desirable behavior.

## Sequence Replay

The sequence replay is the number of times that a sequence will be completely replayed by the servo board. This is used generally for testing a sequence of motions to make sure that the motion from the final positions to the starting position will not cause any issues. As well it can be used for repeating the motions of a robot while it is walking a course.

The replay can only take a few values, outline in the communication document, but they cover a range of values and all common use cases.

## Freeze Playback

The freeze playback function prevents the servo board from changing any of the pulse widths currently being output, even if new positions are being received. This allows for a new position for all of the servos to be sent without having to worry about having one of the servos to start moving too soon.

The standard usage of this command is to send the freeze command followed by a new position for the servos, and then the unfreeze commands. This will start all of the servos moving at the same time. There will no no difference noticed with using this command and not using it for a device with only a few servos, but for a device with 12 servos there is a minimum 75 ms delay between starting sending the first position and receiving the final position. This difference is start times for the servos can result in unexpected behavior by the robot.

## Setting Start Position

When the servo board first powers up there are default values that are loaded into the pulse width register and it begins to output them. This can results in servos moving and motors starting depending on the controllers used. To prevent this from happening the default values can be changed and stored on the board. This can be used to prevent a robot from moving to and unsafe position at start up.

The start position must be changed for all of the servos at once, even if some are not currently being used or in need of changing. The default values for the servos can be any valid position value.

## Loading Values Into RAM

The board allows you to store sequence data in the RAM of the device. Once the data has been stored, it can be replayed by the board after the communication link is removed. The data will only be stored as long as the board is powered.

The data must fit within a specified format, with either 36 positions for data for one servo, 12 positions for 3 servos, or 3 positions for all 12 servos. The limits are imposed by the space that the data can be stored in on the chip and how the information is being represented in memory.

For complete instructions on how to load the data into RAM see the communications guide.

⚠️ **GitHub.com Fallback** ⚠️