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,
00024 maxomega: 1.5,
00025 maxangacc: 1,
00026 maxacc: 0.3,
00027 maxcenacc: 1,
00028 maxe: (double)ROBOT_WIDTH_MM/2.0/1000.0
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;
00126 mul *= 28.0/(2.0*M_PI)*(1<<8);
00127
00128
00129 l = (int)(left * mul);
00130 r = (int)(right * mul);
00131 robot.orte_speed.left = l;
00132 robot.orte_speed.right = r;
00133
00134
00135
00136
00137 ORTEPublicationSend(robot.publisherMotor);
00138 }
00139
00147 void robot_goto(double x, double y )
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