default:
break;
}
-}
-
-/* Homologation states */
-FSM_STATE(homolog_approach_buillon)
-{
- switch(FSM_EVENT) {
- case EV_ENTRY:
- robot_trajectory_new(&tcSlow); // new trajectory
- robot_trajectory_add_point_trans(
- 0.65,
- PLAYGROUND_HEIGHT_M - (ROBOT_WIDTH_M/2.0));
- robot_trajectory_add_point_trans(
- 0.65,
- 1.3);
- robot_trajectory_add_final_point_trans(
- 0.5,
- 1.1,
- NO_TURN());
- break;
- case EV_MOTION_DONE:
- case EV_TIMER:
- FSM_TRANSITION(homolog_push_bottle);
- break;
- default:
- break;
- }
-}
-
-FSM_STATE(homolog_push_bottle)
-{
- switch(FSM_EVENT) {
- case EV_ENTRY:
- robot_trajectory_new(&tcSlow); // new trajectory
- robot_trajectory_add_point_trans(
- 0.64,
- 0.7);
- robot_trajectory_add_final_point_trans(
- 0.64 + 0.08,
- ROBOT_AXIS_TO_FRONT_M + 0.05,
- ARRIVE_FROM(DEG2RAD(270), 0.10));
- break;
- case EV_MOTION_DONE:
- SUBFSM_RET(NULL);
- break;
- default:
- break;
- }
-}
-
-
-/* State for odometry calibration */
-
-FSM_STATE(go_back_for_cal)
-{
- double x1 = 0, y1 = 0;
- char buffer [20];
- switch (FSM_EVENT) {
- case EV_ENTRY:
- robot_set_est_pos_trans(ROBOT_AXIS_TO_BACK_M + 1.0,
- PLAYGROUND_HEIGHT_M - (ROBOT_WIDTH_M/2.0),
- 0);
- robot_move_by(-1.1, NO_TURN(), &tcVerySlow);
- FSM_TIMER(200);
- break;
- case EV_MOTION_DONE:
- ROBOT_LOCK(est_pos_odo);
- robot.odo_cal_a = -1.0/robot.odo_distance_a;
- robot.odo_cal_b = -1.0/robot.odo_distance_b;
- x1 = robot.odo_distance_a;
- y1 = robot.odo_distance_b;
- ROBOT_UNLOCK(est_pos_odo);
- if(x1 != 0 || y1 != 0) {
- printf("Distance for calibration: \n");
- printf("Left%f\n", x1);
- printf("Right%f\n", y1);
- FILE * file;
- file = fopen ("odometry_cal_data","a+");
- sprintf(buffer, "%4.4f", -1/x1);
- fputs (buffer,file);
- fputs (" ", file);
- sprintf(buffer, "%4.4f", -1/y1);
- fputs (buffer,file);
- fputs ("\n", file);
- fclose(file);
- }
- SUBFSM_RET(NULL);
- break;
- case EV_TIMER:
- ROBOT_LOCK(est_pos_odo);
- if(x1 == robot.odo_distance_a){
- x1 = robot.odo_distance_a;
- y1 = robot.odo_distance_b;
- FSM_SIGNAL(MOTION,EV_MOVE_STOP, NULL);
- FSM_SIGNAL(MAIN, EV_MOTION_DONE, NULL);
- } else {
- FSM_TIMER(200);
- }
- ROBOT_UNLOCK(est_pos_odo);
- break;
- default:
- break;
- }
}
\ No newline at end of file
extern bool up;
/* strategy FSM */
FSM_STATE_DECL(get_central_buillon_first);
-FSM_STATE_DECL(homolog_wait_for_start);
+FSM_STATE_DECL(homologation_wait_for_start);
FSM_STATE_DECL(calibrate);
/* Strategy catch buillon in center */
*/
/* HOMOLOGATION states */
/* movement states - buillon */
-FSM_STATE_DECL(homolog_approach_buillon);
+FSM_STATE_DECL(homologation_approach_buillon);
/* Pushing the bottle */
-FSM_STATE_DECL(homolog_push_bottle);
+FSM_STATE_DECL(homologation_push_bottle);
void start_entry();
void start_timer();
void start_go();
int main()
{
int rv;
- //robot_calibrate_odometry(); // calibrate odometry
rv = robot_init();
if (rv) error(1, errno, "robot_init() returned %d\n", rv);
{
robot.odo_cal_a = 1;
robot.odo_cal_b = 1;
- fprintf(stderr, "File not found. \n\n");
+ fprintf(stderr, "ODO calibration file not found! \n\n");
return;
}
char line [15];
}
robot.odo_cal_a = a / num;
robot.odo_cal_b = b / num;
- printf("calibrated value left: %f\n",robot.odo_cal_a);
- printf("calibrated value right: %f\n",robot.odo_cal_b);
+ printf("ODO calibrated value A: %f\n",robot.odo_cal_a);
+ printf("ODO calibrated value B: %f\n",robot.odo_cal_b);
}
//#endif
case EV_START:
start_go();
+ robot_calibrate_odometry();
FSM_TRANSITION(pick_central_buillon);
break;
case EV_TIMER:
start_exit();
break;
case EV_SWITCH_STRATEGY:
- FSM_TRANSITION(homolog_wait_for_start);
+ FSM_TRANSITION(homologation_wait_for_start);
break;
default:;
}
-#include "common-states.h"
-#include "robot.h"
+#define FSM_MAIN
+#include "robodata.h"
+#include <robot.h>
+#include <fsm.h>
+#include <unistd.h>
+#include <math.h>
+#include <movehelper.h>
+#include <map.h>
+#include <sharp.h>
+#include <robomath.h>
+#include <string.h>
+#include <robodim.h>
+#include <error.h>
+#include "actuators.h"
+#include <sharp.h>
+#include <trgen.h>
+#include "match-timing.h"
+#include <stdbool.h>
#include <ul_log.h>
-
+#include "common-states.h"
UL_LOG_CUST(ulogd_strategy_homologation); /* Log domain name = ulogd + name of the file */
-FSM_STATE(homolog_wait_for_start)
+FSM_STATE(homologation_wait_for_start)
{
switch (FSM_EVENT) {
case EV_ENTRY:
//#endif
case EV_START:
start_go();
- SUBFSM_TRANSITION(homolog_approach_buillon, NULL);
+ robot_calibrate_odometry();
+ FSM_TRANSITION(homologation_approach_buillon);
break;
case EV_TIMER:
FSM_TIMER(1000);
break;
default:;
}
+}
+
+FSM_STATE(homologation_approach_buillon)
+{
+ switch(FSM_EVENT) {
+ case EV_ENTRY:
+ robot_trajectory_new(&tcSlow); // new trajectory
+ robot_trajectory_add_point_trans(
+ 0.65,
+ PLAYGROUND_HEIGHT_M - (ROBOT_WIDTH_M/2.0));
+ robot_trajectory_add_point_trans(
+ 0.65,
+ 1.3);
+ robot_trajectory_add_final_point_trans(
+ 0.5,
+ 1.1,
+ NO_TURN());
+ break;
+ case EV_MOTION_DONE:
+ case EV_TIMER:
+ FSM_TRANSITION(homologation_push_bottle);
+ break;
+ default:
+ break;
+ }
+}
+
+FSM_STATE(homologation_push_bottle)
+{
+ switch(FSM_EVENT) {
+ case EV_ENTRY:
+ robot_trajectory_new(&tcSlow); // new trajectory
+ robot_trajectory_add_point_trans(
+ 0.64,
+ 0.7);
+ robot_trajectory_add_final_point_trans(
+ 0.64 + 0.08,
+ ROBOT_AXIS_TO_FRONT_M + 0.05,
+ ARRIVE_FROM(DEG2RAD(270), 0.10));
+ break;
+ case EV_MOTION_DONE:
+ break;
+ default:
+ break;
+ }
}
\ No newline at end of file
-#include "common-states.h"
-#include "robot.h"
+#define FSM_MAIN
+#include "robodata.h"
+#include <robot.h>
+#include <fsm.h>
+#include <unistd.h>
+#include <math.h>
+#include <movehelper.h>
+#include <map.h>
+#include <sharp.h>
+#include <robomath.h>
+#include <string.h>
+#include <robodim.h>
+#include <error.h>
+#include "actuators.h"
+#include <sharp.h>
+#include <trgen.h>
+#include "match-timing.h"
+#include <stdbool.h>
#include <ul_log.h>
+#include "common-states.h"
+
UL_LOG_CUST(ulogd_strategy_odo_calibration); /* Log domain name = ulogd + name of the file */
FSM_STATE(calibrate)
{
- switch (FSM_EVENT) {
- case EV_ENTRY:
- FSM_TIMER(2000);
- robot.odo_cal_a = 1;
- robot.odo_cal_b = 1;
- break;
- case EV_TIMER:
- SUBFSM_TRANSITION(go_back_for_cal,NULL);
- break;
- case EV_RETURN:
- robot_calibrate_odometry();
- //FSM_TRANSITION(get_central_buillon_first);
- break;
- case EV_SWITCH_STRATEGY:
- FSM_TRANSITION(get_central_buillon_first);
- break;
- default:;
- }
+ switch (FSM_EVENT) {
+ case EV_ENTRY:
+ start_entry();
+//#ifdef COMPETITION
+ ul_logmsg("waiting for start\n");
+ FSM_TIMER(1000);
+ break;
+//#endif
+ case EV_START:
+ start_go();
+ robot.obstacle_avoidance_enabled = false;
+ robot.use_back_bumpers = false;
+ robot.odo_cal_a = 1;
+ robot.odo_cal_b = 1;
+ FSM_TRANSITION(go_back_for_cal);
+ break;
+ case EV_TIMER:
+ FSM_TIMER(1000);
+ start_timer();
+ break;
+ case EV_EXIT:
+ start_exit();
+ break;
+ case EV_SWITCH_STRATEGY:
+ FSM_TRANSITION(get_central_buillon_first);
+ break;
+ default:;
+ }
+}
+
+/* State for odometry calibration */
+
+FSM_STATE(go_back_for_cal)
+{
+ double x1 = 0, y1 = 0;
+ char buffer [20];
+ switch (FSM_EVENT) {
+ case EV_ENTRY:
+ robot_set_est_pos_trans(ROBOT_AXIS_TO_BACK_M + 1.0,
+ PLAYGROUND_HEIGHT_M - (ROBOT_WIDTH_M/2.0),
+ 0);
+ robot_move_by(-1.1, NO_TURN(), &tcVerySlow);
+ FSM_TIMER(50);
+ break;
+ case EV_MOTION_DONE:
+ ROBOT_LOCK(est_pos_odo);
+ robot.odo_cal_a = -1.0/robot.odo_distance_a;
+ robot.odo_cal_b = -1.0/robot.odo_distance_b;
+ x1 = robot.odo_distance_a;
+ y1 = robot.odo_distance_b;
+ ROBOT_UNLOCK(est_pos_odo);
+ if(x1 != 0 || y1 != 0) {
+ printf("Distance for calibration: \n");
+ printf("Left%f\n", x1);
+ printf("Right%f\n", y1);
+ FILE * file;
+ file = fopen ("odometry_cal_data","a+");
+ sprintf(buffer, "%4.4f", -1/x1);
+ fputs (buffer,file);
+ fputs (" ", file);
+ sprintf(buffer, "%4.4f", -1/y1);
+ fputs (buffer,file);
+ fputs ("\n", file);
+ fclose(file);
+ }
+ FSM_TRANSITION(get_central_buillon_first);
+ break;
+ case EV_TIMER:
+ ROBOT_LOCK(est_pos_odo);
+ if(x1 == robot.odo_distance_a){
+ x1 = robot.odo_distance_a;
+ y1 = robot.odo_distance_b;
+ FSM_SIGNAL(MOTION,EV_MOVE_STOP, NULL);
+ FSM_SIGNAL(MAIN, EV_MOTION_DONE, NULL);
+ } else {
+ FSM_TIMER(10);
+ }
+ ROBOT_UNLOCK(est_pos_odo);
+ break;
+ default:
+ break;
+ }
}