Monday, 23 March 2015

Di-leong Chan - Servo Learning

With the new sprint, teams and tasks I was assigned to servos control. I started off by looking up the name of the
servo to be used which was a pallalax ( From there reading up on the
documentation the servo was a 180 degrees servo which could be controlled from the command inputted. Online within
the documentation I found the some servo codes as shown below.

When trying to recreate this I found that the "simpletools.h" wasn't locatable. So rather than doing it by the book I
assigned the servos to the pot value.

inData =;

The above snippet was to get an idea on how the servos worked. When applying
this code it was found that the servos full range was not reached. the range was found to be from 70 to 130 degrees
(taking into account full right is 0 degrees and full left is 180 degrees). The next part was to investigate into what
were the values to control the full range of the servos, I implemented this in the code shown below.

#include "mbed.h"
#include "Servo.h"
#include "C12832.h" // Include the LCD header files

PwmOut s1(p21);
C12832 lcd(p5, p7, p6, p8, p11); // Assign the Header files with the name "lcd" where they are connected via pins 5,6,7,8,11

int main()
        for (float a = 0.068; a <0.12; a = a - 0.001)
            if (a = a)
            s1.write(a); // starts at 90 to the right no vibration
            wait(1); // delay by 2 seconds
            else if (a < 0.000)
            lcd.cls(); // clear screen of the lcd
            lcd.locate(0,3);    // Go to the first row of the LCD
            lcd.printf("Dii's %f",a); //Display the following text
            //s1.write(0.068); // Center postition(no vibrate)
            //s1.write(0.19); // 90 to the right(no vibrate)
            //s1.write(0.117); // 90 to the left(no vibrate)
            //s1.write(0.118); // 90 to the left but vibrates

After some run and testing I displayed the value on the LCD to show the current position so I could map out the position according to the value read which can be read from the above code. From here what the next steps would be to implement it with the sonar sensor for field of depth,


No comments:

Post a Comment