From: Nicolas D. <Ba...@us...> - 2011-04-02 20:57:46
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "krobot". The branch, master has been updated via 6d90b631730d84819ae86b701829dc35c1b173f8 (commit) via b972d273f58b18254fb24218becefe72ba47dd06 (commit) from de73d5b2e4253bee8b5a9db7b97cb2138db25b75 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 6d90b631730d84819ae86b701829dc35c1b173f8 Author: Nicolas Dandrimont <Nic...@cr...> Date: Sat Apr 2 22:57:13 2011 +0200 [krobot_viewer] Display the status of the rotary beacon commit b972d273f58b18254fb24218becefe72ba47dd06 Author: Nicolas Dandrimont <Nic...@cr...> Date: Sat Apr 2 22:56:47 2011 +0200 [krobot_message] Implement message types for the rotary beacon ----------------------------------------------------------------------- Changes: diff --git a/info/control2011/src/lib/krobot_message.ml b/info/control2011/src/lib/krobot_message.ml index 60d13dd..3c3e51b 100644 --- a/info/control2011/src/lib/krobot_message.ml +++ b/info/control2011/src/lib/krobot_message.ml @@ -19,6 +19,8 @@ open Lwt_react type direction = Forward | Backward type t = + | Beacon_position of float * float * float + | Beacon_lowlevel_position of float * float * int | Encoder_position_direction_3_4 of int * direction * int * direction | Encoder_position_speed_3 of float * float | Encoder_position_speed_4 of float * float @@ -40,6 +42,18 @@ let string_of_direction = function | Backward -> "Backward" let to_string = function + | Beacon_position(angle, distance, period) -> + sprintf + "Beacon_position(%f, %f, %f)" + angle + distance + period + | Beacon_lowlevel_position(angle, width, period) -> + sprintf + "Beacon_lowlevel_position(%f, %f, %d)" + angle + width + period | Encoder_position_direction_3_4(pos3, dir3, pos4, dir4) -> sprintf "Encoder_position_direction_3_4(%d, %s, %d, %s)" @@ -177,6 +191,28 @@ let encode = function ~remote:false ~format:F29bits ~data + | Beacon_position(angle, length, period) -> + let data = String.create 6 in + put_uint16 data 0 (truncate (angle *. 10000.)); + put_uint16 data 2 (truncate (length *. 1000.)); + put_uint16 data 4 (truncate (period *. 10000.)); + frame + ~identifier:301 + ~kind:Data + ~remote:false + ~format:F29bits + ~data + | Beacon_lowlevel_position(angle, width, period) -> + let data = String.create 6 in + put_uint16 data 0 (truncate (angle *. 10000.)); + put_uint16 data 2 (truncate (width *. 100000.)); + put_uint16 data 4 period; + frame + ~identifier:302 + ~kind:Data + ~remote:false + ~format:F29bits + ~data | Motor_stop -> frame ~identifier:204 @@ -260,6 +296,16 @@ let decode frame = float (get_sint16 frame.data 4) /. 10000.) | 204 -> Motor_stop + | 301 -> + Beacon_position + (float (get_uint16 frame.data 0) /. 10000., + float (get_uint16 frame.data 2) /. 1000., + float (get_uint16 frame.data 4) /. 10000.) + | 302 -> + Beacon_lowlevel_position + (float (get_uint16 frame.data 0) /. 10000., + float (get_uint16 frame.data 2) /. 100000., + get_uint16 frame.data 4) | _ -> Unknown frame with Invalid_argument _ -> diff --git a/info/control2011/src/lib/krobot_message.mli b/info/control2011/src/lib/krobot_message.mli index 5d83d7e..70f56b6 100644 --- a/info/control2011/src/lib/krobot_message.mli +++ b/info/control2011/src/lib/krobot_message.mli @@ -14,6 +14,10 @@ type direction = Forward | Backward (** Type of messages. *) type t = + | Beacon_position of float * float * float + (** The position of the beacon relative to the robot *) + | Beacon_lowlevel_position of float * float * int + (** The position of the beacon as internally stored (for calibration) *) | Encoder_position_direction_3_4 of int * direction * int * direction (** The position and direction of encoders 3 and 4. *) | Encoder_position_speed_3 of float * float diff --git a/info/control2011/src/tools/krobot_viewer.ml b/info/control2011/src/tools/krobot_viewer.ml index c3b1757..5fa46f5 100644 --- a/info/control2011/src/tools/krobot_viewer.ml +++ b/info/control2011/src/tools/krobot_viewer.ml @@ -186,10 +186,17 @@ module Board = struct theta : float; } + type beacon = { + xbeacon : float; + ybeacon : float; + valid : bool; + } + type t = { bus : Krobot_bus.t; ui : Krobot_viewer_ui.window; mutable state : state; + mutable beacon : beacon; mutable points : (float * float) list; mutable event : unit event; mutable moving : bool; @@ -202,6 +209,7 @@ module Board = struct | Red | Blue | Yellow + | Purple let set_color ctx color = let r, g, b = match color with @@ -211,6 +219,7 @@ module Board = struct | Red -> (199., 23., 18.) | Blue -> (0., 59., 128.) | Yellow -> (252., 189., 31.) + | Purple -> (128., 0., 128.) in Cairo.set_source_rgb ctx (r /. 255.) (g /. 255.) (b /. 255.) @@ -379,6 +388,13 @@ module Board = struct Cairo.restore ctx; + (* Draw the beacon *) + if board.beacon.valid then begin + Cairo.arc ctx board.beacon.xbeacon board.beacon.ybeacon 0.04 0. (2. *. pi); + set_color ctx Purple; + Cairo.fill ctx; + end; + (* Draw points. *) Cairo.set_source_rgb ctx 255. 255. 0.; Cairo.move_to ctx board.state.x board.state.y; @@ -508,6 +524,7 @@ module Board = struct bus; ui; state = { x = 0.2; y = 1.9; theta = -0.5 *. pi }; + beacon = { xbeacon = 1.; ybeacon = 1.; valid = true }; points = []; event = E.never; moving = false; @@ -534,6 +551,17 @@ module Board = struct board.ui#entry_moving2#set_text (if m2 then "yes" else "no"); board.ui#entry_moving3#set_text (if m3 then "yes" else "no"); board.ui#entry_moving4#set_text (if m4 then "yes" else "no") + | Beacon_position(angle, distance, period) -> + let newangle = math_mod_float (board.state.theta +. angle) (2. *. pi) in + let x = board.state.x +. distance *. cos (newangle) in + let y = board.state.y +. distance *. sin (newangle) in + let valid = distance <> 0. in + let beacon = { xbeacon = x; ybeacon = y; valid; } in + if beacon <> board.beacon then begin + board.beacon <- beacon; + board.ui#entry_beacon#set_text (if valid then "valid" else "invalid"); + queue_draw board + end | _ -> ()) (Krobot_message.recv bus) diff --git a/info/control2011/src/tools/krobot_viewer_ui.glade b/info/control2011/src/tools/krobot_viewer_ui.glade index 56ec218..45fbd13 100644 --- a/info/control2011/src/tools/krobot_viewer_ui.glade +++ b/info/control2011/src/tools/krobot_viewer_ui.glade @@ -301,7 +301,7 @@ <child> <widget class="GtkTable" id="table1"> <property name="visible">True</property> - <property name="n_rows">9</property> + <property name="n_rows">10</property> <property name="n_columns">2</property> <child> <widget class="GtkSpinButton" id="moving_speed"> @@ -315,8 +315,8 @@ <packing> <property name="left_attach">1</property> <property name="right_attach">2</property> - <property name="top_attach">5</property> - <property name="bottom_attach">6</property> + <property name="top_attach">6</property> + <property name="bottom_attach">7</property> <property name="y_options">GTK_FILL</property> </packing> </child> @@ -332,8 +332,8 @@ <packing> <property name="left_attach">1</property> <property name="right_attach">2</property> - <property name="top_attach">6</property> - <property name="bottom_attach">7</property> + <property name="top_attach">7</property> + <property name="bottom_attach">8</property> <property name="y_options">GTK_FILL</property> </packing> </child> @@ -349,8 +349,8 @@ <packing> <property name="left_attach">1</property> <property name="right_attach">2</property> - <property name="top_attach">7</property> - <property name="bottom_attach">8</property> + <property name="top_attach">8</property> + <property name="bottom_attach">9</property> <property name="y_options">GTK_FILL</property> </packing> </child> @@ -366,8 +366,8 @@ <packing> <property name="left_attach">1</property> <property name="right_attach">2</property> - <property name="top_attach">8</property> - <property name="bottom_attach">9</property> + <property name="top_attach">9</property> + <property name="bottom_attach">10</property> <property name="y_options">GTK_FILL</property> </packing> </child> @@ -397,8 +397,8 @@ </child> </widget> <packing> - <property name="top_attach">5</property> - <property name="bottom_attach">6</property> + <property name="top_attach">6</property> + <property name="bottom_attach">7</property> <property name="x_options">GTK_FILL</property> <property name="y_options">GTK_FILL</property> </packing> @@ -429,8 +429,8 @@ </child> </widget> <packing> - <property name="top_attach">6</property> - <property name="bottom_attach">7</property> + <property name="top_attach">7</property> + <property name="bottom_attach">8</property> <property name="x_options">GTK_FILL</property> <property name="y_options">GTK_FILL</property> </packing> @@ -461,8 +461,8 @@ </child> </widget> <packing> - <property name="top_attach">7</property> - <property name="bottom_attach">8</property> + <property name="top_attach">8</property> + <property name="bottom_attach">9</property> <property name="x_options">GTK_FILL</property> <property name="y_options">GTK_FILL</property> </packing> @@ -493,8 +493,8 @@ </child> </widget> <packing> - <property name="top_attach">8</property> - <property name="bottom_attach">9</property> + <property name="top_attach">9</property> + <property name="bottom_attach">10</property> <property name="x_options">GTK_FILL</property> <property name="y_options">GTK_FILL</property> </packing> @@ -555,8 +555,8 @@ </child> </widget> <packing> - <property name="top_attach">2</property> - <property name="bottom_attach">3</property> + <property name="top_attach">3</property> + <property name="bottom_attach">4</property> </packing> </child> <child> @@ -585,8 +585,8 @@ </child> </widget> <packing> - <property name="top_attach">3</property> - <property name="bottom_attach">4</property> + <property name="top_attach">4</property> + <property name="bottom_attach">5</property> </packing> </child> <child> @@ -615,8 +615,8 @@ </child> </widget> <packing> - <property name="top_attach">4</property> - <property name="bottom_attach">5</property> + <property name="top_attach">5</property> + <property name="bottom_attach">6</property> </packing> </child> <child> @@ -629,8 +629,8 @@ <packing> <property name="left_attach">1</property> <property name="right_attach">2</property> - <property name="top_attach">2</property> - <property name="bottom_attach">3</property> + <property name="top_attach">3</property> + <property name="bottom_attach">4</property> </packing> </child> <child> @@ -643,8 +643,8 @@ <packing> <property name="left_attach">1</property> <property name="right_attach">2</property> - <property name="top_attach">3</property> - <property name="bottom_attach">4</property> + <property name="top_attach">4</property> + <property name="bottom_attach">5</property> </packing> </child> <child> @@ -657,8 +657,8 @@ <packing> <property name="left_attach">1</property> <property name="right_attach">2</property> - <property name="top_attach">4</property> - <property name="bottom_attach">5</property> + <property name="top_attach">5</property> + <property name="bottom_attach">6</property> </packing> </child> <child> @@ -762,6 +762,50 @@ </child> </widget> </child> + <child> + <widget class="GtkHBox" id="hbox16"> + <property name="visible">True</property> + <child> + <widget class="GtkLabel" id="label10"> + <property name="visible">True</property> + <property name="label" translatable="yes">Beacon status:</property> + </widget> + <packing> + <property name="expand">False</property> + <property name="position">0</property> + </packing> + </child> + <child> + <widget class="GtkAlignment" id="alignment10"> + <property name="visible">True</property> + <child> + <placeholder/> + </child> + </widget> + <packing> + <property name="position">1</property> + </packing> + </child> + </widget> + <packing> + <property name="top_attach">2</property> + <property name="bottom_attach">3</property> + </packing> + </child> + <child> + <widget class="GtkEntry" id="entry_beacon"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="editable">False</property> + <property name="invisible_char">•</property> + </widget> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="top_attach">2</property> + <property name="bottom_attach">3</property> + </packing> + </child> </widget> <packing> <property name="expand">False</property> hooks/post-receive -- krobot |