From 068fac5ec55588187a242f3b7ae7033e1f6a39f1 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Sat, 27 Apr 2013 23:51:54 +0200 Subject: digital/io-hub/src/apbirthday: fix conversion from float to integer angle --- digital/io-hub/src/apbirthday/top.cc | 3 ++- digital/io-hub/src/common-cc/move.cc | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'digital') diff --git a/digital/io-hub/src/apbirthday/top.cc b/digital/io-hub/src/apbirthday/top.cc index 0fb37ca1..3f7bf2a5 100644 --- a/digital/io-hub/src/apbirthday/top.cc +++ b/digital/io-hub/src/apbirthday/top.cc @@ -47,7 +47,8 @@ top_cake_angle (const vect_t &pos) float dx = pos.x - pg_cake_pos.x; float dy = pos.y - pg_cake_pos.y; float angle_rad = std::atan2 (dy, dx); - uint16_t angle = angle_rad * ((1 << 16) / (2 * M_PI)); + // Be careful not to lose sign during conversion. + int16_t angle = angle_rad * ((1 << 16) / (2 * M_PI)); return angle; } diff --git a/digital/io-hub/src/common-cc/move.cc b/digital/io-hub/src/common-cc/move.cc index 75613584..5c7d3708 100644 --- a/digital/io-hub/src/common-cc/move.cc +++ b/digital/io-hub/src/common-cc/move.cc @@ -150,7 +150,7 @@ Move::go_or_rotate (const vect_t &dst, uint16_t angle, bool with_angle, // Compute angle to destination, if destination is really near, angle is // almost meaningless. vect_t v = dst; vect_sub (&v, &robot_position.v); - uint16_t dst_angle = 0; + int16_t dst_angle = 0; int16_t diff = 0; if (vect_dot_product (&v, &v) > eps * eps) { -- cgit v1.2.3