wheelCtrl.cpp

00001 /*
00002   並進速度と回転速度の指定による走行指示
00003   Satofumi KAMIMURA
00004   $Id$
00005 */
00006 
00007 #if !MONITOR
00008 #include <runCtrl.h>
00009 #else
00010 #include <mRunCtrl.h>
00011 #endif
00012 #include <vutils.h>
00013 #include <stdio.h>
00014 #include <stdlib.h>
00015 
00016 using namespace VXV;
00017 
00018 
00019 static void stop(RunInterface& run, unsigned long msec) {
00020   VXV::Delay(msec);
00021   run.stop();
00022   while ((abs(run.getStraightVel()) > 10) ||
00023          (abs(run.getRotateVel().to_deg()) > 10)) {
00024     VXV::Delay(100);
00025   }
00026 }
00027 
00028 
00029 static void setVelocityCtrl(RunCtrl& run,
00030                             int straight, const Direction& rotate) {
00031   enum { RIGHT = 0, LEFT = 1 };
00032 
00033   // 並進、回転から車輪毎の目標回転速度を計算するには、トレッドが必要
00034   int whl_mm_vel[2];
00035   int rotate_mm_vel = static_cast<int>(BODY_TREAD_MM * rotate.to_rad());
00036   whl_mm_vel[RIGHT] = straight + rotate_mm_vel;
00037   whl_mm_vel[LEFT] = straight - rotate_mm_vel;
00038 
00039   for (int i = 0; i < 2; ++i) {
00040     run.setWheelVel(i, whl_mm_vel[i]);
00041   }
00042 }
00043 
00044 
00045 int main(int argc, char *argv[]) {
00046   try {
00047 #if !MONITOR
00048     RunCtrl run;
00049 #else
00050     mRunCtrl run;
00051     vmonitor::show();
00052 #endif
00053     if (run.connect(argc, argv) < 0) {
00054       printf("RunCtrl::connect: %s\n", run.what());
00055       exit(1);
00056     }
00057 
00058     setVelocityCtrl(run, 300, deg(0)); // 並進制御
00059     stop(run, 3000);
00060 
00061     setVelocityCtrl(run, 0, deg(45)); // 回転制御
00062     stop(run, 3000);
00063 
00064     setVelocityCtrl(run, 300, deg(45)); // 並進と回転の制御
00065     stop(run, 3000);
00066 
00067   } catch (std::exception& e) {
00068     printf("exception: %s\n", e.what());
00069   }
00070   return 0;
00071 }
00072 
00073 

Generated on Mon Apr 13 22:52:04 2009 by  doxygen 1.5.7.1