本文整理汇总了C++中ARDrone::move3D方法的典型用法代码示例。如果您正苦于以下问题:C++ ARDrone::move3D方法的具体用法?C++ ARDrone::move3D怎么用?C++ ARDrone::move3D使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ARDrone
的用法示例。
在下文中一共展示了ARDrone::move3D方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: goMousePoint
//.........这里部分代码省略.........
if(((x - preX) > 5)&&((x - preX) < threshValue)){
vy = -1;
}
if(((x - preX) < -5)&&((x - preX) > (-1 * threshValue))){
vy = 1;
}
if(((y - preY) < 10)&&((y - preY) > -10)){
if((y>0)&&(y < 150)){
vz = 1;
}
if((y>450)&&(y < 600)){
vz = -1;
}
}
if(((y - preY) > 5)&&((y - preY) < threshValue/2)){
//画面下へドラッグ
//vz = -1;
}
if(((y - preY) < -5)&&((y - preY) > (-1 * threshValue/2))){
//vz = 1;
}
*/
}else{
//マルチタッチモード
//前後飛行
if(((x - preX) > 5)&&((x - preX) < threshValue)){
vz = 1.0;
}
if(((x - preX) < -5)&&((x - preX) > (-1 * threshValue))){
vz = -1.0;
}
}
}
}
//下面カメラ
if((ardrone.getCameraMode() == 1)||(ardrone.getCameraMode() == 3))
{
//printf("cmode:%02d \n",ardrone.getCameraMode());
if((x>0)&&(x<800)&&(y>0)&&(y<600))
{
if((!MouseCtrlMode))
{
if((x>0)&&(x < 300)){
vy = 1.5;
}
if((x>500)&&(x < 800)){
vy = -1.5;
}
if((y>0)&&(y < 200)){
vx = 1.5;
}
if((y>400)&&(y < 600)){
vx = -1.5;
}
/*
if(((x - preX) > 5)&&((x - preX) < threshValue)){
vy = -1;
}
if(((x - preX) < -5)&&((x - preX) > (-1 * threshValue))){
vy = 1;
}
if(((y - preY) > 5)&&((y - preY) < threshValue/2)){
vx = 1;
}
if(((y - preY) < -5)&&((y - preY) > (-1 * threshValue/2))){
vx = -1;
}
*/
}else{
//マルチタッチモード
//昇降下降
if(((x - preX) > 5)&&((x - preX) < threshValue)){
vz = 1.0;
}
if(((x - preX) < -5)&&((x - preX) > (-1 * threshValue))){
vz = -1.0;
}
}
}
}
printf("cmode:%02d pX:%02d-%02d pY:%02d-%02d vx:%02.1f vy:%02.1f vz:%02.1f vr:%02.1f \n",ardrone.getCameraMode(), preX, x, preY, y, vx, vy, vz, vr);
//ardrone.move3D(vx, vy, vz, vr);
if(mArDroneCommandFlag == false)
{
MouseARMode = true;
ardrone.move3D(vx, vy, vz, vr);
msleep(200);
MouseARMode = false;
}
preX = x;
preY = y;
}
//ardrone.move3D(0, 0, 0, 0);
}
}
示例2: main
// --------------------------------------------------------------------------
// main(Number of arguments, Argument values)
// Description : This is the entry point of the program.
// Return value : SUCCESS:0 ERROR:-1
// --------------------------------------------------------------------------
int main(int argc, char *argv[])
{
// AR.Drone class
ARDrone ardrone;
// Initialize
if (!ardrone.open()) {
std::cout << "Failed to initialize." << std::endl;
return -1;
}
// Battery
std::cout << "Battery = " << ardrone.getBatteryPercentage() << "[%]" << std::endl;
// Instructions
std::cout << "***************************************" << std::endl;
std::cout << "* CV Drone sample program *" << std::endl;
std::cout << "* - How to play - *" << std::endl;
std::cout << "***************************************" << std::endl;
std::cout << "* *" << std::endl;
std::cout << "* - Controls - *" << std::endl;
std::cout << "* 'Space' -- Takeoff/Landing *" << std::endl;
std::cout << "* 'Up' -- Move forward *" << std::endl;
std::cout << "* 'Down' -- Move backward *" << std::endl;
std::cout << "* 'Left' -- Turn left *" << std::endl;
std::cout << "* 'Right' -- Turn right *" << std::endl;
std::cout << "* 'Q' -- Move upward *" << std::endl;
std::cout << "* 'A' -- Move downward *" << std::endl;
std::cout << "* *" << std::endl;
std::cout << "* - Others - *" << std::endl;
std::cout << "* 'T' -- Track marker *" << std::endl;
std::cout << "* 'C' -- Change camera *" << std::endl;
std::cout << "* 'Esc' -- Exit *" << std::endl;
std::cout << "* *" << std::endl;
std::cout << "***************************************" << std::endl;
while (1) {
double cx = 0;
double cy = 0;
cv::Rect trackRect;
// Key input
int key = cv::waitKey(33);
if (key == 0x1b) break;
// Get an image
cv::Mat image = ardrone.getImage();
// Take off / Landing
if (key == ' ') {
if (ardrone.onGround()) ardrone.takeoff();
else ardrone.landing();
}
// Move
double vx = 0.0, vy = 0.0, vz = 0.0, vr = 0.0;
if (key == 'i' || key == CV_VK_UP) vx = 1.0;
if (key == 'k' || key == CV_VK_DOWN) vx = -1.0;
if (key == 'u' || key == CV_VK_LEFT) vr = 1.0;
if (key == 'o' || key == CV_VK_RIGHT) vr = -1.0;
if (key == 'j') vy = 1.0;
if (key == 'l') vy = -1.0;
if (key == 'q') vz = 1.0;
if (key == 'a') vz = -1.0;
ardrone.move3D(vx, vy, vz, vr);
// Change camera
static int mode = 0;
if (key == 'c') ardrone.setCamera(++mode % 4);
// Switch tracking ON/OFF
static int track = 0;
if (key == 't') track = !track;
// People detect
trackRect = ardrone.detectHuman(image);
cx = trackRect.x + (trackRect.width / 2);
cy = trackRect.y + (trackRect.height / 2);
cv::Point2f mc = cv::Point2f(cx, cy);
//std::cout << "cx: " << cx << " cy: " << cy <<std::endl;
cv::circle(image, mc, 5, cv::Scalar(0,0,255));
//std::cout << "rect size: " << trackRect.width * trackRect.height << std::endl;
// Tracking
if (track) {
if (cx == 0 && cy == 0)
{
vx = 0.0;
vy = 0.0;
vr = 0.0;
vz = 0.0;
} else {
const double kp = 0.005;
const double ka = 0.005;
//.........这里部分代码省略.........
示例3: main
//.........这里部分代码省略.........
int key = cvWaitKey(33);
//int key = cvWaitKey(15);
if (key == 0x1b){
break;
}
//2014.03.09 add
vx = 0.0;
vy = 0.0;
vz = 0.0;
vr = 0.0;
//音声出力タイミング用ワーク
if (mSendCommandflag == true)
{
if(mSendCommandcounter++ > 50)
{
mSendCommandflag = false;
mSendCommandcounter = 0;
}
}
// Update
if(mNonDronDebug == false)
{
if (!ardrone.update())
break;
// Get an image
image = ardrone.getImage();
if((mbatValue = ardrone.getBatteryPercentage()) < 30){
printf("Battery = %d%%\n",mbatValue );
if(mArDroneCommandFlag == false)
ardrone.move3D(0.0, 0.0, 0.0, 0.0);
msleep(80);
ardrone.landing();
printf("Landing\n");
msleep(180);
}
//}
#ifndef FACEDETECT
try{
//2014.02.15 FaceDetection追加
// (3)メモリを確保し,読み込んだ画像のグレースケール化,ヒストグラムの均一化を行う
CvMemStorage *storage = 0;
storage = cvCreateMemStorage (0);
cvClearMemStorage (storage);
//Mat captureFrame;
//Mat grayscaleFrame;
Mat captureFrameMat = cvarrToMat(image);
cvtColor(captureFrameMat, grayscaleFrame, CV_BGR2GRAY);
equalizeHist(grayscaleFrame, grayscaleFrame);
// mFaceDetectMode:Fキーにてスイッチ
if((mFaceDetectMode == true)
&&((ardrone.getCameraMode() == 0)||(ardrone.getCameraMode() == 2)))//正面カメラの場合に有効
{
// (4)物体(顔)検出
//create a vector array to store the face found
std::vector<Rect> faces;
face_cascade.detectMultiScale(grayscaleFrame, faces, 1.2, 4, CV_HAAR_FIND_BIGGEST_OBJECT|CV_HAAR_SCALE_IMAGE, Size(30,30));
//printf("FaceNum:%02d\n",faces.size());
// (5)検出された全ての顔位置に,四角を描画する
示例4: main
// --------------------------------------------------------------------------
// main(Number of arguments, Argument values)
// Description : This is the entry point of the program.
// Return value : SUCCESS:0 ERROR:-1
// --------------------------------------------------------------------------
int main(int argc, char *argv[])
{
// AR.Drone class
ARDrone ardrone;
// Initialize
if (!ardrone.open()) {
std::cout << "Failed to initialize." << std::endl;
return -1;
}
// Battery
std::cout << "Battery = " << ardrone.getBatteryPercentage() << "[%]" << std::endl;
// Instructions
std::cout << "***************************************" << std::endl;
std::cout << "* CV Drone sample program *" << std::endl;
std::cout << "* - How to play - *" << std::endl;
std::cout << "***************************************" << std::endl;
std::cout << "* *" << std::endl;
std::cout << "* - Controls - *" << std::endl;
std::cout << "* 'Space' -- Takeoff/Landing *" << std::endl;
std::cout << "* 'Up' -- Move forward *" << std::endl;
std::cout << "* 'Down' -- Move backward *" << std::endl;
std::cout << "* 'Left' -- Turn left *" << std::endl;
std::cout << "* 'Right' -- Turn right *" << std::endl;
std::cout << "* 'Q' -- Move upward *" << std::endl;
std::cout << "* 'A' -- Move downward *" << std::endl;
std::cout << "* *" << std::endl;
std::cout << "* - Others - *" << std::endl;
std::cout << "* 'C' -- Change camera *" << std::endl;
std::cout << "* 'Esc' -- Exit *" << std::endl;
std::cout << "* *" << std::endl;
std::cout << "***************************************" << std::endl;
while (1) {
// Key input
int key = cv::waitKey(33);
if (key != -1) std::cout << "Key pressed: " << key << std::endl;
if (key == 0x1b) break;
// Get an image
cv::Mat image = ardrone.getImage();
// Take off / Landing
if (key == ' ') {
if (ardrone.onGround()) ardrone.takeoff();
else ardrone.landing();
}
// Move
double vx = 0.0, vy = 0.0, vz = 0.0, vr = 0.0;
if (key == 'i' || key == CV_VK_UP) vx = 1.0;
//if (key == 2490368) vx = 1.0; // Key up
if (key == 'k' || key == CV_VK_DOWN) vx = -1.0;
//if (key == 2621440) vx = -1.0; // Key down
if (key == 'u' || key == CV_VK_LEFT) vr = 1.0;
//if (key == 2424832) vr = 1.0; // Key left
if (key == 'o' || key == CV_VK_RIGHT) vr = -1.0;
//if (key == 2555904) vr = -1.0; // Key right
if (key == 'j') vy = 1.0;
if (key == 'l') vy = -1.0;
if (key == 'q') vz = 1.0;
if (key == 'a') vz = -1.0;
//ardrone.move3D(1.0, 0.0, 0.0, 0.0);
//std::cout << "vx: " << vx << ", vy: " << vy << ", vz: " << vz << ", vr: " << vr << std::endl;
ardrone.move3D(vx, vy, vz, vr);
// Change camera
static int mode = 0;
if (key == 'c') ardrone.setCamera(++mode % 4);
// Display the image
cv::imshow("Camera", image);
}
// See you
ardrone.close();
return 0;
}
示例5: controls
// --------------------------------------------------------------------------
// controls()
// This function sends commands to the drone using an Xbox Controller.
// --------------------------------------------------------------------------
void controls()
{
// Check for Xbox Controller
if(player1->IsConnected())
{
// 'A' button
if(player1->GetState().Gamepad.wButtons & XINPUT_GAMEPAD_A)
{
// Change camera
static int cameraToggle = 0;
ardrone.setCamera(++cameraToggle%4);
}
// 'B' button
if(player1->GetState().Gamepad.wButtons & XINPUT_GAMEPAD_B)
{
ardrone.emergency();
}
// 'X' button
if(player1->GetState().Gamepad.wButtons & XINPUT_GAMEPAD_X)
{
ardrone.flatTrim();
}
// 'Y' button
/*if(player1->GetState().Gamepad.wButtons & XINPUT_GAMEPAD_Y)
{
}*/
// 'Start' button
if(player1->GetState().Gamepad.wButtons & XINPUT_GAMEPAD_START)
{
if (ardrone.onGround())
{
ardrone.takeoff();
}
else
{
ardrone.landing();
}
}
// 'Back' button
if(player1->GetState().Gamepad.wButtons & XINPUT_GAMEPAD_BACK)
{
// Exit the program.
if (ardrone.onGround())
{
exit(0);
}
}
// Left Thumb-Stick Press
/*if(player1->GetState().Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_THUMB)
{
}*/
// Right Thumb-Stick Press
/*if(player1->GetState().Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB)
{
}*/
// AR.Drone flight controls
//if (!ardrone.onGround())
{
// Check left thumbStick
double leftThumbY = player1->GetState().Gamepad.sThumbLY / STICK_RANGE;
double leftThumbX = player1->GetState().Gamepad.sThumbLX / STICK_RANGE;
// Check the dead zone
if (leftThumbY < STICK_DEAD_ZONE && leftThumbY > -STICK_DEAD_ZONE)
{
leftThumbY = 0;
}
if (leftThumbX < STICK_DEAD_ZONE && leftThumbX > -STICK_DEAD_ZONE)
{
leftThumbX = 0;
}
// Check left thumbStick
double rightThumbY = player1->GetState().Gamepad.sThumbRY / TRIGGER_RANGE;
double rightThumbX = player1->GetState().Gamepad.sThumbRX / TRIGGER_RANGE;
// Check the dead zone
if (rightThumbY < STICK_DEAD_ZONE && rightThumbY > -STICK_DEAD_ZONE)
{
rightThumbY = 0;
}
if (rightThumbX < STICK_DEAD_ZONE && rightThumbX> -STICK_DEAD_ZONE)
{
rightThumbX = 0;
}
double rightTrigger = player1->GetState().Gamepad.bRightTrigger / TRIGGER_RANGE;
double leftTrigger = player1->GetState().Gamepad.bLeftTrigger / TRIGGER_RANGE;
double gaz = rightTrigger - leftTrigger;
// Move
ardrone.move3D(rightThumbY*10, -rightThumbX*10, gaz*10, -leftThumbX*10);
}
//.........这里部分代码省略.........
示例6: main
//.........这里部分代码省略.........
// Move
double vx = 0.0, vy = 0.0, vz = 0.0, vr = 0.0;
if (key == 'i' || key == CV_VK_UP) vx = 1.0;
if (key == 'k' || key == CV_VK_DOWN) vx = -1.0;
if (key == 'u' || key == CV_VK_LEFT) vr = 1.0;
if (key == 'o' || key == CV_VK_RIGHT) vr = -1.0;
if (key == 'j') vy = 1.0;
if (key == 'l') vy = -1.0;
if (key == 'q') vz = 1.0;
if (key == 'a') vz = -1.0;
// Change camera
static int mode = 0;
if (key == 'c') ardrone.setCamera(++mode % 4);
// Switch tracking ON/OFF
static int track = 0;
if (key == 't') track = !track;
// Get an image
cv::Mat image = ardrone.getImage();
// HSV image
cv::Mat hsv;
cv::cvtColor(image, hsv, cv::COLOR_BGR2HSV_FULL);
// Binalize
cv::Mat binalized;
cv::Scalar lower(minH, minS, minV);
cv::Scalar upper(maxH, maxS, maxV);
cv::inRange(hsv, lower, upper, binalized);
// Show result
cv::imshow("binalized", binalized);
// De-noising
cv::Mat kernel = getStructuringElement(cv::MORPH_RECT, cv::Size(3, 3));
cv::morphologyEx(binalized, binalized, cv::MORPH_CLOSE, kernel);
//cv::imshow("morphologyEx", binalized);
// Detect contours
std::vector< std::vector<cv::Point> > contours;
cv::findContours(binalized.clone(), contours, cv::RETR_CCOMP, cv::CHAIN_APPROX_SIMPLE);
// Find largest contour
int contour_index = -1;
double max_area = 0.0;
for (size_t i = 0; i < contours.size(); i++) {
double area = fabs(cv::contourArea(contours[i]));
if (area > max_area) {
contour_index = i;
max_area = area;
}
}
// Object detected
if (contour_index >= 0) {
// Moments
cv::Moments moments = cv::moments(contours[contour_index], true);
double marker_y = (int)(moments.m01 / moments.m00);
double marker_x = (int)(moments.m10 / moments.m00);
// Show result
cv::Rect rect = cv::boundingRect(contours[contour_index]);
cv::rectangle(image, rect, cv::Scalar(0, 255, 0));
// Tracking
if (track) {
const double kp = 0.005;
vx = 0.1;
vy = 0.0;
vz = kp * (binalized.rows / 2 - marker_y);
vr = kp * (binalized.cols / 2 - marker_x);
}
}
// Display the image
cv::putText(image, (track) ? "track on" : "track off", cv::Point(10, 20), cv::FONT_HERSHEY_SIMPLEX, 0.5, (track) ? cv::Scalar(0, 0, 255) : cv::Scalar(0, 255, 0), 1, cv::LINE_AA);
cv::imshow("camera", image);
ardrone.move3D(vx, vy, vz, vr);
}
// Save thresholds
fs.open(filename, cv::FileStorage::WRITE);
if (fs.isOpened()) {
cv::write(fs, "H_MAX", maxH);
cv::write(fs, "H_MIN", minH);
cv::write(fs, "S_MAX", maxS);
cv::write(fs, "S_MIN", minS);
cv::write(fs, "V_MAX", maxV);
cv::write(fs, "V_MIN", minV);
fs.release();
}
// See you
ardrone.close();
return 0;
}
示例7: main
//.........这里部分代码省略.........
0.0, 0.0, 0.1, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.3, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.3, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 0.3;
kalman.processNoiseCov = Q;
// Measurement noise covariance (z, vx, vy, vz)
cv::Mat1f R(4, 4);
R << 0.1, 0.0, 0.00, 0.00,
0.0, 0.1, 0.00, 0.00,
0.0, 0.0, 0.05, 0.00,
0.0, 0.0, 0.00, 0.05;
kalman.measurementNoiseCov = R;
// Main loop
while (1) {
// Key input
int key = cv::waitKey(33);
if (key == 0x1b) break;
// Update
if (!ardrone.update()) break;
// Get an image
cv::Mat image = ardrone.getImage();
// Prediction
cv::Mat prediction = kalman.predict();
// Altitude
double altitude = ardrone.getAltitude();
// Orientations
double roll = ardrone.getRoll();
double pitch = ardrone.getPitch();
double yaw = ardrone.getYaw();
// Velocities
double vx, vy, vz;
double velocity = ardrone.getVelocity(&vx, &vy, &vz);
cv::Mat V = (cv::Mat1f(3,1) << vx, vy, vz);
// Rotation matrices
cv::Mat RZ = (cv::Mat1f(3,3) << cos(yaw), -sin(yaw), 0.0,
sin(yaw), cos(yaw), 0.0,
0.0, 0.0, 1.0);
cv::Mat RY = (cv::Mat1f(3,3) << cos(pitch), 0.0, sin(pitch),
0.0, 1.0, 0.0,
-sin(pitch), 0.0, cos(pitch));
cv::Mat RX = (cv::Mat1f(3,3) << 1.0, 0.0, 0.0,
0.0, cos(roll), -sin(roll),
0.0, sin(roll), cos(roll));
// Time [s]
static int64 last = cv::getTickCount();
double dt = (cv::getTickCount() - last) / cv::getTickFrequency();
last = cv::getTickCount();
// Local movements (z, vx, vy, vz)
cv::Mat1f M = RZ * RY * RX * V * dt;
cv::Mat measurement = (cv::Mat1f(4,1) << altitude, M(0,0), M(1,0), M(2,0));
// Correction
cv::Mat1f estimated = kalman.correct(measurement);
// Position (x, y, z)
double pos[3] = {estimated(0,0), estimated(1,0), estimated(2,0)};
printf("x = %3.2fm, y = %3.2fm, z = %3.2fm\n", pos[0], pos[1], pos[2]);
// Take off / Landing
if (key == ' ') {
if (ardrone.onGround()) ardrone.takeoff();
else ardrone.landing();
}
// Move
double x = 0.0, y = 0.0, z = 0.0, r = 0.0;
if (key == 0x260000) x = 1.0;
if (key == 0x280000) x = -1.0;
if (key == 0x250000) r = 1.0;
if (key == 0x270000) r = -1.0;
if (key == 'q') z = 1.0;
if (key == 'a') z = -1.0;
ardrone.move3D(x, y, z, r);
// Change camera
static int mode = 0;
if (key == 'c') ardrone.setCamera(++mode%4);
// Display the image
cv::circle(map, cv::Point(-pos[1]*100.0 + map.cols/2, -pos[0]*100.0 + map.rows/2), 2, CV_RGB(255,0,0));
cv::imshow("map", map);
cv::imshow("camera", image);
}
// See you
ardrone.close();
return 0;
}
示例8: main
// --------------------------------------------------------------------------
// main(Number of arguments, Argument values)
// Description : This is the entry point of the program.
// Return value : SUCCESS:0 ERROR:-1
// --------------------------------------------------------------------------
int main(int argc, char *argv[])
{
// AR.Drone class
ARDrone ardrone;
// Initialize
if (!ardrone.open()) {
std::cout << "Failed to initialize." << std::endl;
return -1;
}
// Battery
std::cout << "Battery = " << ardrone.getBatteryPercentage() << " [%]" << std::endl;
// Map
cv::Mat map = cv::Mat::zeros(500, 500, CV_8UC3);
// Position matrix
cv::Mat P = cv::Mat::zeros(3, 1, CV_64FC1);
// Main loop
while (1) {
// Key input
int key = cv::waitKey(33);
if (key == 0x1b) break;
// Get an image
cv::Mat image = ardrone.getImage();
// Altitude
double altitude = ardrone.getAltitude();
// Orientations
double roll = ardrone.getRoll();
double pitch = ardrone.getPitch();
double yaw = ardrone.getYaw();
// Velocities
double vx, vy, vz;
double velocity = ardrone.getVelocity(&vx, &vy, &vz);
cv::Mat V = (cv::Mat1f(3, 1) << vx, vy, vz);
// Rotation matrices
cv::Mat RZ = (cv::Mat1f(3, 3) << cos(yaw), -sin(yaw), 0.0,
sin(yaw), cos(yaw), 0.0,
0.0, 0.0, 1.0);
cv::Mat RY = (cv::Mat1f(3, 3) << cos(pitch), 0.0, sin(pitch),
0.0, 1.0, 0.0,
-sin(pitch), 0.0, cos(pitch));
cv::Mat RX = (cv::Mat1f(3, 3) << 1.0, 0.0, 0.0,
0.0, cos(roll), -sin(roll),
0.0, sin(roll), cos(roll));
// Time [s]
static int64 last = cv::getTickCount();
double dt = (cv::getTickCount() - last) / cv::getTickFrequency();
last = cv::getTickCount();
// Dead-reckoning
P = P + RZ * RY * RX * V * dt;
// Position (x, y, z)
double pos[3] = { P.at<double>(0, 0), P.at<double>(1, 0), P.at<double>(2, 0) };
std::cout << "x = " << pos[0] << "[m], " << "y = " << pos[1] << "[m], " << "z = " << pos[2] << "[m]" << std::endl;
// Take off / Landing
if (key == ' ') {
if (ardrone.onGround()) ardrone.takeoff();
else ardrone.landing();
}
// Move
double x = 0.0, y = 0.0, z = 0.0, r = 0.0;
if (key == 'i' || key == CV_VK_UP) vx = 1.0;
if (key == 'k' || key == CV_VK_DOWN) vx = -1.0;
if (key == 'u' || key == CV_VK_LEFT) vr = 1.0;
if (key == 'o' || key == CV_VK_RIGHT) vr = -1.0;
if (key == 'j') vy = 1.0;
if (key == 'l') vy = -1.0;
if (key == 'q') vz = 1.0;
if (key == 'a') vz = -1.0;
ardrone.move3D(x, y, z, r);
// Change camera
static int mode = 0;
if (key == 'c') ardrone.setCamera(++mode % 4);
// Display the image
cv::circle(map, cv::Point(-pos[1] * 100.0 + map.cols / 2, -pos[0] * 100.0 + map.rows / 2), 2, CV_RGB(255, 0, 0));
cv::imshow("map", map);
cv::imshow("camera", image);
}
// See you
ardrone.close();
//.........这里部分代码省略.........
示例9: main
// --------------------------------------------------------------------------
// main(Number of arguments, Argument values)
// Description : This is the entry point of the program.
// Return value : SUCCESS:0 ERROR:-1
// --------------------------------------------------------------------------
int main(int argc, char **argv)
{
// AR.Drone class
ARDrone ardrone;
// Initialize
if (!ardrone.open()) {
printf("Failed to initialize.\n");
return -1;
}
// Battery
printf("Battery = %d%%\n", ardrone.getBatteryPercentage());
// Instructions
printf("***************************************\n");
printf("* CV Drone sample program *\n");
printf("* - How to Play - *\n");
printf("***************************************\n");
printf("* *\n");
printf("* - Controls - *\n");
printf("* 'Space' -- Takeoff/Landing *\n");
printf("* 'Up' -- Move forward *\n");
printf("* 'Down' -- Move backward *\n");
printf("* 'Left' -- Turn left *\n");
printf("* 'Right' -- Turn right *\n");
printf("* 'Q' -- Move upward *\n");
printf("* 'A' -- Move downward *\n");
printf("* *\n");
printf("* - Others - *\n");
printf("* 'C' -- Change camera *\n");
printf("* 'Esc' -- Exit *\n");
printf("* *\n");
printf("***************************************\n\n");
while (1) {
// Key input
int key = cvWaitKey(33);
if (key == 0x1b) break;
// Update
if (!ardrone.update()) break;
// Get an image
IplImage *image = ardrone.getImage();
// Take off / Landing
if (key == ' ') {
if (ardrone.onGround()) ardrone.takeoff();
else ardrone.landing();
}
// Move
double vx = 0.0, vy = 0.0, vz = 0.0, vr = 0.0;
if (key == 0x260000) vx = 1.0;
if (key == 0x280000) vx = -1.0;
if (key == 0x250000) vr = 1.0;
if (key == 0x270000) vr = -1.0;
if (key == 'q') vz = 1.0;
if (key == 'a') vz = -1.0;
ardrone.move3D(vx, vy, vz, vr);
// Change camera
static int mode = 0;
if (key == 'c') ardrone.setCamera(++mode%4);
// Display the image
cvShowImage("camera", image);
}
// See you
ardrone.close();
return 0;
}