]> git.droids-corp.org - aversive.git/commitdiff
other proto for circle
authorzer0 <zer0@carbon.local>
Fri, 29 Jan 2010 23:30:59 +0000 (00:30 +0100)
committerzer0 <zer0@carbon.local>
Fri, 29 Jan 2010 23:30:59 +0000 (00:30 +0100)
modules/devices/robot/trajectory_manager/trajectory_manager_core.c
projects/microb2009/mainboard/commands.c
projects/microb2010/tests/hostsim/cmdline.c
projects/microb2010/tests/hostsim/commands.c
projects/microb2010/tests/hostsim/commands_gen.c
projects/microb2010/tests/hostsim/commands_mainboard.c
projects/microb2010/tests/hostsim/cs.c
projects/microb2010/tests/hostsim/display.py
projects/microb2010/tests/hostsim/main.c

index caa986c88d5c44d2a4b1e57b48daa2bc9d05e1b1..f47068cc6f6a75ffca427fbb0e8d945a40544104 100644 (file)
@@ -475,6 +475,33 @@ void trajectory_manager_xy_event(struct trajectory *traj)
        cs_set_consign(traj->csm_distance, d_consign);
 }
 
+/*
+ * Compute the fastest distance and angle speeds matching the radius
+ * from current traj_speed
+ */
+/* static  */void circle_get_da_speed_from_radius(struct trajectory *traj,
+                                                 double radius_mm,
+                                                 double *speed_d,
+                                                 double *speed_a)
+{
+       /* speed_d = coef * speed_a */
+       double coef;
+       double speed_d2, speed_a2;
+
+       coef = 2. * radius_mm / traj->position->phys.track_mm;
+
+       speed_d2 = traj->a_speed * coef;
+       if (speed_d2 < traj->d_speed) {
+               *speed_d = speed_d2;
+               *speed_a = traj->a_speed;
+       }
+       else {
+               speed_a2 = traj->d_speed / coef;
+               *speed_d = traj->d_speed;
+               *speed_a = speed_a2;
+       }
+}
+
 /* trajectory event for circles */
 /* XXX static */
 void trajectory_manager_circle_event(struct trajectory *traj)
@@ -485,6 +512,8 @@ void trajectory_manager_circle_event(struct trajectory *traj)
        double a = position_get_a_rad_double(traj->position);
        int32_t d_consign = 0, a_consign = 0;
        double angle_to_center_rad;
+       double coef_p, coef_d;
+       double d_speed, a_speed;
 
        /* These vectors contain target position of the robot in
         * its own coordinates */
@@ -500,58 +529,57 @@ void trajectory_manager_circle_event(struct trajectory *traj)
        vect2_cart2pol(&v2cart_pos, &v2pol_target);
        v2pol_target.theta = simple_modulo_2pi(v2pol_target.theta - a);
 
-       /* wanted direction of center of circle:
-        * if we are far, go in the center direction,
-        * if we are at radius, we want to see the center at 90°
-        * if we are nearer than radius, angle to center is > 90° */
+       /* radius consign */
        radius = traj->target.circle.radius;
-       if (v2pol_target.r > radius) {
-               angle_to_center_rad = radius / v2pol_target.r;
-               angle_to_center_rad *= (M_PI / 2);
-       }
-       else {
-               angle_to_center_rad = 1. - (v2pol_target.r /
-                                           (2 * radius));
-               angle_to_center_rad *= M_PI;
-       }
 
-       /* XXX check flags */
-       v2pol_target.theta -= angle_to_center_rad;
+       coef_p = v2pol_target.r / radius;
+       coef_p = 1. * coef_p;
 
-       /* If the robot is correctly oriented to start moving in distance */
-       /* here limit dist speed depending on v2pol_target.theta */
-       if (ABS(v2pol_target.theta) > traj->a_start_rad)
-               set_quadramp_speed(traj, 0, traj->a_speed);
-       else {
-               set_quadramp_speed(traj, traj->d_speed, traj->a_speed);
-       }
+       angle_to_center_rad = v2pol_target.theta - (M_PI / 2.);
+       angle_to_center_rad = simple_modulo_2pi(angle_to_center_rad);
+       if (angle_to_center_rad > 0.5)
+               angle_to_center_rad = 0.5;
+       if (angle_to_center_rad < -0.5)
+               angle_to_center_rad = -0.5;
+       coef_d = exp(5*angle_to_center_rad);
+       coef_d = coef_d;
+
+       circle_get_da_speed_from_radius(traj, radius / (coef_p * coef_d),
+                                       &d_speed, &a_speed);
+       set_quadramp_speed(traj, d_speed, a_speed);
+
+       EVT_DEBUG(E_TRAJECTORY, "angle=%2.2f radius=%2.2f r=%2.2f coef_p=%2.2f coef_d=%2.2f "
+             "d_speed=%2.2f a_speed=%2.2f",
+                 angle_to_center_rad, radius, v2pol_target.r,
+             coef_p, coef_d, d_speed, a_speed);
 
        /* XXX check flags */
-       d_consign = 40000 + rs_get_distance(traj->robot);
+       d_consign = 400000 + rs_get_distance(traj->robot);
+       a_consign = 400000 + rs_get_angle(traj->robot);
 
        /* angle consign */
-       a_consign = (int32_t)(v2pol_target.theta *
-                             (traj->position->phys.distance_imp_per_mm) *
-                             (traj->position->phys.track_mm) / 2.0);
-       a_consign += rs_get_angle(traj->robot);
+/*     a_consign = (int32_t)(v2pol_target.theta * */
+/*                           (traj->position->phys.distance_imp_per_mm) * */
+/*                           (traj->position->phys.track_mm) / 2.0); */
+/*     a_consign += rs_get_angle(traj->robot); */
 
        /* step 2 : update state, or delete event if we reached the
         * destination */
 
-       /* output angle -> delete event */
-       if (a_consign >= traj->target.circle.dest_angle) {
-               a_consign = traj->target.circle.dest_angle;
-               delete_event(traj);
-       }
+/*     /\* output angle -> delete event *\/ */
+/*     if (a_consign >= traj->target.circle.dest_angle) { */
+/*             a_consign = traj->target.circle.dest_angle; */
+/*             delete_event(traj); */
+/*     } */
 
        /* step 3 : send the processed commands to cs */
 
-       EVT_DEBUG(E_TRAJECTORY,"EVENT CIRCLE d_cur=%" PRIi32 ", d_consign=%" PRIi32
-                 ", d_speed=%" PRIi32 ", a_cur=%" PRIi32 ", a_consign=%" PRIi32
-                 ", a_speed=%" PRIi32 "radius = %f",
-                 rs_get_distance(traj->robot), d_consign, get_quadramp_distance_speed(traj),
-                 rs_get_angle(traj->robot), a_consign, get_quadramp_angle_speed(traj),
-                 radius);
+/*     EVT_DEBUG(E_TRAJECTORY,"EVENT CIRCLE d_cur=%" PRIi32 ", d_consign=%" PRIi32 */
+/*               ", d_speed=%" PRIi32 ", a_cur=%" PRIi32 ", a_consign=%" PRIi32 */
+/*               ", a_speed=%" PRIi32 ", radius = %f", */
+/*               rs_get_distance(traj->robot), d_consign, get_quadramp_distance_speed(traj), */
+/*               rs_get_angle(traj->robot), a_consign, get_quadramp_angle_speed(traj), */
+/*               radius); */
 
        cs_set_consign(traj->csm_angle, a_consign);
        cs_set_consign(traj->csm_distance, d_consign);
@@ -620,33 +648,6 @@ void trajectory_circle_rel(struct trajectory *traj,
        schedule_event(traj);
 }
 
-/*
- * Compute the fastest distance and angle speeds matching the radius
- * from current traj_speed
- */
-/* static  */void circle_get_da_speed_from_radius(struct trajectory *traj,
-                                                 double radius_mm,
-                                                 double *speed_d,
-                                                 double *speed_a)
-{
-       /* speed_d = coef * speed_a */
-       double coef;
-       double speed_d2, speed_a2;
-
-       coef = 2. * radius_mm / traj->position->phys.track_mm;
-
-       speed_d2 = traj->a_speed * coef;
-       if (speed_d2 < traj->d_speed) {
-               *speed_d = speed_d2;
-               *speed_a = traj->a_speed;
-       }
-       else {
-               speed_a2 = traj->d_speed / coef;
-               *speed_d = traj->d_speed;
-               *speed_a = speed_a2;
-       }
-}
-
 /* return the distance in millimeters that corresponds to an angle in
  * degree and a radius in mm */
 /* static  */double circle_get_dist_from_degrees(double radius_mm, double a_deg)
index bbcaacf34d7fd8238480f5ccdd25962bd5a6f2a5..25a4745be08930835a2474936de7c3eb21118b25 100644 (file)
@@ -92,6 +92,7 @@ extern parse_pgm_inst_t cmd_build_z1;
 #ifdef TEST_BEACON
 extern parse_pgm_inst_t cmd_beacon_opp_dump;
 #endif
+extern parse_pgm_inst_t cmd_circle_radius;
 extern parse_pgm_inst_t cmd_test;
 
 /* commands_traj.c */
@@ -193,6 +194,7 @@ parse_pgm_ctx_t main_ctx[] = {
 #ifdef TEST_BEACON
        (parse_pgm_inst_t *)&cmd_beacon_opp_dump,
 #endif
+       (parse_pgm_inst_t *)&cmd_circle_radius,
        (parse_pgm_inst_t *)&cmd_test,
 
        /* commands_traj.c */
index 77392ec9734745cfd83f6e0b7728dd043fa8feb0..edf7601e7f7283fa074ab42fc363549011e4e9db 100644 (file)
@@ -115,7 +115,7 @@ void mylog(struct error * e, ...)
        if (e->severity > ERROR_SEVERITY_ERROR) {
                if (gen.log_level < e->severity)
                        return;
-               
+
                for (i=0; i<NB_LOGS+1; i++)
                        if (gen.logs[i] == e->err_num)
                                break;
@@ -126,12 +126,12 @@ void mylog(struct error * e, ...)
        va_start(ap, e);
        tv = time_get_time();
        printf_P(PSTR("%d.%.3d: "), (int)tv.s, (int)(tv.us/1000UL));
-       
+
        printf_P(PSTR("(%d,%d,%d) "),
                 position_get_x_s16(&mainboard.pos),
                 position_get_y_s16(&mainboard.pos),
                 position_get_a_deg_s16(&mainboard.pos));
-       
+
        vfprintf_P(stdout, e->text, ap);
        printf_P(PSTR("\r\n"));
        va_end(ap);
index cb620caf5b7c6dee0a82ad445e5b95d1017e5614..140ef29bc5707781948d9418dadfe664b30ec886 100644 (file)
@@ -92,6 +92,7 @@ extern parse_pgm_inst_t cmd_build_z1;
 #ifdef TEST_BEACON
 extern parse_pgm_inst_t cmd_beacon_opp_dump;
 #endif
+extern parse_pgm_inst_t cmd_circle_radius;
 extern parse_pgm_inst_t cmd_test;
 
 /* commands_traj.c */
@@ -193,6 +194,7 @@ parse_pgm_ctx_t main_ctx[] = {
 #ifdef TEST_BEACON
        (parse_pgm_inst_t *)&cmd_beacon_opp_dump,
 #endif
+       (parse_pgm_inst_t *)&cmd_circle_radius,
        (parse_pgm_inst_t *)&cmd_test,
 
        /* commands_traj.c */
index 92f896945be1e1d2df41cf0a1ac39d6dbb20bf02..f4fd855b1fc0d72ae401aee2566479a437e61efb 100644 (file)
@@ -471,7 +471,7 @@ prog_char str_log_arg0[] = "log";
 parse_pgm_token_string_t cmd_log_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_log_result, arg0, str_log_arg0);
 prog_char str_log_arg1[] = "level";
 parse_pgm_token_string_t cmd_log_arg1 = TOKEN_STRING_INITIALIZER(struct cmd_log_result, arg1, str_log_arg1);
-parse_pgm_token_num_t cmd_log_arg2 = TOKEN_NUM_INITIALIZER(struct cmd_log_result, arg2, INT32);
+parse_pgm_token_num_t cmd_log_arg2 = TOKEN_NUM_INITIALIZER(struct cmd_log_result, arg2, INT8);
 
 prog_char help_log[] = "Set log options: level (0 -> 5)";
 parse_pgm_inst_t cmd_log = {
index 3b2d82b33ab3111eae48b49d0df3899656e0c276..ca84489a004813a9073acdedf8db65890268d951 100644 (file)
@@ -2197,6 +2197,44 @@ parse_pgm_inst_t cmd_beacon_opp_dump = {
 };
 #endif
 
+/**********************************************************/
+/* Circle_Radius */
+
+/* this structure is filled when cmd_circle_radius is parsed successfully */
+struct cmd_circle_radius_result {
+       fixed_string_t arg0;
+       int32_t radius;
+};
+void circle_get_da_speed_from_radius(struct trajectory *traj,
+                               double radius_mm,
+                               double *speed_d,
+                               double *speed_a);
+/* function called when cmd_circle_radius is parsed successfully */
+static void cmd_circle_radius_parsed(void *parsed_result, void *data)
+{
+       struct cmd_circle_radius_result *res = parsed_result;
+       double d,a;
+       strat_set_speed(SPEED_DIST_SLOW, SPEED_ANGLE_SLOW);
+       circle_get_da_speed_from_radius(&mainboard.traj, res->radius, &d, &a);
+       printf_P(PSTR("d=%2.2f a=%2.2f\r\n"), d, a);
+}
+
+prog_char str_circle_radius_arg0[] = "circle_radius";
+parse_pgm_token_string_t cmd_circle_radius_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_circle_radius_result, arg0, str_circle_radius_arg0);
+parse_pgm_token_num_t cmd_circle_radius_arg1 = TOKEN_NUM_INITIALIZER(struct cmd_circle_radius_result, radius, INT32);
+
+prog_char help_circle_radius[] = "Circle_Radius function";
+parse_pgm_inst_t cmd_circle_radius = {
+       .f = cmd_circle_radius_parsed,  /* function to call */
+       .data = NULL,      /* 2nd arg of func */
+       .help_str = help_circle_radius,
+       .tokens = {        /* token list, NULL terminated */
+               (prog_void *)&cmd_circle_radius_arg0,
+               (prog_void *)&cmd_circle_radius_arg1,
+               NULL,
+       },
+};
+
 /**********************************************************/
 /* Test */
 
index 9766ea990e6f35aa5c9514164656cc676860268a..678ebb825a780ee5c168c7bd5c73a1b197035a25 100644 (file)
@@ -168,7 +168,7 @@ void microb_cs_init(void)
        position_init(&mainboard.pos);
        position_set_physical_params(&mainboard.pos, VIRTUAL_TRACK_MM, DIST_IMP_MM);
        position_set_related_robot_system(&mainboard.pos, &mainboard.rs);
-       //position_set_centrifugal_coef(&mainboard.pos, 0.000016);
+       position_set_centrifugal_coef(&mainboard.pos, 0.000016);
        position_use_ext(&mainboard.pos);
 
        /* TRAJECTORY MANAGER */
index d21cc9e49e0acc9a920bcf45fd6e1ca8ae04f662..fac65cf514edf95cbb3633dcfe905bc1bcb9a7ee 100644 (file)
@@ -33,7 +33,7 @@ def square(sz):
     return sq
 
 sq1 = square(250)
-sq1 = square(500)
+sq2 = square(500)
 
 robot_trail = curve()
 robot_trail_list = []
@@ -49,7 +49,7 @@ def set_robot(x, y, a):
                   0)
 
     # save position
-    save_pos.append(robot.pos.x, robot.pos, a)
+    save_pos.append((robot.pos.x, robot.pos, a))
 
     pos = robot.pos.x, robot.pos.y, 0.3
     if pos != last_pos:
index 31a7832ed8e111ee509bd0a61b7ecca3d349b1b8..d36fa5f32debe6d3086fa6aa492ffd0ffa3a2120 100644 (file)
@@ -94,7 +94,7 @@ int main(void)
 \r
        mainboard.flags = DO_ENCODERS | DO_RS |\r
                DO_POS | DO_POWER | DO_BD | DO_CS;\r
-       strat_reset_pos(1000, 1000, 0);\r
+       strat_reset_pos(1000, 1000, -90);\r
 \r
        cmdline_interact();\r
 \r