The FollowMeBot follows the user based on the color of his or her shirt. The device hosts a webcam on a servo to find the object and orient the robot. The color is chosen through the user interface with push buttons. Currently, the MATLAB code supports red and green detection. The purpose of FollowMeBot is to be able to follow the user in order to be helpful for daily tasks.

Dependencies:   Rectangle Servo TextLCD mbed

Fork of FollowMeBot3 by Rahul Shetty

Committer:
dhamilton31
Date:
Mon Nov 18 21:09:13 2013 +0000
Revision:
1:6c399fc35deb
Parent:
0:3ed56271dd2d
Child:
2:0b362c662997
how many things must I commit?!?

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dhamilton31 0:3ed56271dd2d 1 #include "mbed.h"
dhamilton31 0:3ed56271dd2d 2 #include "iRobot.h"
dhamilton31 0:3ed56271dd2d 3 #include "Servo.h"
dhamilton31 1:6c399fc35deb 4 #include "Rectangle.h"
dhamilton31 0:3ed56271dd2d 5
dhamilton31 1:6c399fc35deb 6 // Macros/Constants
dhamilton31 1:6c399fc35deb 7 #define MAX_VIEW_X 1024 // maximum X value input from camera
dhamilton31 1:6c399fc35deb 8 #define MAX_VIEW_Y 1024 // maximum Y value input from camera
dhamilton31 1:6c399fc35deb 9 #define CENTER_BOX_TOLLERANCE 15 // Size of our box
dhamilton31 1:6c399fc35deb 10 #define TO_SERVO_DIVISOR 100.0 // Value to divide by to get the amount to move the servo by
dhamilton31 0:3ed56271dd2d 11
dhamilton31 1:6c399fc35deb 12 // Hardware sensors and devices
dhamilton31 1:6c399fc35deb 13 DigitalOut myled(LED1);
dhamilton31 1:6c399fc35deb 14 iRobot followMeBot(p9, p10);
dhamilton31 1:6c399fc35deb 15 Servo servoHor(p22);
dhamilton31 1:6c399fc35deb 16 Servo servoVer(p21);
dhamilton31 1:6c399fc35deb 17 AnalogIn irSensorFront(p20);
dhamilton31 1:6c399fc35deb 18 AnalogIn irSensorLeft(p19);
dhamilton31 1:6c399fc35deb 19 AnalogIn irSensorRight(p18);
dhamilton31 1:6c399fc35deb 20 Serial pc(USBTX, USBRX); // tx, rx
dhamilton31 1:6c399fc35deb 21
dhamilton31 1:6c399fc35deb 22 // Software variables
dhamilton31 1:6c399fc35deb 23 char serial_rx_buffer[128]; // Input buffer for data from the PC
dhamilton31 1:6c399fc35deb 24 int xpos, ypos; // x and y positions read from matlab
dhamilton31 1:6c399fc35deb 25 Rectangle centerBox((MAX_VIEW_X/2)+CENTER_BOX_TOLLERANCE, (MAX_VIEW_Y/2)+CENTER_BOX_TOLLERANCE,
dhamilton31 1:6c399fc35deb 26 (MAX_VIEW_X/2)-CENTER_BOX_TOLLERANCE,(MAX_VIEW_Y/2)-CENTER_BOX_TOLLERANCE); // Creates a box to examine if the camera is well enough centered
dhamilton31 1:6c399fc35deb 27
dhamilton31 1:6c399fc35deb 28 int main()
dhamilton31 1:6c399fc35deb 29 {
dhamilton31 1:6c399fc35deb 30 followMeBot.start();
dhamilton31 1:6c399fc35deb 31
dhamilton31 0:3ed56271dd2d 32 while(1) {
dhamilton31 0:3ed56271dd2d 33 }
dhamilton31 0:3ed56271dd2d 34 }
dhamilton31 1:6c399fc35deb 35
dhamilton31 1:6c399fc35deb 36 void moveCamera()
dhamilton31 1:6c399fc35deb 37 {
dhamilton31 1:6c399fc35deb 38 if(!centerBox.is_touch(xpos, ypos)) {
dhamilton31 1:6c399fc35deb 39 float temp;
dhamilton31 1:6c399fc35deb 40 temp = servoHor.read() + ((float)centerBox.getCenterX() - (float)xpos)/TO_SERVO_DIVISOR;
dhamilton31 1:6c399fc35deb 41 if(temp > 0 && temp <= 1) {
dhamilton31 1:6c399fc35deb 42 servoHor = temp;
dhamilton31 1:6c399fc35deb 43 }
dhamilton31 1:6c399fc35deb 44 temp = servoVer.read() + ((float)centerBox.getCenterY() - (float)ypos)/TO_SERVO_DIVISOR;
dhamilton31 1:6c399fc35deb 45 if(temp > 0 && temp <= 1) {
dhamilton31 1:6c399fc35deb 46 servoVer = temp;
dhamilton31 1:6c399fc35deb 47 }
dhamilton31 1:6c399fc35deb 48 }
dhamilton31 1:6c399fc35deb 49 }
dhamilton31 1:6c399fc35deb 50
dhamilton31 1:6c399fc35deb 51