Attachment | Size |
---|---|
iRobot Create.pdf | 3 MB |
Hl-340.exe | 219.32 KB |
AutoRDC2012_V2.rar | 423.15 KB |
State_Machine.pptx | 63.06 KB |
AutoRDC2012_V3.rar | 422.18 KB |
RDC2013_v1_main.cpp | 3.42 KB |
Programming iRobot Create
-
EXAMPLE --> RDC2013_v1_main.cpp
-
download MS Visual Studio 2008 Express ให้เลือก Visual C++ 2008 Express Edition with SP1 และเลือกภาษา English แล้วกด Download (ต้องใช้ version 2008 เท่านั้น)
-
download iRobot Create package v1
-
download State Machine Demo v2
-
download Timing Demo v3
-
Slide สำหรับ state machine (http://www.nattee.net/files-dae/State_Machine.pptx)
-
Slide สำหรับเนื้อหาในวันที่ 25 download ที่นี่<
-
Driver ของ USB to Serial อันที่แจกให้
[code lang="c++"]
#include <stdio.h>
#include
#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;
} [/code]