Arduino Servo Motor Protocol

With this devicehandler you can control multiple servo motors simultaneously.

A few words about servor motor:
Servo motors can move with high speeds and big torque. When controlling a servo motor you need to determine the angle the motor has to reach. This angle has a maximum limit in clockwise and counterclockwise directions, since the motor is connected to a potmeter and we know that potmeters can't turn infinitely. The motor knows from the potmeter's voltage value that if it has reached the preferred angle.
To see a simple example please check out the short datasheet of the SG90 micro servo motor:
SG90MicroServo_datasheet.pdf

How to build a test circuit with 3 servo motors and an Arduino Mega?
Arduino codes are included.

I. Startup events from microcontroller in sending order

1. "Welcome" event

Example

c=welcome&id=IqlZci&type=OzServoController&pos=2&t=3

Parameters

Parameter Type Range Functionality
c String "welcome" Identifies the welcome message.
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.
type String "OzServoController" Determines the type of the device.
pos Byte 0-255 Determines the position of the device on the list of the ID manager of the microcontroller. Please make sure there are no other devices in the same position.
t Byte 0-255 Counts the number of events and responses sent combined. Counts from 0 to 255 then from 0 again.



2. "ShowMotorCount" event

Shows the number of servomotors connected to the microcontroller.

//Responds the number of motors
c=showmotorcount&count=10&id=IqlZci&t=3

Parameters

Parameter Type Range Functionality
c String "showmotorcount" Identifies the response.
count Unsigned Int 0-65535 The number of servomotors controlled by the devicehandler. (x, y, z, a... you can call them anyway).
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.
t Byte 0-255 Counts the number of events and responses sent combined. Counts from 0 to 255 then from 0 again.



3. "MotorDetails" events

It gives a name for each servomotor and shows their minimum and maximum angle. For the first boot the angles of the motors are set halfway between their min and max value.

//Responds the motordetails for each servomotor
[c=motordetails&axis=x&min=-60.00&max=-24.00&angle=-42.00&id=IqlZci&t=4]
[c=motordetails&axis=y&min=-120.00&max=180.00&angle=30.00&id=IqlZci&t=5]
[c=motordetails&axis=z&min=-360.00&max=360.00&angle=0.00&id=IqlZci&t=6]
[...]
[c=motordetails&axis=g&min=76.12&max=180.00&angle=128.06&id=IqlZci&t=10]

Parameters

Parameter Type Range Functionality
c String "motordetails" Identifies the response.
axis Char Motor ID (x | y | z | a |... you can call them anyway) The ID we will refer to the motor. They are lower case characters.
min Double -360.00 to 360.00 The minimum angle limit of the motor. Can't be bigger then the "max" parameter.
max Double -360.00 to +360.00 The maximum angle limit of the motor. Can't be smaller then the "min" parameter.
angle Double -360.00 to +360.00 This is the current angle of the motor. At the first boot it's the average between the minimum and maximum angle of the motor.
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.
t Byte 0-255 Counts the number of events and responses sent combined. Counts from 0 to 255 then from 0 again.



II. Commands to microcontroller

"Go" command

This command turns multiple servomotors to the chosen angles, between the minimum and maximum angle limits, as fast as it can. If the motor reaches the chosen angle it tries to keep it there.

Example

//Moves only the 'x', 'y', 'a' motors
c=go&x=10&y=0&a=-70&t=0&id=IqlZci

Parameters

Parameter Type Range Functionality
c String "go" Identifies the command.
Motor ID (x | y | z | a | b ...) Double -360.00 to +360.00 Determines which motor needs to move to which angle. Motors can be <x, y, z, a, b...>. If the motor is in the desired angle then it won't move anywhere.
t Byte 0-255 Counts the number of commands sent. Counts from 0 to 255 then from 0 again.
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.

Response

The respond is sent instantly even if the motor have not reached the required position. If the the target angle is changed the motor tries to instantly position itself to the new target angle.

//Moves only the 'x', 'y', 'a' motors - response
c=go_resp&x=10.00&y=0.00&a=-70.00&id=IqlZci&t=11

Parameters

Parameter Type Range Functionality
c String "go_resp" Identifies the response.
Motor ID (x | y | z | a | b ...) Double Minimum motor angle to Maximum motor angle Determines which motors are trying to stay at which angles. Motors can be <x, y, z, a, b...>. If the ordered angle is not between the minimum or maximum angle of the motor, it will be set to the minimum or maximum angle as a default.
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.
t Byte 0-255 Counts the number of events and responses sent combined. Counts from 0 to 255 then from 0 again.



"ShowMotorDetails" command

This command shows details of the servomotors. This is useful to refresh the informations of the servomotors.

Example

c=showmotordetails&t=1&id=IqlZci

Parameters

Parameter Type Range Functionality
c String "showmotordetails" Identifies the command.
t Byte 0-255 Counts the number of commands sent. Counts from 0 to 255 then from 0 again.
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.

Response

Responds the "ShowMotorCount" and "MotorDetails" events. These are the same events that are sent when the device boots up, but with this "ShowMotorDetails" command you can ask for them again.

//Responds the motordetails
[c=showmotorcount&count=10&id=IqlZci&t=12]
[c=motordetails&axis=x&min=-60.50&max=-24.00&angle=-30.00&id=IqlZci&t=13]
[c=motordetails&axis=y&min=-120.00&max=180.00&angle=-10.00&id=IqlZci&t=14]
[c=motordetails&axis=z&min=-360.00&max=360.00&angle=20.23&id=IqlZci&t=15]
[...]
[c=motordetails&axis=g&min=76.12&max=180.00&angle=90.00&id=IqlZci&t=21]

More information