Electronics_Servo controller (hardware and firmware)

We need to control multiple servo motors in this project. For example steering system is directly hooked into a servo, or possibly for a camera that we are going to need to rotate, etc.

A servomotor is a rotary actuator or linear actuator that allows for precise control of angular or linear position, velocity and acceleration. It consists of a suitable motor coupled to a sensor for position feedback. It also requires a relatively sophisticated controller, often a dedicated module designed specifically for use with servomotors. 

More on servomotors 

The type of servos I am going to use are mostly Futaba s3003.

I have assembled a controller for multiple (up to 15) servos. Using Arduino, I have wrote a small simple program to control them using serial.

The devices I have user for this part are:

IIC servo controller (which is a replica of Adafruit PCA9685 PWM servo driver)

Arduino nano

LM2596S DC-DC 4.5-40V Adjustable Step Down Power Supply Module 


The circuit is easy to assemble and due to rapid changes and our tendency to keep things as simple as possible I wont get into designing and printing PCBs. I am going to use schematics made with Fritzing:

The controller circuit

Servo controller uses I2C to connect to Arduino. Using Arduino nano pin-out map we can see:

Arduino nano pinout

 

A4 is SDA and A5 is SCL. We have also used the D3 port for breakout enable/disable and Arduino 5V/GND to power the breakout.

The firmware I wrote for Arduino in order to communicate with controller and serial to control multiple servos can be found here:

serial_servo_controller

It is a small and highly readable piece of code and does not need much elaboration. It reads the input string from USART until it sees an '@' character or a timeout happens, then looks to see if the input string matches any of "query", "on", "off", "reset" or a "#servoNumber^Degree#servoNumber^Degree..." pattern. If it did match, returns a string containing device name, turns device on/off, resets all servos to 90degree or uses the pattern to control servos.

After uploading the code on the Arduino (Arduino is connected using a USB cable), connecting the convertor to the power and connecting the servos to the connectors we can simply write (for example in Linux, assuming the Arduino port to be /dev/ttyUSB0):
$sudo stty 57600 -F /dev/ttyUSB0
$sudo -i

for listening to device:
$cat -v /dev/ttyUSB0

and writing to it using another terminal:
$sudo i
$echo 'on@'> /dev/ttyUSB0 

we will get a message on the other terminal:
servo_controller on

after that:
$echo '#0^10#1^20#2^30#3^40@'> /dev/ttyUSB0

And servo 0 will go to 10 degree, 1 to 20, 2 to 30, etc. 

All commands should end in '@' character.

To control the servos before each one we use a '#', after that number of servo (0 to 15) after that '^', and the angle we want it to take (0-180 degree), we repeat this pattern as needed, the order of servos does not matter, and at the end of the command a '@':

on@
off@
reset@
#0^10#1^20#2^30#3^40@

The program ignores servo numbers exceeding 15 and maps all input angles to 0-180. The pulse width and frequency is tuned based on characteristics of Futaba s3003 servo and might or might not work with other servos and PWM controlled devices.

Assembled servo controller

Arash Ardeshiri

July 5 2021





Comments

Popular posts from this blog

Mechanics_Chassis

Software_Video streaming services

Software_Joystick service