From: Jérémie D. <Ba...@us...> - 2010-05-09 16:02:14
|
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 32305d14f1b6e3b39f5641e3a84fe452666eb6c0 (commit) via 0927b83a2a2326fb5a54fbba5990a67761b59aab (commit) via 5f13c2909df77c032ae09c65822b00f58b457f8c (commit) via 495382eb3d762fa1b48a9a94a24a18e56f8011a9 (commit) via da74a25ae06c5de0fef21380a06409f99debe82d (commit) from 9b55fdc6db731cc9f59d67253373f8a5c210e93f (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 32305d14f1b6e3b39f5641e3a84fe452666eb6c0 Author: Jérémie Dimino <je...@di...> Date: Sun May 9 18:01:36 2010 +0200 make check more verbose commit 0927b83a2a2326fb5a54fbba5990a67761b59aab Author: Jérémie Dimino <je...@di...> Date: Sun May 9 17:57:25 2010 +0200 Fix reply for Go* methods commit 5f13c2909df77c032ae09c65822b00f58b457f8c Author: Jérémie Dimino <je...@di...> Date: Sun May 9 17:42:53 2010 +0200 AX12_GOTO does not returns a reply commit 495382eb3d762fa1b48a9a94a24a18e56f8011a9 Author: Jérémie Dimino <je...@di...> Date: Sun May 9 17:39:46 2010 +0200 use goto instead of set_ax12 for moving the infrared sensors commit da74a25ae06c5de0fef21380a06409f99debe82d Author: Jérémie Dimino <je...@di...> Date: Sun May 9 17:06:21 2010 +0200 reorganize lib-krobot/Krobot into sub-modules + add commands for the ax12 of the infrared sensors ----------------------------------------------------------------------- Changes: diff --git a/info/control/_tags b/info/control/_tags index 6cd01b3..303b53b 100644 --- a/info/control/_tags +++ b/info/control/_tags @@ -30,6 +30,7 @@ <clients/controller.*>: pkg_lwt.text <clients/script{.*,_lexer.*}>: pkg_text <clients/ax12_control.*>: pkg_lwt.text +<clients/check.*>: pkg_lwt.text # +------------------------------------------------------------------+ # | Services | diff --git a/info/control/clients/check.ml b/info/control/clients/check.ml index ebea3d0..6a5f87b 100644 --- a/info/control/clients/check.ml +++ b/info/control/clients/check.ml @@ -9,27 +9,70 @@ open Lwt open Lwt_io +open Lwt_term + +let test name f = + lwt () = printlf "=[ testing %s ]%s" name (String.make (React.S.value columns - 13 - String.length name) '=') in + try_lwt + lwt () = f () in + printlf "test succeed" + with exn -> + printlc [fg lred; textf "test failed with: %s" (Printexc.to_string exn)] lwt () = lwt krobot = Krobot.create () in - lwt () = printl "testing the gate" in - lwt () = Krobot.Gate.enable krobot in - lwt () = Krobot.Gate.release krobot in - lwt () = Lwt_unix.sleep 0.5 in - lwt () = Krobot.Gate.close krobot in - lwt () = Lwt_unix.sleep 0.5 in - - lwt () = printl "testing the claws" in - lwt () = Krobot.claws_enable krobot in - lwt () = Krobot.claws_open krobot in - lwt () = Lwt_unix.sleep 0.5 in - lwt () = Krobot.claws_close krobot in - - lwt () = printl "testing the grip" in - lwt () = Krobot.grip_open krobot in - lwt () = Lwt_unix.sleep 1.0 in - lwt () = Krobot.grip_close krobot in - lwt () = Lwt_unix.sleep 1.0 in + lwt () = + test "gate" + (fun () -> + lwt () = Krobot.Gate.enable krobot in + lwt () = printl "opening the gate" in + lwt () = Krobot.Gate.release krobot in + lwt () = Lwt_unix.sleep 0.5 in + lwt () = printl "closing the gate" in + lwt () = Krobot.Gate.close krobot in + lwt () = Lwt_unix.sleep 0.5 in + return ()) + in + + lwt () = + test "claws" + (fun () -> + lwt () = Krobot.Claws.enable krobot in + lwt () = printl "opening the claws" in + lwt () = Krobot.Claws.open_ krobot in + lwt () = Lwt_unix.sleep 0.5 in + lwt () = printl "closing the claws" in + lwt () = Krobot.Claws.close krobot in + lwt () = Lwt_unix.sleep 0.5 in + return ()) + in + + lwt () = + test "grip" + (fun () -> + lwt () = printl "opening the grip" in + lwt () = Krobot.Grip.open_ krobot in + lwt () = Lwt_unix.sleep 1.0 in + lwt () = printl "closing the grip" in + lwt () = Krobot.Grip.close krobot in + lwt () = Lwt_unix.sleep 1.0 in + return ()) + in + + lwt () = + test "infrared" + (fun () -> + lwt () = printl "going to the left" in + lwt () = Krobot.Infrared.go_left krobot in + lwt () = Lwt_unix.sleep 1.5 in + lwt () = printl "going to the right" in + lwt () = Krobot.Infrared.go_right krobot in + lwt () = Lwt_unix.sleep 1.5 in + lwt () = printl "going to the center" in + lwt () = Krobot.Infrared.go_center krobot in + lwt () = Lwt_unix.sleep 1.0 in + return ()) + in return () diff --git a/info/control/clients/controller.ml b/info/control/clients/controller.ml index 4d90632..13a7d93 100644 --- a/info/control/clients/controller.ml +++ b/info/control/clients/controller.ml @@ -223,7 +223,7 @@ let draw krobot = lwt () = if driver && devices.Krobot.dev_range_finders then begin - lwt range_finders = OBus_property.get (Krobot.range_finders krobot) in + lwt range_finders = OBus_property.get (Krobot.Range_finders.measures krobot) in for i = 0 to 7 do Draw.textc zone 0 i [textf "%d : " i; text (Text.repeat (range_finders.(i) * 14 / 3146) "=")] done; @@ -238,7 +238,7 @@ let draw krobot = lwt () = if driver && devices.Krobot.dev_logic_sensors then begin - lwt logic_sensors = OBus_property.get (Krobot.logic_sensors krobot) in + lwt logic_sensors = OBus_property.get (Krobot.Logic_sensors.states krobot) in for i = 0 to 7 do let j = i * 2 in Draw.textf zone 20 i "%02d : %s %02d : %s" @@ -291,7 +291,7 @@ let draw krobot = let x = x + 12 in lwt () = if driver && devices.Krobot.dev_compass then begin - lwt compass = OBus_property.get (Krobot.compass krobot) in + lwt compass = OBus_property.get (Krobot.Compass.measure krobot) in Draw.textf zone x 2 "compass = %d" compass; return () end else begin @@ -308,8 +308,8 @@ let draw krobot = in lwt () = if driver && devices.Krobot.dev_motor then begin - lwt forward = OBus_property.get (Krobot.inhibit_forward_until krobot) - and backward = OBus_property.get (Krobot.inhibit_backward_until krobot) in + lwt forward = OBus_property.get (Krobot.Motors.inhibit_forward_until krobot) + and backward = OBus_property.get (Krobot.Motors.inhibit_backward_until krobot) in Draw.textc zone x 3 (text_of_motor_state "move forward: " forward); Draw.textc zone x 4 (text_of_motor_state "move backward: " backward); return () @@ -322,7 +322,7 @@ let draw krobot = in lwt () = if driver && devices.Krobot.dev_infrared then begin - lwt i1, i2 = OBus_property.get (Krobot.infrared_states krobot) in + lwt i1, i2 = OBus_property.get (Krobot.Infrared.states krobot) in Draw.textc zone x 5 [textf "infrared 1: %d" i1]; Draw.textc zone x 6 [textf "infrared 2: %d" i2]; return () @@ -335,7 +335,7 @@ let draw krobot = in lwt () = if driver && devices.Krobot.dev_power then begin - lwt current = OBus_property.get (Krobot.current_voltage krobot) in + lwt current = OBus_property.get (Krobot.Power.current krobot) in Draw.textc zone x 7 [textf "current: %d mA" current]; return () end else begin @@ -513,18 +513,18 @@ lwt () = (function | true -> join [ - notify_property (Krobot.compass krobot); - notify_property (Krobot.logic_sensors krobot); - notify_property (Krobot.range_finders krobot); - notify_property (Krobot.inhibit_forward_until krobot); - notify_property (Krobot.inhibit_backward_until krobot); + notify_property (Krobot.Compass.measure krobot); + notify_property (Krobot.Logic_sensors.states krobot); + notify_property (Krobot.Range_finders.measures krobot); + notify_property (Krobot.Motors.inhibit_forward_until krobot); + notify_property (Krobot.Motors.inhibit_backward_until krobot); notify_property (Krobot.Card.state krobot `Interface); notify_property (Krobot.Card.state krobot `Sensor); notify_property (Krobot.Card.state krobot `Motor); notify_property (Krobot.Card.state krobot `Monitoring); notify_property (Krobot.devices_status krobot); - notify_property (Krobot.infrared_states krobot); - notify_property (Krobot.current_voltage krobot); + notify_property (Krobot.Infrared.states krobot); + notify_property (Krobot.Power.current krobot); ] | false -> List.iter Lwt_signal.disable !notifiers; diff --git a/info/control/clients/init_position.ml b/info/control/clients/init_position.ml index 16aa2e0..e8870ee 100644 --- a/info/control/clients/init_position.ml +++ b/info/control/clients/init_position.ml @@ -13,7 +13,7 @@ open Lwt let move_backward_slowly krobot = lwt () = Lwt_log.notice "moving backward" in - Krobot.move krobot ~distance:(-1000) ~velocity:100 ~acceleration:100 >>= function + Krobot.Motors.move krobot ~distance:(-1000) ~velocity:100 ~acceleration:100 >>= function | `OK -> lwt () = Lwt_log.error "where am i ???" in exit 1 @@ -26,16 +26,16 @@ lwt () = lwt () = move_backward_slowly krobot in lwt () = Lwt_log.notice "going to initial position on first axis" in - lwt _ = Krobot.move krobot ~distance:Config.initial_position ~velocity:400 ~acceleration:800 in + lwt _ = Krobot.Motors.move krobot ~distance:Config.initial_position ~velocity:400 ~acceleration:800 in lwt () = Lwt_log.notice "turning" in - lwt _ = Krobot.turn krobot ~angle:(-90) ~velocity:400 ~acceleration:800 in + lwt _ = Krobot.Motors.turn krobot ~angle:(-90) ~velocity:400 ~acceleration:800 in lwt () = move_backward_slowly krobot in lwt () = Lwt_log.notice "going to initial position on second axis" in - lwt _ = Krobot.move krobot ~distance:Config.initial_position ~velocity:400 ~acceleration:800 in + lwt _ = Krobot.Motors.move krobot ~distance:Config.initial_position ~velocity:400 ~acceleration:800 in lwt () = Lwt_log.notice "turning" in - lwt _ = Krobot.turn krobot ~angle:45 ~velocity:400 ~acceleration:800 in + lwt _ = Krobot.Motors.turn krobot ~angle:45 ~velocity:400 ~acceleration:800 in return () diff --git a/info/control/clients/joy_control.ml b/info/control/clients/joy_control.ml index e903844..0bf7de7 100644 --- a/info/control/clients/joy_control.ml +++ b/info/control/clients/joy_control.ml @@ -141,7 +141,7 @@ let rec set_velocities krobot velocities = lwt () = try_call "set-velocities" (fun () -> - Krobot.set_velocities krobot ~velocities ~accelerations ~duration) + Krobot.Motors.set_velocities krobot ~velocities ~accelerations ~duration) in if velocities = (0, 0) then return () @@ -188,7 +188,7 @@ let parent_loop krobot pipe = | JoyButtonPressed ButtonSquare -> stop := true; cancel !thread; - lwt () = try_call "stop-motors" (fun () -> Krobot.stop_motors krobot ~mode:`Abrupt) in + lwt () = try_call "stop-motors" (fun () -> Krobot.Motors.stop krobot ~mode:`Abrupt) in loop () | JoyButtonReleased ButtonSquare -> stop := false; diff --git a/info/control/clients/script.ml b/info/control/clients/script.ml index cd5e65a..d78724a 100644 --- a/info/control/clients/script.ml +++ b/info/control/clients/script.ml @@ -332,16 +332,16 @@ let () = register "forward" (f3 distance velocity acceleration) (fun logger krobot distance velocity acceleration -> - Krobot.move krobot distance velocity acceleration >>= move_result logger); + Krobot.Motors.move krobot distance velocity acceleration >>= move_result logger); register "backward" (f3 distance velocity acceleration) (fun logger krobot distance velocity acceleration -> - Krobot.move krobot (-distance) velocity acceleration >>= move_result logger); + Krobot.Motors.move krobot (-distance) velocity acceleration >>= move_result logger); register "left" (f3 angle velocity acceleration) (fun logger krobot angle velocity acceleration -> - Krobot.turn krobot angle velocity acceleration >>= move_result logger); + Krobot.Motors.turn krobot angle velocity acceleration >>= move_result logger); register "right" (f3 angle velocity acceleration) (fun logger krobot angle velocity acceleration -> - Krobot.turn krobot (-angle) velocity acceleration >>= move_result logger); + Krobot.Motors.turn krobot (-angle) velocity acceleration >>= move_result logger); register"goto" (f6 (int ~default:0 "x") (int ~default:0 "y") velocity acceleration @@ -350,7 +350,7 @@ let () = ("curve-right", `Curve_right)]) (int ~default:0 "bypass-distance")) (fun logger krobot x y velocity acceleration mode bypass -> - Krobot.goto krobot x y velocity acceleration mode bypass >>= move_result logger); + Krobot.Motors.goto krobot x y velocity acceleration mode bypass >>= move_result logger); (* +---------------------------------------------------------------+ | Motors low-level conrol | @@ -364,14 +364,14 @@ let () = register "motors-state" f0 (fun logger krobot -> - lwt state = OBus_property.get (Krobot.motors_state krobot) in + lwt state = OBus_property.get (Krobot.Motors.state krobot) in logger [text "motors state: "; text state]); register "stop-motors" (f1 stop_mode) (fun logger krobot mode -> - Krobot.stop_motors krobot ~mode); + Krobot.Motors.stop krobot ~mode); register "set-velocities" (f5 (velocity "-left") (velocity "-right") (acceleration "-left") (acceleration "-right") duration) (fun logger krobot velocity_left velocity_right acceleration_left acceleration_right duration -> - Krobot.set_velocities krobot + Krobot.Motors.set_velocities krobot ~velocities:(velocity_left, velocity_right) ~accelerations:(acceleration_left, acceleration_right) ~duration); @@ -398,7 +398,7 @@ let () = register ~path:["calibration"] "get" f0 (fun logger krobot -> - lwt cals = Lwt_list.map_p (Krobot.get_calibration krobot) [0; 1; 2; 3; 4; 5; 6; 7] in + lwt cals = Lwt_list.map_p (Krobot.Range_finders.get_calibration krobot) [0; 1; 2; 3; 4; 5; 6; 7] in let rec loop i = function | [] -> return () @@ -414,11 +414,11 @@ let () = loop 0 cals); register ~path:["calibration"] "start" (f2 (int "range-finder") (keyword "skip-meas" [("true", true); ("false", false)])) - (fun logger -> Krobot.calibration_start); + (fun logger -> Krobot.Range_finders.calibration_start); register ~path:["calibration"] "stop" f0 - (fun logger -> Krobot.calibration_stop); + (fun logger -> Krobot.Range_finders.calibration_stop); register ~path:["calibration"] "continue" f0 - (fun logger -> Krobot.calibration_continue); + (fun logger -> Krobot.Range_finders.calibration_continue); (* +---------------------------------------------------------------+ | AX12 | @@ -473,19 +473,19 @@ let () = register ~path:["grip"] "up" f0 (fun logger krobot -> - Krobot.grip_up krobot); + Krobot.Grip.up krobot); register ~path:["grip"] "down" f0 (fun logger krobot -> - Krobot.grip_down krobot); + Krobot.Grip.down krobot); register ~path:["grip"] "open" f0 (fun logger krobot -> - Krobot.grip_open krobot); + Krobot.Grip.open_ krobot); register ~path:["grip"] "close" f0 (fun logger krobot -> - Krobot.grip_close krobot); + Krobot.Grip.close krobot); register ~path:["grip"] "release" f0 (fun logger krobot -> - Krobot.grip_release krobot); + Krobot.Grip.release krobot); (* +---------------------------------------------------------------+ | Claws | @@ -493,19 +493,19 @@ let () = register ~path:["claws"] "open" f0 (fun logger krobot -> - Krobot.claws_open krobot); + Krobot.Claws.open_ krobot); register ~path:["claws"] "close" f0 (fun logger krobot -> - Krobot.claws_close krobot); + Krobot.Claws.close krobot); register ~path:["claws"] "enable" f0 (fun logger krobot -> - Krobot.claws_enable krobot); + Krobot.Claws.enable krobot); register ~path:["claws"] "disable" f0 (fun logger krobot -> - Krobot.claws_disable krobot); + Krobot.Claws.disable krobot); register ~path:["claws"] "take" f0 (fun logger krobot -> - Krobot.claws_take krobot); + Krobot.Claws.take krobot); (* +---------------------------------------------------------------+ | Gate | @@ -536,7 +536,21 @@ let () = register ~path:["power"] "set-buzzer-state" (f1 (keyword "state" [("true", true); ("false", false)])) (fun logger krobot state -> - Krobot.set_buzzer_state krobot state) + Krobot.Power.set_buzzer_state krobot state); + + (* +---------------------------------------------------------------+ + | Infrared sensors | + +---------------------------------------------------------------+ *) + + register ~path:["infrared"] "left" f0 + (fun logger krobot -> + Krobot.Infrared.go_left krobot); + register ~path:["infrared"] "right" f0 + (fun logger krobot -> + Krobot.Infrared.go_right krobot); + register ~path:["infrared"] "center" f0 + (fun logger krobot -> + Krobot.Infrared.go_center krobot) (* +-----------------------------------------------------------------+ | Unsafe commands | diff --git a/info/control/driver/driver.ml b/info/control/driver/driver.ml index b48af48..a2bf6d9 100644 --- a/info/control/driver/driver.ml +++ b/info/control/driver/driver.ml @@ -158,31 +158,6 @@ struct }] end - -(* +-----------------------------------------------------------------+ - | Infrared | - +-----------------------------------------------------------------+ *) - -module Infrared = -struct - include Service(struct let name = "Infrared" end) - - open Krobot_interfaces.Fr_krobot_Device_Infrared - - let states = - poll card (0, 0) - (fun card -> - lwt ar = USBCard.call Commands.Infrared.get_state card () in - return (ar.(0), ar.(1))) - - let () = - OBus_object.add_interfaces obus - [make ~notify_mode - { - p_States = (fun () -> React.S.map (fun (i1, i2) -> (Int32.of_int i1, Int32.of_int i2)) states); - }] -end - (* +-----------------------------------------------------------------+ | Compass | +-----------------------------------------------------------------+ *) @@ -386,19 +361,6 @@ struct OBus_object.add_interfaces obus [make ~notify_mode { - m_SetAX12 = ( - fun ctx () positions -> - let positions = - List.map - (fun (x1, x2, x3) -> - { aa_id = Int32.to_int x1; - aa_position = Int32.to_int x2; - aa_velocity = Int32.to_int x3 }) - positions - in - lwt () = set_ax12 positions in - OBus_method.return ctx () - ); m_GripUp = ( fun ctx obj () -> lwt result = grip_up obj in @@ -428,6 +390,54 @@ struct end (* +-----------------------------------------------------------------+ + | Infrared | + +-----------------------------------------------------------------+ *) + +module Infrared = +struct + include Service(struct let name = "Infrared" end) + + open Krobot_interfaces.Fr_krobot_Device_Infrared + + let states = + poll card (0, 0) + (fun card -> + lwt ar = USBCard.call Commands.Infrared.get_state card () in + return (ar.(0), ar.(1))) + + let go_left () = + USBCard.call Commands.AX12.goto (get_card card_interface) (1, 750, 200, `Now) + + let go_right () = + USBCard.call Commands.AX12.goto (get_card card_interface) (1, 250, 200, `Now) + + let go_center () = + USBCard.call Commands.AX12.goto (get_card card_interface) (1, 550, 200, `Now) + + let () = + OBus_object.add_interfaces obus + [make ~notify_mode + { + p_States = (fun () -> React.S.map (fun (i1, i2) -> (Int32.of_int i1, Int32.of_int i2)) states); + m_GoLeft = ( + fun ctx () () -> + lwt () = go_left () in + OBus_method.return ctx () + ); + m_GoRight = ( + fun ctx () () -> + lwt () = go_right () in + OBus_method.return ctx () + ); + m_GoCenter = ( + fun ctx () () -> + lwt () = go_center () in + OBus_method.return ctx () + ); + }] +end + +(* +-----------------------------------------------------------------+ | Logic sensors | +-----------------------------------------------------------------+ *) diff --git a/info/control/lib-krobot/krobot.ml b/info/control/lib-krobot/krobot.ml index 9170d97..851a0ce 100644 --- a/info/control/lib-krobot/krobot.ml +++ b/info/control/lib-krobot/krobot.ml @@ -24,8 +24,6 @@ include OBus_peer.Private type team = Team_red | Team_green -type card = [ `Interface | `Sensor | `Motor | `Monitoring ] - let card krobot card = OBus_proxy.make krobot ["fr"; "krobot"; "Cards"; (match card with @@ -66,39 +64,42 @@ let devices_status krobot = (OBus_proxy.make krobot ["fr"; "krobot"; "Manager"])) (* +-----------------------------------------------------------------+ - | Reactive signals | + | Infrared | +-----------------------------------------------------------------+ *) -(* -let team krobot = - React.S.map (fun ls -> if ls.(14) then Team_red else Team_green) krobot.logic_sensors +module Infrared = +struct + open Krobot_interfaces.Fr_krobot_Device_Infrared -let jack krobot = - React.S.map (fun ls -> ls.(15)) krobot.logic_sensors -*) + let states krobot = + OBus_property.map_r + (fun (i1, i2) -> (Int32.to_int i1, Int32.to_int i2)) + (OBus_property.make ~notify_mode p_States (device krobot "Infrared")) -(* +-----------------------------------------------------------------+ - | Infrared | - +-----------------------------------------------------------------+ *) + let go_left krobot = + OBus_method.call m_GoLeft (device krobot "Infrared") () -open Krobot_interfaces.Fr_krobot_Device_Infrared + let go_right krobot = + OBus_method.call m_GoRight (device krobot "Infrared") () -let infrared_states krobot = - OBus_property.map_r - (fun (i1, i2) -> (Int32.to_int i1, Int32.to_int i2)) - (OBus_property.make ~notify_mode p_States (device krobot "Infrared")) + let go_center krobot = + OBus_method.call m_GoCenter (device krobot "Infrared") () +end (* +-----------------------------------------------------------------+ | Power | +-----------------------------------------------------------------+ *) -open Krobot_interfaces.Fr_krobot_Device_Power +module Power = +struct + open Krobot_interfaces.Fr_krobot_Device_Power -let set_buzzer_state krobot state = - OBus_method.call m_SetBuzzerState (device krobot "Power") state + let set_buzzer_state krobot state = + OBus_method.call m_SetBuzzerState (device krobot "Power") state -let current_voltage krobot = - OBus_property.map_r Int32.to_int (OBus_property.make ~notify_mode p_Current (device krobot "Power")) + let current krobot = + OBus_property.map_r Int32.to_int (OBus_property.make ~notify_mode p_Current (device krobot "Power")) +end (* +-----------------------------------------------------------------+ | Gate | @@ -131,158 +132,171 @@ end | Compass | +-----------------------------------------------------------------+ *) -open Krobot_interfaces.Fr_krobot_Device_Compass +module Compass = +struct + open Krobot_interfaces.Fr_krobot_Device_Compass -let compass krobot = - OBus_property.map_r Int32.to_int (OBus_property.make p_Value ~notify_mode (device krobot "Compass")) + let measure krobot = + OBus_property.map_r Int32.to_int (OBus_property.make p_Value ~notify_mode (device krobot "Compass")) +end (* +-----------------------------------------------------------------+ | Logic sensors | +-----------------------------------------------------------------+ *) -open Krobot_interfaces.Fr_krobot_Device_LogicSensors +module Logic_sensors = +struct + open Krobot_interfaces.Fr_krobot_Device_LogicSensors -let logic_sensors krobot = - OBus_property.map_r - Array.of_list - (OBus_property.make p_Value ~notify_mode (device krobot "LogicSensors")) + let states krobot = + OBus_property.map_r + Array.of_list + (OBus_property.make p_Value ~notify_mode (device krobot "LogicSensors")) +end (* +-----------------------------------------------------------------+ | LCD | +-----------------------------------------------------------------+ *) -open Krobot_interfaces.Fr_krobot_Device_LCD +module LCD = +struct + open Krobot_interfaces.Fr_krobot_Device_LCD -let set_lcd krobot lines = - OBus_method.call m_SetLCD (device krobot "LCD") lines + let set krobot lines = + OBus_method.call m_SetLCD (device krobot "LCD") lines -let backlight_on krobot = - OBus_method.call m_BacklightOn (device krobot "LCD") () + let backlight_on krobot = + OBus_method.call m_BacklightOn (device krobot "LCD") () -let backlight_off krobot = - OBus_method.call m_BacklightOff (device krobot "LCD") () + let backlight_off krobot = + OBus_method.call m_BacklightOff (device krobot "LCD") () +end (* +-----------------------------------------------------------------+ | Range finders | +-----------------------------------------------------------------+ *) -open Krobot_interfaces.Fr_krobot_Device_RangeFinders +module Range_finders = +struct + open Krobot_interfaces.Fr_krobot_Device_RangeFinders -let range_finders krobot = - OBus_property.map_r - (fun l -> Array.of_list (List.map Int32.to_int l)) - (OBus_property.make p_Value ~notify_mode (device krobot "RangeFinders")) + let measures krobot = + OBus_property.map_r + (fun l -> Array.of_list (List.map Int32.to_int l)) + (OBus_property.make p_Value ~notify_mode (device krobot "RangeFinders")) -let get_calibration krobot id = - lwt l = OBus_method.call m_GetCalibration (device krobot "RangeFinders") (Int32.of_int id) in - return (Array.of_list (List.map Int32.to_int l)) + let get_calibration krobot id = + lwt l = OBus_method.call m_GetCalibration (device krobot "RangeFinders") (Int32.of_int id) in + return (Array.of_list (List.map Int32.to_int l)) -let calibration_start krobot id skip_meas = - OBus_method.call m_CalibrationStart (device krobot "RangeFinders") (Int32.of_int id, skip_meas) + let calibration_start krobot id skip_meas = + OBus_method.call m_CalibrationStart (device krobot "RangeFinders") (Int32.of_int id, skip_meas) -let calibration_stop krobot = - OBus_method.call m_CalibrationStop (device krobot "RangeFinders") () + let calibration_stop krobot = + OBus_method.call m_CalibrationStop (device krobot "RangeFinders") () -let calibration_continue krobot = - OBus_method.call m_CalibrationContinue (device krobot "RangeFinders") () + let calibration_continue krobot = + OBus_method.call m_CalibrationContinue (device krobot "RangeFinders") () +end (* +-----------------------------------------------------------------+ - | AX12 | + | Grip | +-----------------------------------------------------------------+ *) -open Krobot_interfaces.Fr_krobot_Device_AX12 - -let set_ax12 krobot actions = - OBus_method.call m_SetAX12 (device krobot "AX12") - (List.map - (fun aa -> (Int32.of_int aa.aa_id, - Int32.of_int aa.aa_position, - Int32.of_int aa.aa_velocity)) - actions) +module Grip = +struct + open Krobot_interfaces.Fr_krobot_Device_AX12 -let grip_up krobot = - OBus_method.call m_GripUp (device krobot "AX12") () + let up krobot = + OBus_method.call m_GripUp (device krobot "AX12") () -let grip_down krobot = - OBus_method.call m_GripDown (device krobot "AX12") () + let down krobot = + OBus_method.call m_GripDown (device krobot "AX12") () -let grip_open krobot = - OBus_method.call m_GripOpen (device krobot "AX12") () + let open_ krobot = + OBus_method.call m_GripOpen (device krobot "AX12") () -let grip_close krobot = - OBus_method.call m_GripClose (device krobot "AX12") () + let close krobot = + OBus_method.call m_GripClose (device krobot "AX12") () -let grip_release krobot = - OBus_method.call m_GripRelease (device krobot "AX12") () + let release krobot = + OBus_method.call m_GripRelease (device krobot "AX12") () +end (* +-----------------------------------------------------------------+ - | Servo | + | Claws | +-----------------------------------------------------------------+ *) -open Krobot_interfaces.Fr_krobot_Device_Servo +module Claws = +struct + open Krobot_interfaces.Fr_krobot_Device_Servo -let claws_enable krobot = - OBus_method.call m_ClawsEnable (device krobot "Servo") () + let enable krobot = + OBus_method.call m_ClawsEnable (device krobot "Servo") () -let claws_disable krobot = - OBus_method.call m_ClawsDisable (device krobot "Servo") () + let disable krobot = + OBus_method.call m_ClawsDisable (device krobot "Servo") () -let claws_open krobot = - OBus_method.call m_ClawsOpen (device krobot "Servo") () + let open_ krobot = + OBus_method.call m_ClawsOpen (device krobot "Servo") () -let claws_close krobot = - OBus_method.call m_ClawsClose (device krobot "Servo") () + let close krobot = + OBus_method.call m_ClawsClose (device krobot "Servo") () -let claws_take krobot = - OBus_method.call m_ClawsTake (device krobot "Servo") () + let take krobot = + OBus_method.call m_ClawsTake (device krobot "Servo") () +end (* +-----------------------------------------------------------------+ | Motors | +-----------------------------------------------------------------+ *) -open Krobot_interfaces.Fr_krobot_Device_Motors - -let turn krobot ~angle ~velocity ~acceleration = - OBus_method.call m_Turn (device krobot "Motors") - (Int32.of_int angle, - Int32.of_int velocity, - Int32.of_int acceleration) - >|= move_result_of_int32 - -let move krobot ~distance ~velocity ~acceleration = - OBus_method.call m_Move (device krobot "Motors") - (Int32.of_int distance, - Int32.of_int velocity, - Int32.of_int acceleration) - >|= move_result_of_int32 - -let goto krobot ~x ~y ~velocity ~acceleration ~mode ~bypass_distance = - OBus_method.call m_Goto (device krobot "Motors") - (Int32.of_int x, - Int32.of_int y, - Int32.of_int velocity, - Int32.of_int acceleration, - int32_of_goto_mode mode, - Int32.of_int bypass_distance) - >|= move_result_of_int32 - -let stop_motors krobot ~mode = - OBus_method.call m_StopMotors (device krobot "Motors") (int32_of_stop_mode mode) - -let set_velocities krobot ~velocities:(vl, vr) ~accelerations:(al, ar) ~duration = - OBus_method.call m_SetVelocities (device krobot "Motors") - (Int32.of_int vl, Int32.of_int al, - Int32.of_int vr, Int32.of_int ar, - duration) - -let inhibit_forward_until krobot = - OBus_property.make p_InhibitForwardUntil ~notify_mode (device krobot "Motors") - -let inhibit_backward_until krobot = - OBus_property.make p_InhibitBackwardUntil ~notify_mode (device krobot "Motors") - -let motors_state krobot = - OBus_property.make p_State ~notify_mode (device krobot "Motors") +module Motors = +struct + open Krobot_interfaces.Fr_krobot_Device_Motors + + let turn krobot ~angle ~velocity ~acceleration = + OBus_method.call m_Turn (device krobot "Motors") + (Int32.of_int angle, + Int32.of_int velocity, + Int32.of_int acceleration) + >|= move_result_of_int32 + + let move krobot ~distance ~velocity ~acceleration = + OBus_method.call m_Move (device krobot "Motors") + (Int32.of_int distance, + Int32.of_int velocity, + Int32.of_int acceleration) + >|= move_result_of_int32 + + let goto krobot ~x ~y ~velocity ~acceleration ~mode ~bypass_distance = + OBus_method.call m_Goto (device krobot "Motors") + (Int32.of_int x, + Int32.of_int y, + Int32.of_int velocity, + Int32.of_int acceleration, + int32_of_goto_mode mode, + Int32.of_int bypass_distance) + >|= move_result_of_int32 + + let stop krobot ~mode = + OBus_method.call m_StopMotors (device krobot "Motors") (int32_of_stop_mode mode) + + let set_velocities krobot ~velocities:(vl, vr) ~accelerations:(al, ar) ~duration = + OBus_method.call m_SetVelocities (device krobot "Motors") + (Int32.of_int vl, Int32.of_int al, + Int32.of_int vr, Int32.of_int ar, + duration) + + let inhibit_forward_until krobot = + OBus_property.make p_InhibitForwardUntil ~notify_mode (device krobot "Motors") + + let inhibit_backward_until krobot = + OBus_property.make p_InhibitBackwardUntil ~notify_mode (device krobot "Motors") + + let state krobot = + OBus_property.make p_State ~notify_mode (device krobot "Motors") +end (* +-----------------------------------------------------------------+ | Raw USB calls | @@ -338,6 +352,8 @@ module Card = struct open Krobot_interfaces.Fr_krobot_Card + type card = [ `Interface | `Sensor | `Motor | `Monitoring ] + let name = function | `Interface -> "interface" | `Sensor -> "sensor" diff --git a/info/control/lib-krobot/krobot.mli b/info/control/lib-krobot/krobot.mli index 9bc2768..f34db67 100644 --- a/info/control/lib-krobot/krobot.mli +++ b/info/control/lib-krobot/krobot.mli @@ -14,7 +14,7 @@ include OBus_peer.Private val create : unit -> t Lwt.t - (** [create ()] makes a Krobot valie *) + (** [create ()] makes a Krobot *) val bus : unit -> OBus_bus.t Lwt.t (** [bus ()] returns the bus used by the krobot. @@ -24,15 +24,6 @@ val bus : unit -> OBus_bus.t Lwt.t - otherwise it uses the local krobot bus *) -val device : t -> OBus_path.element -> OBus_proxy.t - (** [device name] returns a proxy for the given device *) - -type card = [ `Interface | `Sensor | `Motor | `Monitoring ] - (** Type of a card *) - -val card : t -> card -> OBus_proxy.t - (** [card name] returns a proxy for the given card *) - (** {6 Devices} *) type devices_status = { @@ -49,15 +40,22 @@ type devices_status = { val devices_status : t -> devices_status OBus_property.r (** List of services with their status *) -(** {6 Infrared} *) +module Infrared : sig + val states : t -> (int * int) OBus_property.r + (** Property holding the state of the infrared sensors *) -val infrared_states : t -> (int * int) OBus_property.r - -(** {6 Power} *) + val go_right : t -> unit Lwt.t + val go_left : t -> unit Lwt.t + val go_center : t -> unit Lwt.t +end -val set_buzzer_state : t -> bool -> unit Lwt.t +module Power : sig + val set_buzzer_state : t -> bool -> unit Lwt.t + (** Enables or disables the buzzer *) -val current_voltage : t -> int OBus_property.r + val current : t -> int OBus_property.r + (** Proeprty holding the current used by the robot *) +end (** {6 Gate} *) @@ -81,106 +79,95 @@ module Gate : sig (** Stop holding the gate *) end -(** {6 LCD} *) - -val set_lcd : t -> string list -> unit Lwt.t - (** [set_lcd lines] set the lines displayed on the LCD. [lines] may - contains at most 4 lines, of maximum length 20. *) - -val backlight_on : t -> unit Lwt.t - (** Turn on the LCD backlight *) - -val backlight_off : t -> unit Lwt.t - (** Turn off the LCD backlight *) - -(** {6 Compass} *) - -val compass : t -> int OBus_property.r - (** Signal holding the current value of the compass. *) - -(** {6 Logic sensors} *) - -val logic_sensors : t -> bool array OBus_property.r - (** Signal holding the current state of logic sensors. *) - -(** {6 Team/jack stuff} *) -(* -type team = Team_red | Team_green - -val team : t -> team OBus_property.r - (** Signal holding the state of the team button *) - -val jack : t -> bool OBus_property.r - (** Signal holding the status of the jack *) -*) -(** {6 Range finders} *) - -val range_finders : t -> int array OBus_property.r - (** Signal holding the current range finders state *) +module LCD : sig + val set : t -> string list -> unit Lwt.t + (** [set lines] set the lines displayed on the LCD. [lines] may + contains at most 4 lines, of maximum length 20. *) -val get_calibration : t -> int -> int array Lwt.t - (** [get_calibration krobot num] returns the calibration of the - given range finder. *) + val backlight_on : t -> unit Lwt.t + (** Turn on the LCD backlight *) -val calibration_start : t -> int -> bool -> unit Lwt.t -val calibration_continue : t -> unit Lwt.t -val calibration_stop : t -> unit Lwt.t - -(** {6 AX12s} *) - -val set_ax12 : t -> Types.ax12_action list -> unit Lwt.t - (** [set_ax12 krobot actions] move all given ax12 at the same - time. *) - -val grip_up : t -> unit Lwt.t -val grip_down : t -> unit Lwt.t -val grip_open : t -> unit Lwt.t -val grip_close : t -> unit Lwt.t -val grip_release : t -> unit Lwt.t - -(** {6 Servos} *) + val backlight_off : t -> unit Lwt.t + (** Turn off the LCD backlight *) +end -val claws_enable : t -> unit Lwt.t -val claws_disable : t -> unit Lwt.t -val claws_open : t -> unit Lwt.t -val claws_close : t -> unit Lwt.t -val claws_take : t -> unit Lwt.t +module Compass : sig + val measure : t -> int OBus_property.r + (** Signal holding the current value of the compass. *) +end -(** {6 Motors} *) +module Logic_sensors : sig + val states : t -> bool array OBus_property.r + (** Signal holding the current state of logic sensors. *) +end -val motors_state : t -> string OBus_property.r - (** String describing the current state of motors *) +module Range_finders : sig + val measures : t -> int array OBus_property.r + (** Signal holding the current range finders state *) -val turn : t -> angle : int -> velocity : int -> acceleration : int -> Types.move_result Lwt.t -val move : t -> distance : int -> velocity : int -> acceleration : int -> Types.move_result Lwt.t -val goto : t -> - x : int -> y : int -> - velocity : int -> - acceleration : int -> - mode : Types.goto_mode -> - bypass_distance : int -> Types.move_result Lwt.t + val get_calibration : t -> int -> int array Lwt.t + (** [get_calibration krobot num] returns the calibration of the + given range finder. *) -val stop_motors : t -> mode : Types.stop_mode -> unit Lwt.t - (** [stop_motorw t mode] stop the two motors. *) + val calibration_start : t -> int -> bool -> unit Lwt.t + val calibration_continue : t -> unit Lwt.t + val calibration_stop : t -> unit Lwt.t +end -val set_velocities : t -> - velocities : int * int -> - accelerations : int * int -> - duration : float -> unit Lwt.t - (** [set_velocities krobot ~velocities ~accelerations ~duration] set - the velocities of each motors, then wait for [duration] seconds - and stop the motors, unless [set_velocities] is called again - before. *) +module Grip : sig + val up : t -> unit Lwt.t + val down : t -> unit Lwt.t + val open_ : t -> unit Lwt.t + val close : t -> unit Lwt.t + val release : t -> unit Lwt.t +end -val inhibit_forward_until : t -> float OBus_property.rw - (** The date until which the robot is reallowed to move forward *) +module Claws : sig + val enable : t -> unit Lwt.t + val disable : t -> unit Lwt.t + val open_ : t -> unit Lwt.t + val close : t -> unit Lwt.t + val take : t -> unit Lwt.t +end -val inhibit_backward_until : t -> float OBus_property.rw +module Motors : sig + val state : t -> string OBus_property.r + (** String describing the current state of motors *) + + val turn : t -> angle : int -> velocity : int -> acceleration : int -> Types.move_result Lwt.t + val move : t -> distance : int -> velocity : int -> acceleration : int -> Types.move_result Lwt.t + val goto : t -> + x : int -> y : int -> + velocity : int -> + acceleration : int -> + mode : Types.goto_mode -> + bypass_distance : int -> Types.move_result Lwt.t + + val stop : t -> mode : Types.stop_mode -> unit Lwt.t + (** [stop_motorw t mode] stop the two motors. *) + + val set_velocities : t -> + velocities : int * int -> + accelerations : int * int -> + duration : float -> unit Lwt.t + (** [set_velocities krobot ~velocities ~accelerations ~duration] + set the velocities of each motors, then wait for [duration] + seconds and stop the motors, unless [set_velocities] is called + again before. *) + + val inhibit_forward_until : t -> float OBus_property.rw + (** The date until which the robot is reallowed to move forward *) + + val inhibit_backward_until : t -> float OBus_property.rw (** The date until which the robot is reallowed to move backward *) +end (** {6 Cards} *) module Card : sig + type card = [ `Interface | `Sensor | `Motor | `Monitoring ] + (** Type of a card *) + val name : card -> string (** Returns the name of a card *) diff --git a/info/control/myocamlbuild.ml b/info/control/myocamlbuild.ml index 82ccc6b..f9dce15 100644 --- a/info/control/myocamlbuild.ml +++ b/info/control/myocamlbuild.ml @@ -74,7 +74,7 @@ let targets = List.filter_opt (function (true, target) -> Some target | (false, (have_lwt_unix && have_obus && have_lwt_text, "clients/controller.best"); (have_lwt_unix && have_obus && have_sdl, "clients/joy_control.best"); (have_lwt_unix && have_obus && have_lwt_text, "clients/ax12_control.best"); - (have_lwt_unix && have_obus, "clients/check.best"); + (have_lwt_unix && have_obus && have_lwt_text, "clients/check.best"); (* Services *) (have_lwt_unix && have_obus, "services/hard_stop.best"); diff --git a/info/control/protocol/commands.ml b/info/control/protocol/commands.ml index 59577e1..1e9dc6a 100644 --- a/info/control/protocol/commands.ml +++ b/info/control/protocol/commands.ml @@ -169,7 +169,7 @@ struct let goto = register { name = "Goto"; - response = true; + response = false; command = PcInterface.cmd_ax12; request = Some PcInterface.ax12_goto; send = (arg4 diff --git a/info/control/protocol/krobot.obus b/info/control/protocol/krobot.obus index 7c3e775..9720c1e 100644 --- a/info/control/protocol/krobot.obus +++ b/info/control/protocol/krobot.obus @@ -23,6 +23,10 @@ interface "fr.krobot.Device.Power" { interface "fr.krobot.Device.Infrared" { property.r States : (int32 * int32) structure + + method GoLeft : () -> () + method GoRight : () -> () + method GoCenter : () -> () } interface "fr.krobot.Device.Gate" { @@ -80,7 +84,6 @@ interface "fr.krobot.Device.Servo" { } interface "fr.krobot.Device.AX12" { - method SetAX12 : (positions : (int32 * int32 * int32) structure array) -> () method GripUp : () -> () method GripDown : () -> () method GripOpen : () -> () diff --git a/info/control/services/hard_stop.ml b/info/control/services/hard_stop.ml index 9c4c623..27547c5 100644 --- a/info/control/services/hard_stop.ml +++ b/info/control/services/hard_stop.ml @@ -27,12 +27,12 @@ let handle_collide krobot sensors = join [ (if Util.front_collide sensors then begin lwt () = Lwt_log.notice "front collision detected, inhibit motors" in - OBus_property.set (Krobot.inhibit_forward_until krobot) duration + OBus_property.set (Krobot.Motors.inhibit_forward_until krobot) duration end else return ()); (if Util.back_collide sensors then begin lwt () = Lwt_log.notice "back collision detected, inhibit motors" in - OBus_property.set (Krobot.inhibit_backward_until krobot) duration + OBus_property.set (Krobot.Motors.inhibit_backward_until krobot) duration end else return ()); ] @@ -59,7 +59,7 @@ lwt () = lwt krobot = Krobot.create () in (* Stop motors as soon as possible: *) - lwt logic_sensors = OBus_property.monitor (Krobot.logic_sensors krobot) in + lwt logic_sensors = OBus_property.monitor (Krobot.Logic_sensors.states krobot) in Lwt_signal.always_notify_p (handle_collide krobot) logic_sensors; (* Continue the inhibition: *) diff --git a/info/control/tests/double_move.ml b/info/control/tests/double_move.ml index 005147c..05b18e8 100644 --- a/info/control/tests/double_move.ml +++ b/info/control/tests/double_move.ml @@ -16,10 +16,10 @@ let print_result = function lwt () = lwt krobot = Krobot.create () in print_endline "first move"; - lwt result = Krobot.move krobot ~distance:(-500) ~velocity:100 ~acceleration:200 in + lwt result = Krobot.Motors.move krobot ~distance:(-500) ~velocity:100 ~acceleration:200 in print_result result; print_endline "second move"; - lwt result = Krobot.move krobot ~distance:200 ~velocity:100 ~acceleration:200 in + lwt result = Krobot.Motors.move krobot ~distance:200 ~velocity:100 ~acceleration:200 in print_result result; print_endline "done"; return () diff --git a/info/control/tests/move.ml b/info/control/tests/move.ml index 47b4563..3bd0a09 100644 --- a/info/control/tests/move.ml +++ b/info/control/tests/move.ml @@ -37,12 +37,12 @@ let rec loop krobot state = | Some krobot -> lwt () = if angle <> 0 then - lwt _ = Krobot.turn krobot ~angle ~velocity ~acceleration in + lwt _ = Krobot.Motors.turn krobot ~angle ~velocity ~acceleration in return () else return () in - lwt _ = Krobot.move krobot ~distance ~velocity ~acceleration in + lwt _ = Krobot.Motors.move krobot ~distance ~velocity ~acceleration in return () | None -> return () diff --git a/info/control/tests/scan_infrared.ml b/info/control/tests/scan_infrared.ml index 574d130..03a0b45 100644 --- a/info/control/tests/scan_infrared.ml +++ b/info/control/tests/scan_infrared.ml @@ -18,22 +18,16 @@ let rec print krobot infrared = let delay = 1.5 -let action pos = { - Types.aa_id = 1; - Types.aa_position = pos; - Types.aa_velocity = 200; -} - lwt () = lwt krobot = Krobot.create () in let rec loop1 () = - lwt () = Krobot.set_ax12 krobot [action 250] in + lwt () = Krobot.Infrared.go_left krobot in lwt () = Lwt_unix.sleep delay in loop2 () and loop2 () = - lwt () = Krobot.set_ax12 krobot [action 750] in + lwt () = Krobot.Infrared.go_right krobot in lwt () = Lwt_unix.sleep delay in loop1 () in - lwt infrared = OBus_property.monitor (Krobot.infrared_states krobot) in + lwt infrared = OBus_property.monitor (Krobot.Infrared.states krobot) in join [loop1 (); print krobot infrared] diff --git a/info/control/tests/stop_and_restart.ml b/info/control/tests/stop_and_restart.ml index f04a368..ce35b12 100644 --- a/info/control/tests/stop_and_restart.ml +++ b/info/control/tests/stop_and_restart.ml @@ -12,12 +12,12 @@ open Lwt lwt () = lwt krobot = Krobot.create () in print_endline "moving forward"; - let t = Krobot.move krobot ~distance:1000 ~velocity:100 ~acceleration:200 in + let t = Krobot.Motors.move krobot ~distance:1000 ~velocity:100 ~acceleration:200 in lwt () = Lwt_unix.sleep 2.0 in print_endline "stopping motors"; - lwt () = Krobot.stop_motors krobot `Smooth in + lwt () = Krobot.Motors.stop krobot `Smooth in print_endline "waiting for trajectory to terminates"; lwt _ = t in print_endline "mobing backward"; - lwt _ = Krobot.move krobot ~distance:(-200) ~velocity:100 ~acceleration:200 in + lwt _ = Krobot.Motors.move krobot ~distance:(-200) ~velocity:100 ~acceleration:200 in return () diff --git a/info/control/tests/trajectories.ml b/info/control/tests/trajectories.ml index 9a2cd01..0e5a1c1 100644 --- a/info/control/tests/trajectories.ml +++ b/info/control/tests/trajectories.ml @@ -14,6 +14,6 @@ open Lwt lwt () = lwt krobot = Krobot.create () in - lwt _ = Krobot.move krobot 100 400 800 in - lwt _ = Krobot.move krobot 100 400 800 in + lwt _ = Krobot.Motors.move krobot 100 400 800 in + lwt _ = Krobot.Motors.move krobot 100 400 800 in return () hooks/post-receive -- krobot |