New strategy for odometry autocalibration. Robot goes back and calibrate its odometry.
bin_PROGRAMS += competition
competition_SOURCES = competition2012.cc \
- common-states.cc strategy_get_central_buillon.cc
+ common-states.cc strategy_get_central_buillon.cc \
+ strategy_odo_calibration.cc
bin_PROGRAMS += homologation
homologation_SOURCES = homologation2012.cc
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.5, NO_TURN(), &tcSlow);
+ FSM_TIMER(500);
+ break;
+ case EV_MOTION_DONE:
+ ROBOT_LOCK(est_pos_odo);
+ robot.odo_cal_a = 1/robot.odo_distance_a;
+ robot.odo_cal_b = 1/robot.odo_distance_b;
+ x1 = robot.odo_distance_a;
+ y1 = robot.odo_distance_b;
+ ROBOT_UNLOCK(est_pos_odo);
+ printf("EROOR%f", x1);
+ FILE * file;
+ file = fopen ("odometry_cal_data","a+");
+ sprintf(buffer, "%4.4f", 1/x1);
+ fputs (buffer,file);
+ fputs ("\n", file);
+ sprintf(buffer, "%4.4f", 1/y1);
+ fputs (buffer,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(500);
+ }
+ ROBOT_UNLOCK(est_pos_odo);
+ break;
+ default:
+ break;
+ }
}
\ No newline at end of file
/* strategy FSM */
FSM_STATE_DECL(get_central_buillon_first);
FSM_STATE_DECL(ignore_central_buillon);
-//FSM_STATE_DECL(calibrate);
+FSM_STATE_DECL(calibrate);
/* Strategy catch buillon in center */
FSM_STATE_DECL(approach_central_buillon);
//FSM_STATE_DECL(push_nearest_buillon);
//FSM_STATE_DECL(push_bottle_fw);
+/* Autocalibration */
+FSM_STATE_DECL(go_back_for_cal);
+
/* Common states */
FSM_STATE_DECL(leave_home);
FSM_STATE_DECL(leave_home_for_totem);
/*
* competition.cc 12/02/28
*
- * Robot's control program intended for homologation (approval phase) on Eurobot 2012.
+ * Robot's control program intended for competition on Eurobot 2012.
*
* Copyright: (c) 2012 CTU Flamingos
* CTU FEE - Department of Control Engineering
int main()
{
int rv;
-
+ //robot_calibrate_odometry(); // calibrate odometry
rv = robot_init();
if (rv) error(1, errno, "robot_init() returned %d\n", rv);
robot.fsm.motion.debug_states = 1;
//robot.fsm.act.debug_states = 1;
- robot.fsm.main.state = &fsm_state_main_get_central_buillon_first;
+ robot.fsm.main.state = &fsm_state_main_calibrate;
//robot.fsm.main.transition_callback = trans_callback;
//robot.fsm.motion.transition_callback = move_trans_callback;
robot_destroy();
return 0;
-}
\ No newline at end of file
+}
\ No newline at end of file
--- /dev/null
+#include "common-states.h"
+#include "robot.h"
+#include <ul_log.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);
+ 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:;
+ }
+}
+