When it comes to Robotics, Parallax continuous rotation robotics servo is the entry point item that every student needs to master. In this post, we will show how to drive Parallax continuous rotation servo on pcDuino through the linker servo module.
The datasheet of the parallax continuous rotation servo can be found at 154datasheet. It needs a 50Hz with variable duty cycle to change its direction.
We will use linker servo module that is connected to [D1 D2 V S] slot of the Linker base shield. The code is as follows:
#include <core.h>
//***************************************
//*function: Rotate clockwire
//*parameters: pwm (select the channel of PWM)
//* Speed (100<Speed<300)
//*Description: The larger the value of speed, the slower the rotation.
//***************************************
void forward(unsigned char pwm,unsigned int Speed)
{
if((Speed>100)&&(Speed<300))
{
//cammand : S + PWM + Duty_H + Duty_L + E
Serial.print('S'); //Start
Serial.print(char(pwm)); //PWM channel selection
Serial.print(char(Speed/0xFF)); //Duty HIGH
Serial.print(char(Speed%0xFF)); //Duty LOW
Serial.print('E'); //End
}
}
//***************************************
//*function: Servo rotates counter-clockwise
//*Parameter: pwm (select the channel of PWM)
//* Speed (300<Speed<500)
//*Description:The smaller the value of Speed, the slower the rotation.
//***************************************
void backward(unsigned char pwm,unsigned int Speed)
{
if((Speed>300)&&(Speed<500))
{
Serial.print('S'); //Start
Serial.print(char(pwm)); //PWM channel selection
Serial.print(char(Speed/0xFF)); //Duty HIGH
Serial.print(char(Speed%0xFF)); //Duty LOW
Serial.print('E'); //End
}
}
//***************************************
//*Function:Stop
//*paramter:pwm (select the PWM channel)
//* DelayMs (delay value in ms)
//*Description:Stop the servo
//***************************************
void ServoStop(unsigned char pwm,unsigned int DelayMs)
{
Serial.print('S'); //Start
Serial.print(char(pwm)); //PWM channel selection
Serial.print(char(305/0xFF)); //Duty HIGH
Serial.print(char(305%0xFF)); //Duty LOW
Serial.print('E'); //End
delay(DelayMs);
}
void setup()
{
Serial.begin(9600);
delay(100);
}
void loop()
{
unsigned int i = 320;
for(i=100;i<=300;i++)
{
forward(1,i);
delay(50);
}
ServoStop(1,1000);
for(i=300;i<=500;i++)
{
backward(1,i);
delay(50);
}
ServoStop(1,1000);
}
The video

Leave a Reply
You must be logged in to post a comment.