arduino servo motor

16
Arduino Servo Motor Control

Upload: jirapong-manit

Post on 27-Oct-2014

363 views

Category:

Documents


13 download

TRANSCRIPT

Page 1: Arduino Servo Motor

Arduino Servo Motor Control

Page 2: Arduino Servo Motor

Outline

● Tower Pro SG-5010● Wiring Diagram● Arduino Servo Shield● Arduino Servo Library● Communication Protocol● Let's Roll...

Page 3: Arduino Servo Motor

Tower Pro SG-5010● Operating Voltage: 4.8V~6.0V

● Stall torque:5.50 kg-cm (4.8V)6.50 kg-cm (6.0V)

● Operating speed:0.20 sec/60degree (4.8V)0.16 sec/60degree (6.0V)

● Dead band width: 10us

● Temperature Range: 0 ~ 55℃ ℃● Dimension: 40.2 x 20.2 x 43.2

mm

● Rotational Range: 180 degree

Page 4: Arduino Servo Motor

Wiring Diagram

VCC

GND

SIGNAL

Page 5: Arduino Servo Motor

Arduino Servo Shield

Page 6: Arduino Servo Motor

Arduino Servo Library

● #include <Servo.h>● Functions:

– attach()

– write()

– writeMicroseconds()

– read()

– attached()

– detach()

Page 7: Arduino Servo Motor

Functions● attach()

● Attach the Servo variable to a pin.

● Syntax:servo.attach(pin)servo.attach(pin, min, max)

● Parameterspin: the number of the pin that the servo is attached to

min (optional): the pulse width, in microseconds, (defaults to 544)

max (optional): the pulse width, in microseconds, (defaults to 2400)

Page 8: Arduino Servo Motor

Functions

● write()

● Writes a value to the servo, controlling the shaft accordingly.

● Syntax:servo.write(angle)

● Parametersangle: the value to write to the servo, from 0 to 180

Page 9: Arduino Servo Motor

Functions

● writeMicroseconds()

● Writes a value in microseconds (uS) to the servo, controlling the shaft accordingly.

● Syntax:servo.writeMicroseconds(uS)

● ParametersuS: the value of the parameter in microseconds(int)

Page 10: Arduino Servo Motor

Functions

● read()

● Read the current angle of the servo (the value passed to the last call to write()).

● Syntax:servo.read()

● Returns:

The angle of the servo, from 0 to 180 degrees.

Page 11: Arduino Servo Motor

Functions

● attached()

● Check whether the Servo variable is attached to a pin.

● Syntax:servo.attached()

● Returns:

true if the servo is attached to pin; false otherwise.

Page 12: Arduino Servo Motor

Functions

● detach()

● Detach the Servo variable from its pin. If all Servo variables are detached, then pins 9 and 10 can be used for PWM output with analogWrite().

● Syntax:servo.detach()

Page 13: Arduino Servo Motor

Example#include <Servo.h>

Servo myservo; // create servo object to control a servo // a maximum of eight servo objects can be created

int pos = 0; // variable to store the servo position

void setup() { myservo.attach(9); // attaches the servo on pin 9 to the servo object }

void loop() { for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees { // in steps of 1 degree myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position }

for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees { myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } }

Page 14: Arduino Servo Motor

Communication Protocol

● What is the protocol?● Why do we need a protocol?

Page 15: Arduino Servo Motor

Communication Protocol

0xFF 0xFF Motor No. Angle CheckSum

● An example of 5 bytes command

● First two bytes (0xFF) as the starting bytes

● Angel from 0 ~ 180

● Check Sum = Byte1^Byte2^Byte3^...^ByteN

Page 16: Arduino Servo Motor

Let's Roll...

● Try to control two and more servo motor. ● Try to assign a home position to the robot arm.● Try to assign the robot arm to another pose and

them back to the home position