]> rtime.felk.cvut.cz Git - eurobot/public.git/commitdiff
robofsm: Fix names of events
authorPetr Silhavik <silhavik.p@gmail.com>
Tue, 26 Feb 2013 16:39:26 +0000 (17:39 +0100)
committerPetr Silhavik <silhavik.p@gmail.com>
Tue, 26 Feb 2013 16:39:26 +0000 (17:39 +0100)
src/robofsm/common-states.h
src/robofsm/events.h

index 9d093a375893dc2d0ae8c745fe9620cddc92f72c..a61d9863301fccbe25b886be800fa352ca373afa 100644 (file)
@@ -179,7 +179,7 @@ struct survey : TimedSimpleState<survey, competing> {
                sc::custom_reaction<evTimer>,
                sc::custom_reaction<evMotionDone>,
                sc::transition<evMotionError, move_around>,
-               sc::transition<evEntry, approach_target> > reactions;
+               sc::transition<evTargetDetected, approach_target> > reactions;
       void do_work() {
        //              DBG_PRINT_EVENT("survey");
 #if 1   // FIXME just for test
@@ -195,7 +195,7 @@ struct survey : TimedSimpleState<survey, competing> {
                        }
 #endif
                        // target detected, go to the target
-                       robot.sched.queue_event(robot.MAIN, new evEntry());
+                       robot.sched.queue_event(robot.MAIN, new evTargetDetected());
 //                     DBG_PRINT_EVENT("Target detected!");
                } else {
                        // no target detected in this heading, turn 120°
@@ -227,15 +227,7 @@ struct approach_target : TimedSimpleState<approach_target, competing, recognize_
        approach_target() {
 //             DBG_PRINT_EVENT("approaching target");
                target_cntr = 0;
-               max_target = detected_target.size();
-               x_target = detected_target[target_cntr].x;
-               y_tatget = detected_target[target_cntr].y;
-               target_cntr++;
-               printf("target %d / %d\n", target_cntr, max_target);
-
-               get_approach_point(x_target, y_tatget, &x_approach, &y_approach, &phi_approach);
-               robot.move_helper.goto_notrans(x_approach, y_approach, ARRIVE_FROM(phi_approach, 0.1), &tcSlow);
-            
+               do_work();
        }
        ~approach_target() {
              target_cntr = 0;
@@ -253,7 +245,8 @@ struct approach_target : TimedSimpleState<approach_target, competing, recognize_
                        return discard_event();
                } else if (!robot.target_valid && (target_cntr < max_target)) {
                        // go for next target if any
-                       return transit<approach_target>();
+                       do_work();
+                       return discard_event();
                } else {
                        // go to new point and survey
                        return transit<move_around>();
@@ -271,7 +264,16 @@ struct approach_target : TimedSimpleState<approach_target, competing, recognize_
                sc::custom_reaction<evMotionDone>,
                sc::custom_reaction<evReturn>,
                sc::custom_reaction<evMotionError> > reactions;
-       
+       void do_work() {
+               max_target = detected_target.size();
+               x_target = detected_target[target_cntr].x;
+               y_tatget = detected_target[target_cntr].y;
+               target_cntr++;
+               printf("target %d / %d\n", target_cntr, max_target);
+
+               get_approach_point(x_target, y_tatget, &x_approach, &y_approach, &phi_approach);
+               robot.move_helper.goto_notrans(x_approach, y_approach, ARRIVE_FROM(phi_approach, 0.1), &tcSlow);
+       }
 };
 
 struct move_around : TimedSimpleState<move_around, competing> {
index 145bc83697c2b8efdfd980d1223504e8042865a6..7b0c170a087e806b036c44c9a7b679cad3013046 100644 (file)
@@ -21,6 +21,11 @@ struct evRunSubFSM : sc::event< evRunSubFSM > {
        evRunSubFSM(void *par = NULL) : ev_ptr(par) {};
 };
 
+struct evTargetDetected : sc::event< evTargetDetected > {
+       void *ev_ptr;
+       evTargetDetected(void *par = NULL) : ev_ptr(par) {};
+};
+
 struct evEntry : sc::event< evEntry > {
        void *ev_ptr;
        evEntry(void *par = NULL) : ev_ptr(par) {};