Monday, 15 May 2017

Sprint 2 - Vision Team - Deepak

Goal: To build a Mini-Lampbot and test movement based on the vision system developed
Minutes of the Meeting:
Ø  Status on the Vision Systems Developed
o   Terry – Fully functional facial recognition (up to 6 faces & 300cm in distance)
o   Deepak – Functional face detection and was working on training the vision system to identify faces.
o   Zhuo – Working on developing an Object detection
Ø  Instructions from Client (Mr. Jason Berry)
o   Build a mini-lampbot and test the facial recognition developed by terry
o   Terry to build the complete Mock up
o   Deepak and Zhuo to develop the mbed code to process the serial data from vision system and control the X, Y and Z movement of the mini-lampbot
Introduction:
For this sprint we were given goal to build a mini lampbot and test the vision system developed. I and Zhuo were asked to develop the mbed code to control the lampbot. To make it easier we divided our work into two parts, Zhou would work on the X, Y and Z movement of the mini lampbot and I would work on the serial buffer. An important part of the design was to first determine the working ranges for each motor (in degrees). When discussion on how the each motor would move was crucial to the code. During one of the discussions, Zhuo came up with great solution on how Y and Z motion would together in their movement and also the ranges that we need to set and this put us in the right path to get the right algorithm to make it work. We also felt to code it in our own way and then convert it to mbed RTOS format (discussed in Sprint 3 blogpost).
Reflections on Assigned Work:
The data from the vision system initially contained 5 parameters, as shown below:
F00x000y000d000
Where,
Ø  F à is a flag that determines a face or an object
Ø  X à is the pan movement of the lampbot in degrees
Ø  Y à is the tilt movement of the lampbot in degrees
Ø  D à is the approximate distance of the object or face from the camera in centimetres
Over the course of the sprint, it was identified that an extra variable ‘T’ will be added to the existing buffer, which now will denote the type of detection (object or face) and ‘F’ will act as a flag for multiple faces. Now the buffer will look like:
T00F00x000y000d000
The buffer is received through the serial port and is made available for execution. Terry had already written a code during the sprint 1 and hence made my work little easier by having place to start with. The below code is what I received from Terry (Buffer Part of the code):


#include
//Serial
Serial pc(USBTX, USBRX);
// Buffer
char *token;
char buffer[128];
pc.baud(9600);
            pc.gets(buffer,18); 
            token = strtok(buffer, "'' Fxyd");
            lcd.locate(0,0);
            lcd.printf("%s\n", buffer);
          
            f = atoi(token);                    // Get face #
            token = strtok(NULL, " '' Fxyd");
            lcd.locate(0,8);
            //lcd.printf("t = %s\n", token);
            x = atoi(token);                    // Det x pos
            //x = (int)(token);
            token = strtok(NULL, "'' Fxyd");
            //lcd.printf("token = %s\n", token);
            y = atoi(token);                    // Get y Pos
            //y = (int)(token);
            token = strtok(NULL, "'' Fxyd");
            //lcd.printf("token = %s\n", token);
            d = atoi(token);                    // Get D pos
            lcd.locate(0,17);
            yt = y;              // Set new vari for d outside sweetspot
            lcd.printf("f=%d; x=%d; y=%d d=%d; \n", f, x, y,d);

After making some minor changes based on requirement, the code was modified and the complete code inclusive of Zhou’s control algorithm is:

#include "mbed.h"
#include "C12832.h"
#include 
#include "Servo.h"
 
C12832 lcd(p5, p7, p6, p8, p11);
//SErvo 1 & 2
Servo servopan(p21);
Servo servotilt(p22);
Servo servotiltd(p23);
//Serial
Serial pc(USBTX, USBRX);
// Buffer
char *token;
char buffer[128];
int f,d,x,y,yt;
 
int main()
{   
 
servopan.write(85);     //initialise position
servotilt.write(45);    //initialise position
servotiltd.write(85);   //initialise position
 
pc.baud(9600);
lcd.cls();
while(1) {               
 
            //pc.printf("Thread buffer\n");            
            pc.gets(buffer,17);
            //char buffer[] = "T0F1x047y014d052";  
            lcd.locate(0,0);
            lcd.printf("%s\n", buffer);
            token = strtok(buffer, " '' TFxyd");
            T = atoi(token);
            token = strtok(NULL, " '' TFxyd");
            F = atoi(token);                    // Get face #
            token = strtok(NULL, " '' TFxyd");
            x = atoi(token);
            pc.printf("%d", x);                    // Det x pos
            token = strtok(NULL, "'' TFxyd");
            y = atoi(token);                    // Get y Pos
            token = strtok(NULL, "'' TFxyd");
            d = atoi(token);                    // Get D pos
            lcd.locate(0,21);
            //lcd.locate(0,17);
            yt = y;               // Set new vari for d outside sweetspot
            lcd.printf("y=%d x=%d D=%d",x, y,d);
//************************** Pan *************************            
            if (f == 1)                     // Only enter for face # 1
            {
                if((x+85)<10 180="" degree="" nbsp="" o:p="" prevent="" swing="" to="">
                    {
                        servopan.write(10); // Pan min
                    }
                    else if((x+85)>170)
                    {
                        servopan.write(170);    // pan max
                    }
                    else {
                    servopan.write(85+x);       // Else write to servo
                    }
        //************************ End of pan ********************* 
                    if((yt+45)<5 90="" degree="" nbsp="" o:p="" prevent="" swing="" to="">
                    {
                        yt = 10;
                    }
                    else if((yt+45)>90)
                    {
                        yt = 85;   //to prevent 180 degree swing
                    }
                    if((y+85)<5 180="" degree="" nbsp="" o:p="" prevent="" swing="" to="">
                    {
                        y = 10;
                    }
                    else if((y+85)>175)
                    {
                        y = 175;   //to prevent 180 degree swing
                    }
                    
                    if(d<120 close="" is="" nbsp="" o:p="" user="" when="">
                    {
                        servotilt.write(yt+45);
                        servotiltd.write(y+85);
                    }
                    else if(d>180)   //when user is far away
                    {
                        servotilt.write(yt+45);
                        servotiltd.write(y+85);
                    }
                    else  //when user is at comfort zone
                    {
                        servotilt.write(y+45);
                        servotiltd.write(85);
                    }
            }
            wait(0.1);    // Delay of 10 ms
    }
}

Challenges: The given deadline initially was not met and caused some contentions among the team members but after several discussions and an extension on the project delivery date we were able to accomplish what was asked of us.
Summary of Sprint 2:
Ø  Create mini version of lampbot and test the vision system
o   Terry will build a small mock-up of the Lampbot design
o   Zhou and Deepak to write the mbed code to integrate with the vision system
§  Zhou worked on the x, y and z control of the robot
§  Deepak worked on the serial buffer

                     

No comments:

Post a Comment