movehelper.cc

Go to the documentation of this file.
00001 
00011 #include "trgen.h"
00012 #include "robot.h"
00013 #include "movehelper.h"
00014 #include "fsmmove.h"
00015 #include <path_simplifier.h>
00016 #include <stdio.h>
00017 #include <stdlib.h>
00018 #include <sys/stat.h>
00019 #include <math.h>
00020 #include <map.h>
00021 
00022 struct TrajectoryConstraints trajectoryConstraintsDefault = {
00023         maxv: 0.3,              // m/s
00024         maxomega: 1.5,          // rad/s
00025         maxangacc: 1,           // rad/s^2
00026         maxacc: 0.3,            // m/s^2
00027         maxcenacc: 1,           // m/s^2
00028         maxe: (double)ROBOT_WIDTH_MM/2.0/1000.0 // m
00029 };
00030 
00031 
00037 static void robot_trajectory_new_ex(struct TrajectoryConstraints *tc, bool backward)
00038 {
00039         Trajectory *ot, *nt;
00040         
00041         if (!tc) tc = &trajectoryConstraintsDefault;
00042 
00043         nt = new Trajectory(*tc, backward);
00044         ROBOT_LOCK(new_trajectory);
00045         ot = (Trajectory*)robot.new_trajectory;
00046         robot.new_trajectory = nt;
00047 
00048         ROBOT_UNLOCK(new_trajectory);
00049         if (ot) delete(ot);
00050 }
00051 
00052 
00059 void robot_trajectory_new(struct TrajectoryConstraints *tc) {
00060         robot_trajectory_new_ex(tc, false);
00061 }
00062 void robot_trajectory_new_backward(struct TrajectoryConstraints *tc) {
00063         robot_trajectory_new_ex(tc, true);
00064 }
00065 
00072 void robot_trajectory_add_point(double x_m, double y_m)
00073 {
00074         Trajectory *w;
00075         
00076         ROBOT_LOCK(new_trajectory);
00077         w = (Trajectory*)robot.new_trajectory;
00078         if (w) {
00079                 w->addPoint(x_m, y_m);
00080         }
00081         ROBOT_UNLOCK(new_trajectory);
00082 }
00083 
00084 double target_x, target_y;
00085 
00093 void robot_trajectory_add_final_point(double x_m, double y_m, double heading_deg)
00094 {
00095         target_x = x_m;
00096         target_y = y_m;
00097         robot_trajectory_add_point(target_x, target_y);
00098         
00099         Trajectory *w;
00100         ROBOT_LOCK(new_trajectory);
00101         w = (Trajectory*)robot.new_trajectory;
00102         if (w) {
00103                 w->finalHeading = heading_deg/180.0*M_PI;
00104         }
00105         ROBOT_UNLOCK(new_trajectory);
00106 
00107         FSM_SIGNAL(MOTION, EV_NEW_TRAJECTORY);
00108 }
00109 
00110 
00115 void robot_trajectory_stop()
00116 {
00117         delete_actual_trajectory();
00118 }
00119 
00120 
00121 void robot_send_speed(double left, double right) {
00122         double mul;
00123         unsigned l, r;
00124 
00125         mul = 1000.0 / ROBOT_WHEEL_RADIUS_MM; // to angular speed
00126         mul *= 28.0/(2.0*M_PI)/*gear*/*(1<<8);  // to pxmc speed
00127 
00128         // I hope it is not neccessary to lock here
00129         l = (int)(left * mul);
00130         r = (int)(right * mul);
00131         robot.orte_speed.left = l;//(l&0xff) << 8 | (l&0xff00) >> 8;
00132         robot.orte_speed.right = r;//(r&0xff) << 8 | (r&0xff00) >> 8;
00133 //      DBG("speed l=%8.3g (%6d) r=%8.3g (%6d)", 
00134 //          left, l, // robot.orte_speed.left, 
00135 //          right, r //robot.orte_speed.right
00136 //          );
00137         ORTEPublicationSend(robot.publisherMotor);
00138 }
00139 
00147 void robot_goto(double x, double y /*, double phi*/)
00148 {
00149         ROBOT_LOCK(goal);
00150         robot.goal.x = x;
00151         robot.goal.y = y;
00152         ROBOT_UNLOCK(goal);
00153         FSM_SIGNAL(MOTION, EV_NEW_GOAL);
00154 }
00155 
00156 
00157 
00158 
00159 
00160 
00161 

Generated on Thu Sep 13 11:28:28 2007 for DCE-Eurobot by  doxygen 1.5.3