Thursday, 9 February 2017

Servo Motors - Sophie Wicks


I have never worked with servo motors before now so this part was very new to me. I got a quick run over with servos from Tommy who worked with them in the 3rd year project. I had the vision system working with the mbed and thought I could control the motor using the vision system....

Working with the Servos

I got a simple hello world working with one of the servos that went to some fixed positions. I decided to use the head tracking code that was used on BENGiE's vision system that I used in my own third year project in the VBScript module. I obtained the X and Y center of gravity co-ordinates and two data messages were changing accordingly. I used the value from one of the data variables as the input to the servo's position.

The serial data was being read into the servo using pc.getc() which read in characters from the vision system on the serial port. I assigned the variable being read in on the serial port as "msg" and tried to plot the servo to go to the position that Roborealm was outputting.


The communication from RoboRealm was getting to the board, however the servo locked in one position. I moved the object around the frame to see that the variable being sent to the board was also changing. I noticed that because the value being read on the mbed is expecting a character, that the integer value being sent down was not of the same data type. I also noticed that the ASCII to integer conversion might be incorrect so I toook the "msg" data being read in a subtracted 48 from it to account for the offset. 

I tried to get the motor to track the center of gravity of the object for a number of hours with no luck. I have since been informed that the scanf() function looks after the data type variance when something is being read to the mbed serially. In a future revision, and with more time, I would like to keep working on this issue. I didn't get far enough to add the code into an RTOS thread however I have attached the code that I parked the motors with below. 

 #include "mbed.h"
 #include "Servo.h"
 #include "C12832.h"

C12832 lcd(p5, p7, p6, p8, p11); 
  Servo myservo(p21);
  Serial pc(USBTX, USBRX);
  char msg = '0';
  int send;
  int main() 
        msg = pc.getc();
        send = msg - 48;
        // pc.printf(" this is: %d\n\r", send);
            lcd.printf("number is %s", send);

        if (send < 170) // to protect the motor, only send values less than 170
            // pc.printf(" i have serial comms %f\n\r", msg);
           //pc.printf(" this is the value read: %d\n\r", send);

No comments:

Post a Comment