RDC 2013

Programming iRobot Create

#include <stdio.h>
#include <iostream>
 
#include "RobotConnector.h"
 
#include "cv.h"
#include "highgui.h"
 
using namespace std;
 
#define Create_Comport "COM4"
 
bool isRecord = false;
 
int main()
{
    CreateData  robotData;
    RobotConnector  robot;
 
    ofstream    record;
    record.open("../data/robot.txt");
 
    if( !robot.Connect(Create_Comport) )
    {
        cout << "Error : Can't connect to robot @" << Create_Comport << endl;
        return -1;
    }
 
    robot.DriveDirect(0, 0);
    cvNamedWindow("Robot");
 
 
    while(true)
    {
        cvWaitKey(30);
        double vx, vz;
        vx = vz = 0;
 
 
        if (robotData.bumper[0]) {
            cout << "bump left" << endl;
        }
        if (robotData.bumper[1]) {
            cout << "bump right" << endl;
        }
 
 
        double vl = vx - vz;
        double vr = vx + vz;
 
        int velL = (int)(vl*Create_MaxVel);
        int velR = (int)(vr*Create_MaxVel);
 
        int color = (abs(velL)+abs(velR))/4;
        color = (color < 0) ? 0 : (color > 255) ? 255 : color;
 
        int inten = (robotData.cliffSignal[1] + robotData.cliffSignal[2])/8 - 63;
        inten = (inten < 0) ? 0 : (inten > 255) ? 255 : inten;
 
        //cout << color << " " << inten << " " << robotData.cliffSignal[1] << " " << robotData.cliffSignal[2] << endl;
 
        robot.LEDs(velL > 0, velR > 0, color, inten);
 
        if( !robot.DriveDirect(velL, velR) )
            cout << "SetControl Fail" << endl;
 
        if( !robot.ReadData(robotData) ) {
            //cout << "ReadData Fail" << endl;
        }
 
        if( isRecord )
            record << robotData.cliffSignal[0] << "\t" << robotData.cliffSignal[1] << "\t" << robotData.cliffSignal[2] << "\t" << robotData.cliffSignal[3] << endl;
 
        cout << "Robot " << robotData.cliffSignal[0] << endl;
    }
 
    robot.Disconnect();
 
    return 0;
}
File attachments: 
AttachmentSize
PDF icon iRobot Create.pdf3 MB
File Hl-340.exe219.32 KB
File AutoRDC2012_V2.rar423.15 KB
File State_Machine.pptx63.06 KB
File AutoRDC2012_V3.rar422.18 KB
File RDC2013_v1_main.cpp3.42 KB

Syndicate

Subscribe to Syndicate
© 2014 Nattee Niparnan. Drupal theme by Kiwi Themes.