You can subscribe to this list here.
2009 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(13) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2010 |
Jan
(50) |
Feb
(137) |
Mar
(84) |
Apr
(36) |
May
(100) |
Jun
(5) |
Jul
|
Aug
(4) |
Sep
(13) |
Oct
(1) |
Nov
(4) |
Dec
(22) |
2011 |
Jan
(4) |
Feb
(9) |
Mar
(113) |
Apr
(76) |
May
(31) |
Jun
(19) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2012 |
Jan
(4) |
Feb
|
Mar
(2) |
Apr
(6) |
May
(19) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(4) |
Nov
|
Dec
|
2013 |
Jan
|
Feb
|
Mar
(2) |
Apr
(22) |
May
(6) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
2014 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Jérémie D. <Ba...@us...> - 2010-02-20 20:16:16
|
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 77d57ce86871b5b3a5a8f9557efd383a9ebc9def (commit) from 8822a5899f69e2335d351079b1f6f2e997f76260 (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 77d57ce86871b5b3a5a8f9557efd383a9ebc9def Author: Jérémie Dimino <je...@di...> Date: Sat Feb 20 21:15:54 2010 +0100 add the test command ----------------------------------------------------------------------- Changes: diff --git a/PC_Mainboard/clients/script.ml b/PC_Mainboard/clients/script.ml index 17bf780..8b1673d 100644 --- a/PC_Mainboard/clients/script.ml +++ b/PC_Mainboard/clients/script.ml @@ -49,6 +49,8 @@ let commands = [ args = [("card", Arg_keyword ["interface"; "sensor"; "motor"])] }; { name = "reset"; args = [("card", Arg_keyword ["interface"; "sensor"; "motor"])] }; + { name = "test"; + args = [("card", Arg_keyword ["interface"; "sensor"; "motor"])] }; { name = "get-calibration"; args = [] }; { name = "calibration-start"; @@ -196,6 +198,13 @@ let exec krobot line = | "motor" -> `Motor | "sensor" -> `Sensor | _ -> failwith "Script.exec: invalid card") + | "test" -> + Krobot.Card.test krobot + (match arg_string "card" "" with + | "interface" -> `Interface + | "motor" -> `Motor + | "sensor" -> `Sensor + | _ -> failwith "Script.exec: invalid card") | "get-calibration" -> lwt l = Lwt_list.map_p (Krobot.get_calibration krobot) [0; 1; 2; 3; 4; 5; 6; 7] in let buffer = Buffer.create 1024 in diff --git a/PC_Mainboard/driver/commands.ml b/PC_Mainboard/driver/commands.ml index 043c955..e29aaf6 100644 --- a/PC_Mainboard/driver/commands.ml +++ b/PC_Mainboard/driver/commands.ml @@ -32,6 +32,9 @@ let bootloader card = let reset card = Card.send_command card Protocol.cmd_reset "" +let test card = + Card.send_command card Protocol.cmd_test "" + module Compass = struct let get card = diff --git a/PC_Mainboard/driver/commands.mli b/PC_Mainboard/driver/commands.mli index 0c7c5b8..8e2028e 100644 --- a/PC_Mainboard/driver/commands.mli +++ b/PC_Mainboard/driver/commands.mli @@ -15,6 +15,7 @@ val get_firmware_build : Card.t -> string Lwt.t val get_board_info : Card.t -> string Lwt.t val bootloader : Card.t -> unit Lwt.t val reset : Card.t -> unit Lwt.t +val test : Card.t -> unit Lwt.t module Compass : sig val get : Card.t -> int Lwt.t diff --git a/PC_Mainboard/driver/driver.ml b/PC_Mainboard/driver/driver.ml index 71e8a5b..ad4f936 100644 --- a/PC_Mainboard/driver/driver.ml +++ b/PC_Mainboard/driver/driver.ml @@ -536,6 +536,9 @@ struct OL_method Reset : unit = fun dev -> Commands.reset (get_card dev) + OL_method Test : unit = fun dev -> + Commands.test (get_card dev) + OL_signal StateChanged : Types.card_state let make name card path = diff --git a/PC_Mainboard/lib_krobot/krobot.ml b/PC_Mainboard/lib_krobot/krobot.ml index 3a83fc5..ed460f0 100644 --- a/PC_Mainboard/lib_krobot/krobot.ml +++ b/PC_Mainboard/lib_krobot/krobot.ml @@ -229,6 +229,7 @@ struct OP_method GetBoardInfo : string OP_method Bootloader : unit OP_method Reset : unit + OP_method Test : unit let proxy krobot card = OBus_proxy.make krobot.peer @@ -241,4 +242,5 @@ struct let get_board_info krobot card = get_board_info (proxy krobot card) let bootloader krobot card = bootloader (proxy krobot card) let reset krobot card = reset (proxy krobot card) + let test krobot card = test (proxy krobot card) end diff --git a/PC_Mainboard/lib_krobot/krobot.mli b/PC_Mainboard/lib_krobot/krobot.mli index e8bce6d..18aba87 100644 --- a/PC_Mainboard/lib_krobot/krobot.mli +++ b/PC_Mainboard/lib_krobot/krobot.mli @@ -123,4 +123,5 @@ module Card : sig val get_firmware_build : t -> card -> string Lwt.t val get_board_info : t -> card -> string Lwt.t val reset : t -> card -> unit Lwt.t + val test : t -> card -> unit Lwt.t end hooks/post-receive -- krobot |
From: Jérémie D. <Ba...@us...> - 2010-02-20 19:50:12
|
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 8822a5899f69e2335d351079b1f6f2e997f76260 (commit) from e3602ee46fe8c73cd28897123824e17c6e3aff69 (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 8822a5899f69e2335d351079b1f6f2e997f76260 Author: Jérémie Dimino <je...@di...> Date: Sat Feb 20 20:49:44 2010 +0100 add all ax12 commands ----------------------------------------------------------------------- Changes: diff --git a/PC_Mainboard/clients/script.ml b/PC_Mainboard/clients/script.ml index 2453320..17bf780 100644 --- a/PC_Mainboard/clients/script.ml +++ b/PC_Mainboard/clients/script.ml @@ -59,6 +59,30 @@ let commands = [ args = [] }; { name = "ax12-goto"; args = [("id", Arg_int); ("pos", Arg_int); ("speed", Arg_int)] }; + { name = "ax12-ping"; + args = [("id", Arg_int); ("timeout", Arg_int)] }; + { name = "ax12-read8"; + args = [("id", Arg_int); ("reg", Arg_int); ("timeout", Arg_int)] }; + { name = "ax12-read16"; + args = [("id", Arg_int); ("reg", Arg_int); ("timeout", Arg_int)] }; + { name = "ax12-write8"; + args = [("id", Arg_int); ("reg", Arg_int); ("value", Arg_int)] }; + { name = "ax12-write16"; + args = [("id", Arg_int); ("reg", Arg_int); ("value", Arg_int)] }; + { name = "ax12-get-pos"; + args = [("id", Arg_int); ("timeout", Arg_int)] }; + { name = "ax12-get-speed"; + args = [("id", Arg_int); ("timeout", Arg_int)] }; + { name = "ax12-get-load"; + args = [("id", Arg_int); ("timeout", Arg_int)] }; + { name = "ax12-stats"; + args = [("id", Arg_int); ("timeout", Arg_int)] }; + { name = "ax12-write-reg8"; + args = [("id", Arg_int); ("reg", Arg_int); ("value", Arg_int)] }; + { name = "ax12-write-reg16"; + args = [("id", Arg_int); ("reg", Arg_int); ("value", Arg_int)] }; + { name = "ax12-action"; + args = [("id", Arg_int)] }; ] let set_of_list l = List.fold_left (fun set x -> TextSet.add x set) TextSet.empty l @@ -198,7 +222,51 @@ let exec krobot line = | "calibration-stop" -> Krobot.calibration_stop krobot | "ax12-goto" -> - Krobot.ax12_goto krobot ~id:(arg_int "id" 0) ~pos:(arg_int "pos" 0) ~speed:(arg_int "speed" 0) + Krobot.AX12.goto krobot ~id:(arg_int "id" 0) ~pos:(arg_int "pos" 0) ~speed:(arg_int "speed" 0) + | "ax12-ping" -> + lwt n = Krobot.AX12.ping krobot ~id:(arg_int "id" 0) ~timeout:(arg_int "timeout" 100) in + Log.notice_f "ax12 ping result: %d" n + | "ax12-read8" -> + lwt n = Krobot.AX12.read8 krobot ~id:(arg_int "id" 0) ~reg:(arg_int "reg" 0) ~timeout:(arg_int "timeout" 100) in + Log.notice_f "ax12 read8 result: %d" n + | "ax12-read16" -> + lwt n = Krobot.AX12.read16 krobot ~id:(arg_int "id" 0) ~reg:(arg_int "reg" 0) ~timeout:(arg_int "timeout" 100) in + Log.notice_f "ax12 read8 result: %d" n + | "ax12-write8" -> + Krobot.AX12.write8 krobot ~id:(arg_int "id" 0) ~reg:(arg_int "reg" 0) ~value:(arg_int "value" 0) + | "ax12-write16" -> + Krobot.AX12.write16 krobot ~id:(arg_int "id" 0) ~reg:(arg_int "reg" 0) ~value:(arg_int "value" 0) + | "ax12-get-pos" -> + lwt n = Krobot.AX12.get_pos krobot ~id:(arg_int "id" 0) ~timeout:(arg_int "timeout" 100) in + Log.notice_f "ax12 position: %d" n + | "ax12-get-speed" -> + lwt n = Krobot.AX12.get_speed krobot ~id:(arg_int "id" 0) ~timeout:(arg_int "timeout" 100) in + Log.notice_f "ax12 speed: %d" n + | "ax12-get-load" -> + lwt n = Krobot.AX12.get_load krobot ~id:(arg_int "id" 0) ~timeout:(arg_int "timeout" 100) in + Log.notice_f "ax12 load: %d" n + | "ax12-stats" -> + lwt stats = Krobot.AX12.stats krobot ~id:(arg_int "id" 0) ~timeout:(arg_int "timeout" 100) in + Log.notice_f "ax12 position = %d\n\ + ax12 speed = %d\n\ + ax12 torque = %d\n\ + ax12 voltage = %d\n\ + ax12 temperature = %d\n\ + ax12 cw-angle-limit = %d\n\ + ax12 ccw-angle-limit = %d\n" + stats.Types.ax12_position + stats.Types.ax12_speed + stats.Types.ax12_torque + stats.Types.ax12_voltage + stats.Types.ax12_temperature + stats.Types.ax12_cw_angle_limit + stats.Types.ax12_ccw_angle_limit + | "ax12-write-reg8" -> + Krobot.AX12.write_reg8 krobot ~id:(arg_int "id" 0) ~reg:(arg_int "reg" 0) ~value:(arg_int "value" 0) + | "ax12-write-reg16" -> + Krobot.AX12.write_reg16 krobot ~id:(arg_int "id" 0) ~reg:(arg_int "reg" 0) ~value:(arg_int "value" 0) + | "ax12-action" -> + Krobot.AX12.action krobot ~id:(arg_int "id" 0) | _ -> Log.error_f "unknown command %S" action with diff --git a/PC_Mainboard/common/types.ml b/PC_Mainboard/common/types.ml index 98efd31..60ab4ce 100644 --- a/PC_Mainboard/common/types.ml +++ b/PC_Mainboard/common/types.ml @@ -40,3 +40,13 @@ let obus_goto_mode = OBus_type.mapping obus_int [(`Straight, 0); (`Curve_right, 1); (`Curve_left, 2)] + +type ax12_stats = { + ax12_position : int; + ax12_speed : int; + ax12_torque : int; + ax12_voltage : int; + ax12_temperature : int; + ax12_cw_angle_limit : int; + ax12_ccw_angle_limit : int; +} with obus diff --git a/PC_Mainboard/common/types.mli b/PC_Mainboard/common/types.mli index 3095cbc..164f85a 100644 --- a/PC_Mainboard/common/types.mli +++ b/PC_Mainboard/common/types.mli @@ -30,3 +30,13 @@ type card_state = [ `Present | `Absent ] with obus(basic) type goto_mode = [ `Straight | `Curve_right | `Curve_left ] with obus(basic) (** Form of the trajectory for the goto command *) + +type ax12_stats = { + ax12_position : int; + ax12_speed : int; + ax12_torque : int; + ax12_voltage : int; + ax12_temperature : int; + ax12_cw_angle_limit : int; + ax12_ccw_angle_limit : int; +} with obus(sequence) diff --git a/PC_Mainboard/driver/commands.ml b/PC_Mainboard/driver/commands.ml index 49b16c9..043c955 100644 --- a/PC_Mainboard/driver/commands.ml +++ b/PC_Mainboard/driver/commands.ml @@ -8,6 +8,7 @@ *) open Lwt +open Types let string_of_azt data = try @@ -40,7 +41,7 @@ end module AX12 = struct - let goto card ~id ~pos ~speed = + let goto card id pos speed = let data = Card.make_buffer () in RW.set_uint8 data 0 Protocol.ax12_goto; RW.set_uint8 data 1 id; @@ -48,6 +49,119 @@ struct RW.set_uint16 data 4 speed; lwt _ = Card.send_request card Protocol.cmd_ax12 data in return () + + let ping card id timeout = + let data = Card.make_buffer () in + RW.set_uint8 data 0 Protocol.ax12_ping; + RW.set_uint8 data 1 id; + RW.set_uint8 data 2 timeout; + lwt data = Card.send_request card Protocol.cmd_ax12 data in + return (RW.get_uint8 data 0) + + let read8 card id reg timeout = + let data = Card.make_buffer () in + RW.set_uint8 data 0 Protocol.ax12_read; + RW.set_uint8 data 1 id; + RW.set_uint8 data 2 reg; + RW.set_uint8 data 3 0; + RW.set_uint8 data 4 timeout; + lwt data = Card.send_request card Protocol.cmd_ax12 data in + return (RW.get_uint8 data 0) + + let read16 card id reg timeout = + let data = Card.make_buffer () in + RW.set_uint8 data 0 Protocol.ax12_read; + RW.set_uint8 data 1 id; + RW.set_uint8 data 2 reg; + RW.set_uint8 data 3 1; + RW.set_uint8 data 4 timeout; + lwt data = Card.send_request card Protocol.cmd_ax12 data in + return (RW.get_uint16 data 0) + + let write8 card id reg value = + let data = Card.make_buffer () in + RW.set_uint8 data 0 Protocol.ax12_write; + RW.set_uint8 data 1 id; + RW.set_uint8 data 2 reg; + RW.set_uint8 data 3 0; + RW.set_uint8 data 4 value; + lwt data = Card.send_request card Protocol.cmd_ax12 data in + return () + + let write16 card id reg value = + let data = Card.make_buffer () in + RW.set_uint8 data 0 Protocol.ax12_write; + RW.set_uint8 data 1 id; + RW.set_uint8 data 2 reg; + RW.set_uint8 data 3 0; + RW.set_uint16 data 4 value; + lwt data = Card.send_request card Protocol.cmd_ax12 data in + return () + + let get_pos card id timeout = + let data = Card.make_buffer () in + RW.set_uint8 data 0 Protocol.ax12_get_pos; + RW.set_uint8 data 1 id; + RW.set_uint8 data 2 timeout; + lwt data = Card.send_request card Protocol.cmd_ax12 data in + return (RW.get_uint16 data 0) + + let get_speed card id timeout = + let data = Card.make_buffer () in + RW.set_uint8 data 0 Protocol.ax12_get_speed; + RW.set_uint8 data 1 id; + RW.set_uint8 data 2 timeout; + lwt data = Card.send_request card Protocol.cmd_ax12 data in + return (RW.get_uint16 data 0) + + let get_load card id timeout = + let data = Card.make_buffer () in + RW.set_uint8 data 0 Protocol.ax12_get_load; + RW.set_uint8 data 1 id; + RW.set_uint8 data 2 timeout; + lwt data = Card.send_request card Protocol.cmd_ax12 data in + return (RW.get_uint16 data 0) + + let stats card id timeout = + let data = Card.make_buffer () in + RW.set_uint8 data 0 Protocol.ax12_get_stats; + RW.set_uint8 data 1 id; + RW.set_uint8 data 2 timeout; + lwt data = Card.send_request card Protocol.cmd_ax12 data in + return { ax12_position = RW.get_int16 data 0; + ax12_speed = RW.get_int16 data 2; + ax12_torque = RW.get_int16 data 4; + ax12_voltage = RW.get_uint8 data 6; + ax12_temperature = RW.get_uint8 data 7; + ax12_cw_angle_limit = RW.get_int16 data 8; + ax12_ccw_angle_limit = RW.get_int16 data 10 } + + let write_reg8 card id reg value = + let data = String.create 5 in + RW.set_uint8 data 0 Protocol.ax12_write_reg; + RW.set_uint8 data 1 id; + RW.set_uint8 data 2 reg; + RW.set_uint8 data 3 0; + RW.set_uint8 data 4 value; + lwt _ = Card.send_request card Protocol.cmd_ax12 data in + return () + + let write_reg16 card id reg value = + let data = String.create 6 in + RW.set_uint8 data 0 Protocol.ax12_write_reg; + RW.set_uint8 data 1 id; + RW.set_uint8 data 2 reg; + RW.set_uint8 data 3 1; + RW.set_int16 data 4 value; + lwt _ = Card.send_request card Protocol.cmd_ax12 data in + return () + + let action card id = + let data = String.create 2 in + RW.set_uint8 data 0 Protocol.ax12_action; + RW.set_uint8 data 1 id; + lwt _ = Card.send_request card Protocol.cmd_ax12 data in + return () end module Logic_sensors = diff --git a/PC_Mainboard/driver/commands.mli b/PC_Mainboard/driver/commands.mli index cce2301..0c7c5b8 100644 --- a/PC_Mainboard/driver/commands.mli +++ b/PC_Mainboard/driver/commands.mli @@ -21,7 +21,19 @@ module Compass : sig end module AX12 : sig - val goto : Card.t -> id : int -> pos : int -> speed : int -> unit Lwt.t + val goto : Card.t -> int -> int -> int -> unit Lwt.t + val ping : Card.t -> int -> int -> int Lwt.t + val read8 : Card.t -> int -> int -> int -> int Lwt.t + val read16 : Card.t -> int -> int -> int -> int Lwt.t + val write8 : Card.t -> int -> int -> int -> unit Lwt.t + val write16 : Card.t -> int -> int -> int -> unit Lwt.t + val get_pos : Card.t -> int -> int -> int Lwt.t + val get_speed : Card.t -> int -> int -> int Lwt.t + val get_load : Card.t -> int -> int -> int Lwt.t + val stats : Card.t -> int -> int -> Types.ax12_stats Lwt.t + val write_reg8 : Card.t -> int -> int -> int -> unit Lwt.t + val write_reg16 : Card.t -> int -> int -> int -> unit Lwt.t + val action : Card.t -> int -> unit Lwt.t end module Logic_sensors : sig diff --git a/PC_Mainboard/driver/driver.ml b/PC_Mainboard/driver/driver.ml index d354076..71e8a5b 100644 --- a/PC_Mainboard/driver/driver.ml +++ b/PC_Mainboard/driver/driver.ml @@ -76,9 +76,21 @@ struct include OBus.MakeInterface(struct let name = "fr.krobot.Device.AX12" end) - OL_method AX12Goto : int -> int -> int -> unit = - fun dev id pos speed -> - Commands.AX12.goto dev.card id pos speed + let wrap f dev = f dev.card + + OL_method Goto : int -> int -> int -> unit = wrap Commands.AX12.goto + OL_method Ping : int -> int -> int = wrap Commands.AX12.ping + OL_method Read8 : int -> int -> int -> int = wrap Commands.AX12.read8 + OL_method Read16 : int -> int -> int -> int = wrap Commands.AX12.read16 + OL_method Write8 : int -> int -> int -> unit = wrap Commands.AX12.write8 + OL_method Write16 : int -> int -> int -> unit = wrap Commands.AX12.write16 + OL_method GetPos : int -> int -> int = wrap Commands.AX12.get_pos + OL_method GetSpeed : int -> int -> int = wrap Commands.AX12.get_speed + OL_method GetLoad : int -> int -> int = wrap Commands.AX12.get_load + OL_method Stats : int -> int -> Types.ax12_stats = wrap Commands.AX12.stats + OL_method WriteReg8 : int -> int -> int -> unit = wrap Commands.AX12.write_reg8 + OL_method WriteReg16 : int -> int -> int -> unit = wrap Commands.AX12.write_reg16 + OL_method Action : int -> unit = wrap Commands.AX12.action let make card path = return { diff --git a/PC_Mainboard/lib_krobot/krobot.ml b/PC_Mainboard/lib_krobot/krobot.ml index 67ab2a0..3a83fc5 100644 --- a/PC_Mainboard/lib_krobot/krobot.ml +++ b/PC_Mainboard/lib_krobot/krobot.ml @@ -173,9 +173,23 @@ OP_method CalibrationContinue : unit | AX12 | +-----------------------------------------------------------------+ *) -include MakeDevice(struct let name = "AX12" end) - -OP_method AX12Goto : id : int -> pos : int -> speed : int -> unit +module AX12 = +struct + include MakeDevice(struct let name = "AX12" end) + OP_method Goto : id : int -> pos : int -> speed : int -> unit + OP_method Ping : id : int -> timeout : int -> int + OP_method Read8 : id : int -> reg : int -> timeout : int -> int + OP_method Read16 : id : int -> reg : int -> timeout : int -> int + OP_method Write8 : id : int -> reg : int -> value : int -> unit + OP_method Write16 : id : int -> reg : int -> value : int -> unit + OP_method GetPos : id : int -> timeout : int -> int + OP_method GetSpeed : id : int -> timeout : int -> int + OP_method GetLoad : id : int -> timeout : int -> int + OP_method Stats : id : int -> timeout : int -> Types.ax12_stats + OP_method WriteReg8 : id : int -> reg : int -> value : int -> unit + OP_method WriteReg16 : id : int -> reg : int -> value : int -> unit + OP_method Action : id : int -> unit +end (* +-----------------------------------------------------------------+ | Motors | diff --git a/PC_Mainboard/lib_krobot/krobot.mli b/PC_Mainboard/lib_krobot/krobot.mli index 694bae6..e8bce6d 100644 --- a/PC_Mainboard/lib_krobot/krobot.mli +++ b/PC_Mainboard/lib_krobot/krobot.mli @@ -61,7 +61,21 @@ val calibration_stop : t -> unit Lwt.t (** {6 Manipulation of AX12s} *) -val ax12_goto : t -> id : int -> pos : int -> speed : int -> unit Lwt.t +module AX12 : sig + val goto : t -> id : int -> pos : int -> speed : int -> unit Lwt.t + val ping : t -> id : int -> timeout : int -> int Lwt.t + val read8 : t -> id : int -> reg : int -> timeout : int -> int Lwt.t + val read16 : t -> id : int -> reg : int -> timeout : int -> int Lwt.t + val write8 : t -> id : int -> reg : int -> value : int -> unit Lwt.t + val write16 : t -> id : int -> reg : int -> value : int -> unit Lwt.t + val get_pos : t -> id : int -> timeout : int -> int Lwt.t + val get_speed : t -> id : int -> timeout : int -> int Lwt.t + val get_load : t -> id : int -> timeout : int -> int Lwt.t + val stats : t -> id : int -> timeout : int -> Types.ax12_stats Lwt.t + val write_reg8 : t -> id : int -> reg : int -> value : int -> unit Lwt.t + val write_reg16 : t -> id : int -> reg : int -> value : int -> unit Lwt.t + val action : t -> id : int -> unit Lwt.t +end (** {6 Motors} *) hooks/post-receive -- krobot |
From: Jérémie D. <Ba...@us...> - 2010-02-20 18:27:00
|
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 e3602ee46fe8c73cd28897123824e17c6e3aff69 (commit) via 5196fc4b5d9de11ad4a319b1b060796361efa92f (commit) from 2cfb7162690b09e27ef50cd5b8da74b83b98a4ce (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 e3602ee46fe8c73cd28897123824e17c6e3aff69 Author: Jérémie Dimino <je...@di...> Date: Sat Feb 20 19:26:36 2010 +0100 [controller] fix default value for goto mode commit 5196fc4b5d9de11ad4a319b1b060796361efa92f Author: Jérémie Dimino <je...@di...> Date: Sat Feb 20 19:26:09 2010 +0100 [commands] fix forward/backward ----------------------------------------------------------------------- Changes: diff --git a/PC_Mainboard/clients/script.ml b/PC_Mainboard/clients/script.ml index 0591871..2453320 100644 --- a/PC_Mainboard/clients/script.ml +++ b/PC_Mainboard/clients/script.ml @@ -139,7 +139,7 @@ let exec krobot line = | "goto" -> move (Krobot.goto krobot ~x:(arg_int "x" 0) ~y:(arg_int "y" 0) ~speed:(arg_int "speed" 400) ?acc:(arg_int "acc" 800) - ~mode:(match arg_string "mode" "" with + ~mode:(match arg_string "mode" "straight" with | "straight" -> `Straight | "curve-left" -> `Curve_left | "curve-right" -> `Curve_right diff --git a/PC_Mainboard/driver/commands.ml b/PC_Mainboard/driver/commands.ml index 81a2ab8..49b16c9 100644 --- a/PC_Mainboard/driver/commands.ml +++ b/PC_Mainboard/driver/commands.ml @@ -110,9 +110,9 @@ struct let move card ~dist ~speed ~acc = if dist < 0 then - backend Protocol.traj_forward card (-dist) speed acc + backend Protocol.traj_backward card (-dist) speed acc else - backend Protocol.traj_backward card dist speed acc + backend Protocol.traj_forward card dist speed acc let turn card ~angle ~speed ~acc = if angle < 0 then hooks/post-receive -- krobot |
From: Jérémie D. <Ba...@us...> - 2010-02-20 18:13:56
|
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 2cfb7162690b09e27ef50cd5b8da74b83b98a4ce (commit) from 51956ee3c6f426691e6be27179a4b06f37cd7a5e (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 2cfb7162690b09e27ef50cd5b8da74b83b98a4ce Author: Jérémie Dimino <je...@di...> Date: Sat Feb 20 19:13:18 2010 +0100 [send-firmware] reset the device after flashing it ----------------------------------------------------------------------- Changes: diff --git a/PC_Mainboard/card_tools/send_firmware.ml b/PC_Mainboard/card_tools/send_firmware.ml index 1dedd01..443036a 100644 --- a/PC_Mainboard/card_tools/send_firmware.ml +++ b/PC_Mainboard/card_tools/send_firmware.ml @@ -41,6 +41,7 @@ let do_flash force filename = lwt () = printf "Flash erased\n" in lwt () = Bootloader.write_flash k ~address memory address length in lwt () = printf "Flashing completed\n" in + lwt () = Bootloader.close k in return () let _ = hooks/post-receive -- krobot |
From: Jérémie D. <Ba...@us...> - 2010-02-20 17:54:01
|
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 51956ee3c6f426691e6be27179a4b06f37cd7a5e (commit) from 0a4a8974690761898757827e31075adc80eb9be0 (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 51956ee3c6f426691e6be27179a4b06f37cd7a5e Author: Jérémie Dimino <je...@di...> Date: Sat Feb 20 18:53:38 2010 +0100 [controller] add the ax12-goto command ----------------------------------------------------------------------- Changes: diff --git a/PC_Mainboard/clients/script.ml b/PC_Mainboard/clients/script.ml index 94d8d3d..0591871 100644 --- a/PC_Mainboard/clients/script.ml +++ b/PC_Mainboard/clients/script.ml @@ -57,6 +57,8 @@ let commands = [ args = [] }; { name = "calibration-continue"; args = [] }; + { name = "ax12-goto"; + args = [("id", Arg_int); ("pos", Arg_int); ("speed", Arg_int)] }; ] let set_of_list l = List.fold_left (fun set x -> TextSet.add x set) TextSet.empty l @@ -195,6 +197,8 @@ let exec krobot line = Krobot.calibration_continue krobot | "calibration-stop" -> Krobot.calibration_stop krobot + | "ax12-goto" -> + Krobot.ax12_goto krobot ~id:(arg_int "id" 0) ~pos:(arg_int "pos" 0) ~speed:(arg_int "speed" 0) | _ -> Log.error_f "unknown command %S" action with hooks/post-receive -- krobot |
From: Jérémie D. <Ba...@us...> - 2010-02-20 17:47:13
|
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 0a4a8974690761898757827e31075adc80eb9be0 (commit) from f82b9539b1b2cc4537a68d5b77a39b78c5cbb2fb (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 0a4a8974690761898757827e31075adc80eb9be0 Author: Jérémie Dimino <je...@di...> Date: Sat Feb 20 18:46:19 2010 +0100 [controller] mini rendering enhancement ----------------------------------------------------------------------- Changes: diff --git a/PC_Mainboard/clients/controller.ml b/PC_Mainboard/clients/controller.ml index 5b940f3..5d43d37 100644 --- a/PC_Mainboard/clients/controller.ml +++ b/PC_Mainboard/clients/controller.ml @@ -32,6 +32,7 @@ let rec draw (inhibited_forward_until, inhibited_backward_until), (state_interface, state_sensor, state_motor))) = Lwt_mutex.with_lock drawer_mutex begin fun () -> + lwt () = Lwt_main.fast_yield () in if Lwt_mutex.is_empty drawer_mutex then begin (* Redraw the screen only if there is no other thread waiting to do it *) hooks/post-receive -- krobot |
From: Jérémie D. <Ba...@us...> - 2010-02-20 14:21:44
|
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 f82b9539b1b2cc4537a68d5b77a39b78c5cbb2fb (commit) via 3c36a3407c82006185997e92c6135fc4b78564cf (commit) from 530d98a475d5fd24a8a5aa9a04a3ae293cf0a022 (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 f82b9539b1b2cc4537a68d5b77a39b78c5cbb2fb Author: Jérémie Dimino <je...@di...> Date: Sat Feb 20 15:21:18 2010 +0100 add the goto command commit 3c36a3407c82006185997e92c6135fc4b78564cf Author: Jérémie Dimino <je...@di...> Date: Sat Feb 20 14:41:49 2010 +0100 Better movements when using the joystick ----------------------------------------------------------------------- Changes: diff --git a/PC_Mainboard/clients/joy_control.ml b/PC_Mainboard/clients/joy_control.ml index 3d7d355..42b9b4d 100644 --- a/PC_Mainboard/clients/joy_control.ml +++ b/PC_Mainboard/clients/joy_control.ml @@ -40,8 +40,10 @@ type button = | ButtonRAxis type event = - | JoyRAxis of int - | JoyLAxis of int + | JoyRAxisV of int + | JoyLAxisV of int + | JoyRAxisH of int + | JoyLAxisH of int | JoyButtonPressed of button | JoyButtonReleased of button | KeyPressed of Sdlkey.t @@ -51,8 +53,10 @@ type event = | int --> button | +-----------------------------------------------------------------+ *) -let raxis = 3 -let laxis = 1 +let raxis_v = 3 +let raxis_h = 2 +let laxis_v = 1 +let laxis_h = 0 let axis_min = -32768 let axis_max = 32767 @@ -95,14 +99,20 @@ let child_loop pipe joy = Sdl.quit (); exit 0 end - | JOYAXISMOTION { jae_axis = axis; jae_value = value } when axis = raxis || axis = laxis -> + | JOYAXISMOTION { jae_axis = axis; jae_value = value } -> let value = 100 - ((value - axis_min) * 200 / (axis_max - axis_min)) in if value <> axis_state.(axis) then begin axis_state.(axis) <- value; - if axis = laxis then - send (JoyLAxis value) + if axis = laxis_h then + send (JoyLAxisH value) + else if axis = laxis_v then + send (JoyLAxisV value) + else if axis = raxis_h then + send (JoyRAxisH value) + else if axis = raxis_v then + send (JoyRAxisV value) else - send (JoyRAxis value) + () end | JOYBUTTONUP { jbe_button = button } -> send (JoyButtonPressed(button_of_num button)) @@ -116,7 +126,8 @@ let child_loop pipe joy = | Handling events (in the parent process) | +-----------------------------------------------------------------+ *) -let axis_coef = 8 +let axis_coef = 6 +let axis_coef_turn = 4 let acceleration = 800 let try_call action f = @@ -139,34 +150,46 @@ let parent_loop krobot pipe = let rstop = ref false and lstop = ref false in let rthread = ref (return ()) and lthread = ref (return ()) in let rabort_wakener = ref None and labort_wakener = ref None in + let raxis_h = ref 0 + and raxis_v = ref 0 + and laxis_h = ref 0 + and laxis_v = ref 0 in + let set_speeds () = + begin match !labort_wakener with + | None -> () + | Some w -> wakeup_exn w Exit + end; + begin match !rabort_wakener with + | None -> () + | Some w -> wakeup_exn w Exit + end; + let waiter, wakener = Lwt.wait () in + labort_wakener := Some wakener; + lthread := set_speed "set-speed-left" krobot `Left (!laxis_v * axis_coef - !raxis_h * axis_coef_turn) waiter; + let waiter, wakener = Lwt.wait () in + rabort_wakener := Some wakener; + rthread := set_speed "set-speed-right" krobot `Right (!laxis_v * axis_coef + !raxis_h * axis_coef_turn) waiter + in let rec loop () = Lwt_io.read_value pipe >>= function | KeyPressed KEY_ESCAPE -> return () - | JoyRAxis n -> - if not !rstop then begin - begin match !rabort_wakener with - | None -> () - | Some w -> wakeup_exn w Exit - end; - let waiter, wakener = Lwt.wait () in - rabort_wakener := Some wakener; - rthread := set_speed "set-speed-right" krobot `Right (n * axis_coef) waiter; - loop () - end else - loop () - | JoyLAxis n -> - if not !lstop then begin - begin match !labort_wakener with - | None -> () - | Some w -> wakeup_exn w Exit - end; - let waiter, wakener = Lwt.wait () in - labort_wakener := Some wakener; - lthread := set_speed "set-speed-left" krobot `Left (n * axis_coef) waiter; - loop () - end else - loop () + | JoyLAxisV n -> + laxis_v := n; + set_speeds (); + loop () + | JoyLAxisH n -> + laxis_h := n; + set_speeds (); + loop () + | JoyRAxisV n -> + raxis_v := n; + set_speeds (); + loop () + | JoyRAxisH n -> + raxis_h := n; + set_speeds (); + loop () | JoyButtonPressed ButtonL2 -> lstop := true; cancel !lthread; diff --git a/PC_Mainboard/clients/script.ml b/PC_Mainboard/clients/script.ml index 9c3f558..94d8d3d 100644 --- a/PC_Mainboard/clients/script.ml +++ b/PC_Mainboard/clients/script.ml @@ -30,6 +30,10 @@ let commands = [ args = [("dist", Arg_int); ("speed", Arg_int); ("acc", Arg_int)] }; { name = "backward"; args = [("dist", Arg_int); ("speed", Arg_int); ("acc", Arg_int)] }; + { name = "goto"; + args = [("x", Arg_int); ("y", Arg_int); ("speed", Arg_int); ("acc", Arg_int); + ("mode", Arg_keyword ["straight"; "curve-left"; "curve-right"]); + ("bypass-dist", Arg_int)] }; { name = "left"; args = [("angle", Arg_int); ("speed", Arg_int); ("acc", Arg_int)] }; { name = "right"; @@ -130,6 +134,15 @@ let exec krobot line = move (Krobot.turn krobot ~angle:(arg_int "angle" 100) ~speed:(arg_int "speed" 400) ?acc:(arg_int "acc" 800)) | "right" -> move (Krobot.turn krobot ~angle:(-(arg_int "angle" 100)) ~speed:(arg_int "speed" 400) ?acc:(arg_int "acc" 800)) + | "goto" -> + move (Krobot.goto krobot + ~x:(arg_int "x" 0) ~y:(arg_int "y" 0) ~speed:(arg_int "speed" 400) ?acc:(arg_int "acc" 800) + ~mode:(match arg_string "mode" "" with + | "straight" -> `Straight + | "curve-left" -> `Curve_left + | "curve-right" -> `Curve_right + | _ -> failwith "Script.exec: invalid goto mode") + ~bypass_dist:(arg_int "bypass-dist" 0)) | "stop-motors" -> Krobot.stop_motors krobot ~motor:(motor_of_string (arg_string "motor" "both")) diff --git a/PC_Mainboard/common/types.ml b/PC_Mainboard/common/types.ml index 0a4f80a..98efd31 100644 --- a/PC_Mainboard/common/types.ml +++ b/PC_Mainboard/common/types.ml @@ -33,3 +33,10 @@ type card_state = [ `Present | `Absent ] let obus_card_state = OBus_type.mapping obus_int [(`Present, 0); (`Absent, 1)] + +type goto_mode = [ `Straight | `Curve_right | `Curve_left ] + +let obus_goto_mode = OBus_type.mapping obus_int + [(`Straight, 0); + (`Curve_right, 1); + (`Curve_left, 2)] diff --git a/PC_Mainboard/common/types.mli b/PC_Mainboard/common/types.mli index 53a3511..3095cbc 100644 --- a/PC_Mainboard/common/types.mli +++ b/PC_Mainboard/common/types.mli @@ -27,3 +27,6 @@ type stop_mode = [ `Off | `Abrupt | `Smooth ] with obus(basic) type card_state = [ `Present | `Absent ] with obus(basic) (** State of a card *) + +type goto_mode = [ `Straight | `Curve_right | `Curve_left ] with obus(basic) + (** Form of the trajectory for the goto command *) diff --git a/PC_Mainboard/driver/commands.ml b/PC_Mainboard/driver/commands.ml index 97337c7..81a2ab8 100644 --- a/PC_Mainboard/driver/commands.ml +++ b/PC_Mainboard/driver/commands.ml @@ -120,6 +120,20 @@ struct else backend Protocol.traj_tr card angle speed acc + let goto card ~x ~y ~speed ~acc ~mode ~bypass_dist = + let data = Card.make_buffer () in + RW.set_uint8 data 0 Protocol.traj_goto; + RW.set_int16 data 1 x; + RW.set_int16 data 3 y; + RW.set_int16 data 5 speed; + RW.set_int16 data 7 acc; + RW.set_uint8 data 9 (match mode with (* lm629.h:157 *) + | `Straight -> 0 + | `Curve_right -> 1 + | `Curve_left -> 2); + RW.set_int16 data 10 bypass_dist; + Card.send_command card Protocol.cmd_traj data + (* Values comming from lm629.h *) let int_of_direction motor dir = match motor, dir with | `Right, `Forward -> -1 diff --git a/PC_Mainboard/driver/commands.mli b/PC_Mainboard/driver/commands.mli index 43fc243..cce2301 100644 --- a/PC_Mainboard/driver/commands.mli +++ b/PC_Mainboard/driver/commands.mli @@ -42,6 +42,8 @@ module Motor : sig val move : Card.t -> dist : int -> speed : int -> acc : int -> unit Lwt.t val turn : Card.t -> angle : int -> speed : int -> acc : int -> unit Lwt.t + val goto : Card.t -> x : int -> y : int -> speed : int -> acc : int -> mode : Types.goto_mode -> bypass_dist : int -> unit Lwt.t + type stop_mode = [ `Off | `Abrupt | `Smooth ] val stop : Card.t -> motor : t -> mode : stop_mode -> unit Lwt.t diff --git a/PC_Mainboard/driver/driver.ml b/PC_Mainboard/driver/driver.ml index e97a0cf..d354076 100644 --- a/PC_Mainboard/driver/driver.ml +++ b/PC_Mainboard/driver/driver.ml @@ -193,7 +193,7 @@ struct (* No movement *) | Ms_stopping (* The trajectory has been stopped *) - | Ms_moving of [ `Forward | `Backward | `Turn ] + | Ms_moving of [ `Forward | `Backward | `Turn | `Goto ] (* Currently moving. The argument is a wakener to stop the mover. *) @@ -292,8 +292,26 @@ struct dev.move_state <- Ms_static; return result + let goto dev x y speed acc mode bypass_dist = + match dev.move_state with + | Ms_moving _ | Ms_stopping -> + fail (Failure "already moving") + | Ms_static -> + reset_speed dev; + dev.move_state <- Ms_moving `Goto; + lwt () = Commands.Motor.goto dev.card ~x ~y ~speed ~acc ~mode ~bypass_dist and _ = Lwt_event.next dev.traj_completed in + let result = match dev.move_state with + | Ms_stopping -> + `Stopped + | _ -> + `OK + in + dev.move_state <- Ms_static; + return result + OL_method Turn : int -> int -> int -> Types.move_result OL_method Move : int -> int -> int -> Types.move_result + OL_method Goto : int -> int -> int -> int -> Types.goto_mode -> int -> Types.move_result (* +---------------------------------------------------------------+ | Low-level control of speed and acceleration of each motor | @@ -372,7 +390,7 @@ struct dev.inhibit_forward_until <- until; ignore (inhibited_forward_changed dev until); match dev.move_state with - | Ms_moving `Forward -> + | Ms_moving (`Forward | `Goto) -> stop_motors dev `Both `Abrupt | Ms_static when dev.speed_left > 0 || dev.speed_right > 0 -> stop_motors dev `Both `Abrupt @@ -385,7 +403,7 @@ struct dev.inhibit_backward_until <- until; ignore (inhibited_backward_changed dev until); match dev.move_state with - | Ms_moving `Backward -> + | Ms_moving (`Backward | `Goto) -> stop_motors dev `Both `Abrupt | Ms_static when dev.speed_left < 0 || dev.speed_right < 0 -> stop_motors dev `Both `Abrupt diff --git a/PC_Mainboard/lib_krobot/krobot.ml b/PC_Mainboard/lib_krobot/krobot.ml index e3bf7f6..67ab2a0 100644 --- a/PC_Mainboard/lib_krobot/krobot.ml +++ b/PC_Mainboard/lib_krobot/krobot.ml @@ -183,27 +183,11 @@ OP_method AX12Goto : id : int -> pos : int -> speed : int -> unit include MakeDevice(struct let name = "Motors" end) -type motor = [ `Left | `Right | `Both ] -type move_result = [ `OK | `Stopped ] - -let obus_move_result = OBus_type.mapping obus_int - [(`OK, 0); - (`Stopped, 1)] - -let obus_motor = OBus_type.mapping obus_int - [(`Left, -1); - (`Both, 0); - (`Right, 1)] - -let obus_stop_mode = OBus_type.mapping obus_int - [(`Off, 0); - (`Abrupt, 1); - (`Smooth, 2)] - -OP_method Turn : angle : int -> speed : int -> acc : int -> move_result -OP_method Move : dist : int -> speed : int -> acc : int -> move_result -OP_method StopMotors : motor : motor -> mode : stop_mode -> unit -OP_method SetSpeed : motor : motor -> speed : int -> acc : int -> unit +OP_method Turn : angle : int -> speed : int -> acc : int -> Types.move_result +OP_method Move : dist : int -> speed : int -> acc : int -> Types.move_result +OP_method Goto : x : int -> y : int -> speed : int -> acc : int -> mode : Types.goto_mode -> bypass_dist : int -> Types.move_result +OP_method StopMotors : motor : Types.motor -> mode : Types.stop_mode -> unit +OP_method SetSpeed : motor : Types.motor -> speed : int -> acc : int -> unit OP_method InhibitForward : float -> unit OP_method InhibitBackward : float -> unit diff --git a/PC_Mainboard/lib_krobot/krobot.mli b/PC_Mainboard/lib_krobot/krobot.mli index cb468bb..694bae6 100644 --- a/PC_Mainboard/lib_krobot/krobot.mli +++ b/PC_Mainboard/lib_krobot/krobot.mli @@ -67,6 +67,7 @@ val ax12_goto : t -> id : int -> pos : int -> speed : int -> unit Lwt.t val turn : t -> angle : int -> speed : int -> acc : int -> Types.move_result Lwt.t val move : t -> dist : int -> speed : int -> acc : int -> Types.move_result Lwt.t +val goto : t -> x : int -> y : int -> speed : int -> acc : int -> mode : Types.goto_mode -> bypass_dist : int -> Types.move_result Lwt.t val stop_motors : t -> motor : Types.motor -> mode : Types.stop_mode -> unit Lwt.t (** [stop_motorw t motor mode] stop the given motor(s). *) hooks/post-receive -- krobot |
From: Jérémie D. <Ba...@us...> - 2010-02-19 12:27: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 530d98a475d5fd24a8a5aa9a04a3ae293cf0a022 (commit) from 63fb5ee679acec91c2b3916b2a465e93bbbb4a2b (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 530d98a475d5fd24a8a5aa9a04a3ae293cf0a022 Author: Jérémie Dimino <je...@di...> Date: Fri Feb 19 13:26:25 2010 +0100 [driver] rename `primary_owner to `Primary_owner ----------------------------------------------------------------------- Changes: diff --git a/PC_Mainboard/driver/driver.ml b/PC_Mainboard/driver/driver.ml index 0a6a4c0..e97a0cf 100644 --- a/PC_Mainboard/driver/driver.ml +++ b/PC_Mainboard/driver/driver.ml @@ -604,7 +604,7 @@ lwt () = else begin (* Request the bus name for the driver: *) lwt () = OBus_bus.request_name bus "fr.krobot" >>= function - | `primary_owner -> + | `Primary_owner -> return () | _ -> fail (Failure "cannot obtain the name 'fr.krobot'") hooks/post-receive -- krobot |
From: Jérémie D. <Ba...@us...> - 2010-02-19 10:37:43
|
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 63fb5ee679acec91c2b3916b2a465e93bbbb4a2b (commit) from f8de486ed428692bf71920a2343a51fe066bce60 (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 63fb5ee679acec91c2b3916b2a465e93bbbb4a2b Author: Jérémie Dimino <je...@di...> Date: Fri Feb 19 11:36:50 2010 +0100 update logging instructions ----------------------------------------------------------------------- Changes: diff --git a/PC_Mainboard/clients/controller.ml b/PC_Mainboard/clients/controller.ml index 25728ec..5b940f3 100644 --- a/PC_Mainboard/clients/controller.ml +++ b/PC_Mainboard/clients/controller.ml @@ -9,6 +9,8 @@ (* Prints status continuously *) +module Log = Lwt_log.Make(struct let section = "controller" end) + open Lwt open Lwt_term open Lwt_read_line @@ -259,7 +261,7 @@ let rec loop krobot history = else begin let history = Lwt_read_line.add_entry line history in set_engine_state (Engine.init history); - lwt () = Log#notice "%s" line in + lwt () = Log.notice line in ignore (Script.exec krobot line); loop krobot history end @@ -304,7 +306,7 @@ let redirect_stderr () = () lwt () = - lwt () = Log#notice "connecting to the krobot bus..." in + lwt () = Log.notice "connecting to the krobot bus..." in lwt krobot = Krobot.create () in lwt () = save_state () in lwt () = hide_cursor () in diff --git a/PC_Mainboard/clients/init_position.ml b/PC_Mainboard/clients/init_position.ml index 4683c51..94073a3 100644 --- a/PC_Mainboard/clients/init_position.ml +++ b/PC_Mainboard/clients/init_position.ml @@ -9,34 +9,35 @@ (* Put the robot into its initial state *) +module Log = Lwt_log.Make(struct let section = "" end) + open Lwt let move_backward_slowly krobot = - lwt () = Log#notice "moving backward" in + lwt () = Log.notice "moving backward" in Krobot.move krobot ~dist:(-1000) ~speed:100 ~acc:100 >>= function | `OK -> - lwt () = Log#error "where am i ???" in + lwt () = Log.error "where am i ???" in exit 1 | `Stopped -> - lwt () = Log#notice "backward colisiton dectected" in - return () + Log.notice "backward colisiton dectected" lwt () = lwt krobot = Krobot.create () in lwt () = move_backward_slowly krobot in - lwt () = Log#notice "going to initial position on first axis" in + lwt () = Log.notice "going to initial position on first axis" in lwt _ = Krobot.move krobot ~dist:Config.initial_position ~speed:400 ~acc:800 in - lwt () = Log#notice "turning" in + lwt () = Log.notice "turning" in lwt _ = Krobot.turn krobot ~angle:(-90) ~speed:400 ~acc:800 in lwt () = move_backward_slowly krobot in - lwt () = Log#notice "going to initial position on second axis" in + lwt () = Log.notice "going to initial position on second axis" in lwt _ = Krobot.move krobot ~dist:Config.initial_position ~speed:400 ~acc:800 in - lwt () = Log#notice "turning" in + lwt () = Log.notice "turning" in lwt _ = Krobot.turn krobot ~angle:45 ~speed:400 ~acc:800 in return () diff --git a/PC_Mainboard/clients/joy_control.ml b/PC_Mainboard/clients/joy_control.ml index 4510e0f..3d7d355 100644 --- a/PC_Mainboard/clients/joy_control.ml +++ b/PC_Mainboard/clients/joy_control.ml @@ -9,6 +9,8 @@ (* Control the robot with a joystick *) +module Log = Lwt_log.Make(struct let section = "" end) + open Lwt open Sdljoystick open Sdlevent @@ -121,7 +123,7 @@ let try_call action f = try_lwt f () with Failure msg -> - lwt () = Log#error "action %s failed with: %s" action msg in + lwt () = Log.error_f "action %s failed with: %s" action msg in return () let rec set_speed action krobot motor speed abort_waiter = @@ -210,6 +212,6 @@ let () = Unix.close fd_w; Lwt_main.run begin lwt krobot = Krobot.create () in - lwt() = Log#notice "ready to process event" in + lwt() = Log.notice "ready to process event" in parent_loop krobot (Lwt_io.of_unix_fd ~mode:Lwt_io.input fd_r) end diff --git a/PC_Mainboard/clients/script.ml b/PC_Mainboard/clients/script.ml index 11d89d3..9c3f558 100644 --- a/PC_Mainboard/clients/script.ml +++ b/PC_Mainboard/clients/script.ml @@ -7,6 +7,8 @@ * This file is a part of [kro]bot. *) +module Log = Lwt_log.Make(struct let section = "script" end) + open Lwt module TextSet = Set.Make(Text) @@ -110,9 +112,9 @@ let motor_of_string = function let move thread = thread >>= function | `OK -> - Log#notice "done" + Log.notice "done" | `Stopped -> - Log#notice "stopped" + Log.notice "stopped" let exec krobot line = try_lwt @@ -169,7 +171,7 @@ let exec krobot line = (i + 1)) 0 l in - Log#notice "%s" (Buffer.contents buffer) + Log.notice (Buffer.contents buffer) | "calibration-start" -> Krobot.calibration_start krobot (arg_int "range-finder" 0) (match arg_string "skip-meas" "false" with @@ -181,11 +183,11 @@ let exec krobot line = | "calibration-stop" -> Krobot.calibration_stop krobot | _ -> - Log#error "unknown command %S" action + Log.error_f "unknown command %S" action with | Script_lexer.Parse_failure msg -> - Log#error "parse failure: %s" msg + Log.error_f "parse failure: %s" msg | Failure msg -> - Log#error "command failed: %s" msg + Log.error_f "command failed: %s" msg | exn -> - Log#exn exn "command failed with" + Log.exn exn "command failed with" diff --git a/PC_Mainboard/driver/card.ml b/PC_Mainboard/driver/card.ml index b93e429..7ffe0b7 100644 --- a/PC_Mainboard/driver/card.ml +++ b/PC_Mainboard/driver/card.ml @@ -7,6 +7,8 @@ * This file is a part of [kro]bot. *) +module Log = Lwt_log.Make(struct let section = "card" end) + open Lwt (* +-----------------------------------------------------------------+ @@ -167,13 +169,13 @@ let rec dispatch card = return (`Error exn) end >>= function | `Error exn -> - lwt () = Log#exn exn "stop dispatching on %s card" card.wrapper.name in + lwt () = Log.exn_f exn "stop dispatching on %s card" card.wrapper.name in lwt _ = abort card.wrapper exn in return () | `OK len -> if len <> 64 then begin let msg = Printf.sprintf "read on %s card returned %d instead of 64" card.wrapper.name len in - lwt () = Log#error "%s" msg in + lwt () = Log.error msg in lwt _ = abort card.wrapper (Card_crashed msg) in return () end else begin @@ -185,7 +187,7 @@ let rec dispatch card = card.serial_pool <- card.serial_pool @ [msg.host_serial]; Lwt.wakeup wakener msg.data | None -> - LogI#warning "response dropped" + ignore (Log.warning "response dropped") end else begin match try Some(Int_map.find msg.command card.events) with Not_found -> None with | Some seq -> @@ -194,10 +196,10 @@ let rec dispatch card = try push msg.data with exn -> - LogI#exn exn "pushing event %d from %s card failed with" msg.command card.wrapper.name) + ignore (Log.exn_f exn "pushing event %d from %s card failed with" msg.command card.wrapper.name)) seq | None -> - LogI#warning "command dropped" + ignore (Log.warning "command dropped") end; dispatch card end @@ -258,7 +260,7 @@ let send card buffer = lwt len = select [card.abort_waiter; USB.interrupt_send ~handle:card.handle ~endpoint:1 buffer 0 64] in if len <> 64 then begin let msg = Printf.sprintf "write on %s card returned %d instead of 64" card.wrapper.name len in - lwt () = Log#error "%s" msg in + lwt () = Log.error msg in fail =<< abort card.wrapper (Card_crashed msg) end else return () @@ -292,7 +294,7 @@ let rec send_request wrapper command data = | Canceled -> fail Canceled | exn -> - lwt () = Log#exn exn "write to %s card failed with" wrapper.name in + lwt () = Log.exn_f exn "write to %s card failed with" wrapper.name in fail =<< abort wrapper exn (* Send a command without waiting for the reply: *) @@ -309,7 +311,7 @@ let rec send_command wrapper command data = | Canceled -> fail Canceled | exn -> - lwt () = Log#exn exn "write to %s card failed with" wrapper.name in + lwt () = Log.exn_f exn "write to %s card failed with" wrapper.name in fail =<< abort wrapper exn let connect wrapper command = match wrapper.state with diff --git a/PC_Mainboard/driver/driver.ml b/PC_Mainboard/driver/driver.ml index 37379f1..0a6a4c0 100644 --- a/PC_Mainboard/driver/driver.ml +++ b/PC_Mainboard/driver/driver.ml @@ -9,6 +9,8 @@ (* Driver for USB cards *) +module Log = Lwt_log.Make(struct let section = "driver" end) + open OBus_pervasives open Lwt @@ -250,7 +252,7 @@ struct dev.speed_right <- 0 let move dev dist speed acc = - lwt () = Log#info "motor: move(dist=%d, speed=%d, acc=%d)" dist speed acc in + lwt () = Log.info_f "motor: move(dist=%d, speed=%d, acc=%d)" dist speed acc in match dev.move_state with | Ms_moving _ | Ms_stopping -> fail (Failure "already moving") @@ -273,7 +275,7 @@ struct end let turn dev angle speed acc = - lwt () = Log#info "motor: turn(angle=%d, speed=%d, acc=%d)" angle speed acc in + lwt () = Log.info_f "motor: turn(angle=%d, speed=%d, acc=%d)" angle speed acc in match dev.move_state with | Ms_moving _ | Ms_stopping -> fail (Failure "already moving") @@ -308,12 +310,12 @@ struct | `Smooth -> "smooth" let stop_motors dev motor mode = - lwt () = Log#info "motor: stopping(motor=%s, mode=%s)" (string_of_motor motor) (string_of_stop_mode mode) in + lwt () = Log.info_f "motor: stopping(motor=%s, mode=%s)" (string_of_motor motor) (string_of_stop_mode mode) in stop_move dev; Commands.Motor.stop dev.card motor mode let set_speed dev motor speed acc = - lwt () = Log#info "motor: set_speed(motor=%s, speed=%d, acc=%d)" (string_of_motor motor) speed acc in + lwt () = Log.info_f "motor: set_speed(motor=%s, speed=%d, acc=%d)" (string_of_motor motor) speed acc in stop_move dev; let dir, abs_speed = if speed < 0 then (`Backward, -speed) else (`Forward, speed) in let date = Unix.gettimeofday () in @@ -446,7 +448,7 @@ struct state card_motor) OL_method Shutdown : OBus_connection.t -> unit = fun () connection -> - lwt () = Log#info "exiting" in + lwt () = Log.info "exiting" in quit := true; lwt _ = OBus_bus.release_name connection "fr.krobot" and () = close card_interface @@ -529,10 +531,10 @@ end let rec monitor_card ~name ~vendor_id ~product_id ~set on_up on_down = match try `Handle(USB.open_device_with ~vendor_id ~product_id) with exn -> `Error exn with | `Error exn -> - lwt () = Log#exn exn "failed to open %s card" name in + lwt () = Log.exn_f exn "failed to open %s card" name in restart_card ~name ~vendor_id ~product_id ~set on_up on_down | `Handle handle -> - lwt () = Log#info "%s card opened" name in + lwt () = Log.info_f "%s card opened" name in begin try_lwt lwt card = Card.make name handle in @@ -541,7 +543,7 @@ let rec monitor_card ~name ~vendor_id ~product_id ~set on_up on_down = return (`Error exn) end >>= function | `Card card -> - lwt () = Log#info "%s card is up and running" name in + lwt () = Log.info_f "%s card is up and running" name in set (Some card); lwt () = on_up card in lwt result = Card.watch card in @@ -552,11 +554,11 @@ let rec monitor_card ~name ~vendor_id ~product_id ~set on_up on_down = | `Closed -> return () | `Error exn -> - Log#exn exn "%s card crashed with" name + Log.exn_f exn "%s card crashed with" name in restart_card ~name ~vendor_id ~product_id ~set on_up on_down | `Error exn -> - lwt () = Log#exn exn "failed to make %s card" name in + lwt () = Log.exn_f exn "failed to make %s card" name in restart_card ~name ~vendor_id ~product_id ~set on_up on_down and restart_card ~name ~vendor_id ~product_id ~set on_up on_down = @@ -585,7 +587,7 @@ lwt () = lwt () = try_lwt - lwt () = Log#info "Killing any running driver" in + lwt () = Log.info "Killing any running driver" in OBus_connection.method_call bus ~path:["fr"; "krobot"; "Manager"] ~interface:"fr.krobot.Manager" @@ -611,9 +613,9 @@ lwt () = lwt () = if !foreground then (* Running foreground, prints message on stderr: *) - Log#notice "starting krobot driver in foreground mode" + Log.notice "starting krobot driver in foreground mode" else begin - lwt () = Log#notice "starting krobot driver in daemon mode" in + lwt () = Log.notice "starting krobot driver in daemon mode" in Lwt_daemon.daemonize (); return () end @@ -661,6 +663,6 @@ lwt () = Manager.OBus.export bus (); - LogI#notice "ready, waiting for requests"; + lwt () = Log.notice "ready, waiting for requests" in done_waiter end diff --git a/PC_Mainboard/lib_krobot/krobot.ml b/PC_Mainboard/lib_krobot/krobot.ml index fd4a1a1..e3bf7f6 100644 --- a/PC_Mainboard/lib_krobot/krobot.ml +++ b/PC_Mainboard/lib_krobot/krobot.ml @@ -7,6 +7,8 @@ * This file is a part of [kro]bot. *) +module Log = Lwt_log.Make(struct let section = "krobot" end) + open OBus_pervasives open Lwt @@ -88,7 +90,7 @@ let get_bus () = match try Some(Sys.getenv "KROBOT") with Not_found -> None with | Some command -> begin try_lwt - lwt () = Log#info "connecting to the krobot with command %S" command in + lwt () = Log.info_f "connecting to the krobot with command %S" command in let process = Lwt_process.open_process (Lwt_process.shell command) in let transport = OBus_transport.make @@ -101,15 +103,15 @@ let get_bus () = lwt () = OBus_bus.register_connection connection in return connection with exn -> - lwt () = Log#exn exn "failed to create remote transport" in + lwt () = Log.exn exn "failed to create remote transport" in fail exn end | None -> try_lwt - lwt () = Log#info "connecting to the krobot with the local krobot bus" in + lwt () = Log.info "connecting to the krobot with the local krobot bus" in Lazy.force bus with exn -> - lwt () = Log#exn exn "failed to connect to the local krobot bus" in + lwt () = Log.exn exn "failed to connect to the local krobot bus" in fail exn let create ?peer () = diff --git a/PC_Mainboard/services/hard_stop.ml b/PC_Mainboard/services/hard_stop.ml index f2352a7..a07d177 100644 --- a/PC_Mainboard/services/hard_stop.ml +++ b/PC_Mainboard/services/hard_stop.ml @@ -9,6 +9,8 @@ (* Stop the robot on collisions *) +module Log = Lwt_log.Make(struct let section = "" end) + open Lwt (* Duration of an inhibition: *) @@ -25,12 +27,12 @@ type state = OK | Stopped let handle_collide krobot sensors = join [ (if Util.front_collide sensors then begin - lwt () = Log#notice "front collision detected, inhibit motors" in + lwt () = Log.notice "front collision detected, inhibit motors" in Krobot.inhibit_forward krobot duration end else return ()); (if Util.back_collide sensors then begin - lwt () = Log#notice "back collision detected, inhibit motors" in + lwt () = Log.notice "back collision detected, inhibit motors" in Krobot.inhibit_backward krobot duration end else return ()); @@ -40,9 +42,9 @@ lwt () = Arg.parse args ignore usage; if !foreground then - LogI#info "starting hard_stop in foreground mode" + ignore (Log.info "starting hard_stop in foreground mode") else begin - LogI#info "starting hard_stop in daemon mode"; + ignore (Log.info "starting hard_stop in daemon mode"); Lwt_log.default := Lwt_log.syslog ~level:(min Lwt_log.Info Lwt_log.default_level) ~facility:`Daemon hooks/post-receive -- krobot |
From: Jérémie D. <Ba...@us...> - 2010-02-18 23:27:22
|
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 f8de486ed428692bf71920a2343a51fe066bce60 (commit) from 6f556df4ed198f82f795fbd18b86cf51e9275015 (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 f8de486ed428692bf71920a2343a51fe066bce60 Author: Jérémie Dimino <je...@di...> Date: Fri Feb 19 00:27:07 2010 +0100 update logs ----------------------------------------------------------------------- Changes: diff --git a/PC_Mainboard/clients/controller.ml b/PC_Mainboard/clients/controller.ml index 614cf73..25728ec 100644 --- a/PC_Mainboard/clients/controller.ml +++ b/PC_Mainboard/clients/controller.ml @@ -259,7 +259,7 @@ let rec loop krobot history = else begin let history = Lwt_read_line.add_entry line history in set_engine_state (Engine.init history); - Log#notice "%s" line; + lwt () = Log#notice "%s" line in ignore (Script.exec krobot line); loop krobot history end @@ -304,7 +304,7 @@ let redirect_stderr () = () lwt () = - Log#notice "connecting to the krobot bus..."; + lwt () = Log#notice "connecting to the krobot bus..." in lwt krobot = Krobot.create () in lwt () = save_state () in lwt () = hide_cursor () in diff --git a/PC_Mainboard/clients/joy_control.ml b/PC_Mainboard/clients/joy_control.ml index 0eace2d..4510e0f 100644 --- a/PC_Mainboard/clients/joy_control.ml +++ b/PC_Mainboard/clients/joy_control.ml @@ -121,7 +121,7 @@ let try_call action f = try_lwt f () with Failure msg -> - Log#error "action %s failed with: %s" action msg; + lwt () = Log#error "action %s failed with: %s" action msg in return () let rec set_speed action krobot motor speed abort_waiter = @@ -202,7 +202,7 @@ let () = try open_joystick 0 with exn -> - Log#error "cannot open joystick: %S" (Printexc.to_string exn); + Printf.eprintf "cannot open joystick: %s\n%!" (Printexc.to_string exn); raise exn in child_loop (Unix.out_channel_of_descr fd_w) joy @@ -210,6 +210,6 @@ let () = Unix.close fd_w; Lwt_main.run begin lwt krobot = Krobot.create () in - Log#notice "ready to process event"; + lwt() = Log#notice "ready to process event" in parent_loop krobot (Lwt_io.of_unix_fd ~mode:Lwt_io.input fd_r) end diff --git a/PC_Mainboard/clients/script.ml b/PC_Mainboard/clients/script.ml index a25c932..11d89d3 100644 --- a/PC_Mainboard/clients/script.ml +++ b/PC_Mainboard/clients/script.ml @@ -110,11 +110,9 @@ let motor_of_string = function let move thread = thread >>= function | `OK -> - Log#notice "done"; - return () + Log#notice "done" | `Stopped -> - Log#notice "stopped"; - return () + Log#notice "stopped" let exec krobot line = try_lwt @@ -171,8 +169,7 @@ let exec krobot line = (i + 1)) 0 l in - Log#notice "%s" (Buffer.contents buffer); - return () + Log#notice "%s" (Buffer.contents buffer) | "calibration-start" -> Krobot.calibration_start krobot (arg_int "range-finder" 0) (match arg_string "skip-meas" "false" with @@ -184,15 +181,11 @@ let exec krobot line = | "calibration-stop" -> Krobot.calibration_stop krobot | _ -> - Log#error "unknown command %S" action; - return () + Log#error "unknown command %S" action with | Script_lexer.Parse_failure msg -> - Log#error "parse failure: %s" msg; - return () + Log#error "parse failure: %s" msg | Failure msg -> - Log#error "command failed: %s" msg; - return () + Log#error "command failed: %s" msg | exn -> - Log#exn exn "command failed with"; - return () + Log#exn exn "command failed with" hooks/post-receive -- krobot |
From: Jérémie D. <Ba...@us...> - 2010-02-18 22:44:59
|
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 6f556df4ed198f82f795fbd18b86cf51e9275015 (commit) from 473355d363bbc31784528a6238acd0a3baad451e (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 6f556df4ed198f82f795fbd18b86cf51e9275015 Author: Jérémie Dimino <je...@di...> Date: Thu Feb 18 23:40:10 2010 +0100 Add commands for calibration ----------------------------------------------------------------------- Changes: diff --git a/PC_Mainboard/clients/init_position.ml b/PC_Mainboard/clients/init_position.ml index 2217b76..4683c51 100644 --- a/PC_Mainboard/clients/init_position.ml +++ b/PC_Mainboard/clients/init_position.ml @@ -12,13 +12,13 @@ open Lwt let move_backward_slowly krobot = - Log#notice "moving backward"; + lwt () = Log#notice "moving backward" in Krobot.move krobot ~dist:(-1000) ~speed:100 ~acc:100 >>= function | `OK -> - Log#error "where am i ???"; + lwt () = Log#error "where am i ???" in exit 1 | `Stopped -> - Log#notice "backward colisiton dectected"; + lwt () = Log#notice "backward colisiton dectected" in return () lwt () = @@ -26,17 +26,17 @@ lwt () = lwt () = move_backward_slowly krobot in - Log#notice "going to initial position on first axis"; + lwt () = Log#notice "going to initial position on first axis" in lwt _ = Krobot.move krobot ~dist:Config.initial_position ~speed:400 ~acc:800 in - Log#notice "turning"; + lwt () = Log#notice "turning" in lwt _ = Krobot.turn krobot ~angle:(-90) ~speed:400 ~acc:800 in lwt () = move_backward_slowly krobot in - Log#notice "going to initial position on second axis"; + lwt () = Log#notice "going to initial position on second axis" in lwt _ = Krobot.move krobot ~dist:Config.initial_position ~speed:400 ~acc:800 in - Log#notice "turning"; + lwt () = Log#notice "turning" in lwt _ = Krobot.turn krobot ~angle:45 ~speed:400 ~acc:800 in return () diff --git a/PC_Mainboard/clients/script.ml b/PC_Mainboard/clients/script.ml index 1d147a3..a25c932 100644 --- a/PC_Mainboard/clients/script.ml +++ b/PC_Mainboard/clients/script.ml @@ -45,6 +45,12 @@ let commands = [ args = [("card", Arg_keyword ["interface"; "sensor"; "motor"])] }; { name = "get-calibration"; args = [] }; + { name = "calibration-start"; + args = [("range-finder", Arg_int); ("skip-meas", Arg_keyword ["true"; "false"])] }; + { name = "calibration-stop"; + args = [] }; + { name = "calibration-continue"; + args = [] }; ] let set_of_list l = List.fold_left (fun set x -> TextSet.add x set) TextSet.empty l @@ -167,6 +173,16 @@ let exec krobot line = in Log#notice "%s" (Buffer.contents buffer); return () + | "calibration-start" -> + Krobot.calibration_start krobot (arg_int "range-finder" 0) + (match arg_string "skip-meas" "false" with + | "true" -> true + | "false" -> false + | _ -> raise (Failure "invalid boolean value")) + | "calibration-continue" -> + Krobot.calibration_continue krobot + | "calibration-stop" -> + Krobot.calibration_stop krobot | _ -> Log#error "unknown command %S" action; return () diff --git a/PC_Mainboard/driver/commands.ml b/PC_Mainboard/driver/commands.ml index 44ce69d..97337c7 100644 --- a/PC_Mainboard/driver/commands.ml +++ b/PC_Mainboard/driver/commands.ml @@ -75,6 +75,23 @@ struct RW.set_uint8 data 1 num; lwt data = Card.send_request card Protocol.cmd_get data in return (Array.init 8 (fun i -> RW.get_uint8 data i)) + + let calibration_start card num skip_meas = + let data = Card.make_buffer () in + RW.set_uint8 data 0 Protocol.cal_start; + RW.set_uint8 data 1 num; + RW.set_uint8 data 2 (if skip_meas then 1 else 0); + Card.send_command card Protocol.cmd_calibrate data + + let calibration_continue card = + let data = Card.make_buffer () in + RW.set_uint8 data 0 Protocol.cal_continue; + Card.send_command card Protocol.cmd_calibrate data + + let calibration_stop card = + let data = Card.make_buffer () in + RW.set_uint8 data 0 Protocol.cal_stop; + Card.send_command card Protocol.cmd_calibrate data end module Motor = diff --git a/PC_Mainboard/driver/commands.mli b/PC_Mainboard/driver/commands.mli index 1b7ff04..43fc243 100644 --- a/PC_Mainboard/driver/commands.mli +++ b/PC_Mainboard/driver/commands.mli @@ -31,6 +31,9 @@ end module Range_finders : sig val get : Card.t -> int array Lwt.t val get_calibration : Card.t -> int -> int array Lwt.t + val calibration_start : Card.t -> int -> bool -> unit Lwt.t + val calibration_continue : Card.t -> unit Lwt.t + val calibration_stop : Card.t -> unit Lwt.t end module Motor : sig diff --git a/PC_Mainboard/driver/driver.ml b/PC_Mainboard/driver/driver.ml index c9563e4..37379f1 100644 --- a/PC_Mainboard/driver/driver.ml +++ b/PC_Mainboard/driver/driver.ml @@ -152,6 +152,13 @@ struct OL_method GetCalibration : int -> int array = fun dev num -> Commands.Range_finders.get_calibration dev.card num + OL_method CalibrationStart : int -> bool -> unit = fun dev num skip_meas -> + Commands.Range_finders.calibration_start dev.card num skip_meas + OL_method CalibrationStop : unit = fun dev -> + Commands.Range_finders.calibration_stop dev.card + OL_method CalibrationContinue : unit = fun dev -> + Commands.Range_finders.calibration_continue dev.card + let rec loop dev = lwt data = Commands.Range_finders.get dev.card in if data <> dev.data then begin diff --git a/PC_Mainboard/lib_krobot/krobot.ml b/PC_Mainboard/lib_krobot/krobot.ml index 8d2ec2e..fd4a1a1 100644 --- a/PC_Mainboard/lib_krobot/krobot.ml +++ b/PC_Mainboard/lib_krobot/krobot.ml @@ -88,7 +88,7 @@ let get_bus () = match try Some(Sys.getenv "KROBOT") with Not_found -> None with | Some command -> begin try_lwt - Log#info "connecting to the krobot with command %S" command; + lwt () = Log#info "connecting to the krobot with command %S" command in let process = Lwt_process.open_process (Lwt_process.shell command) in let transport = OBus_transport.make @@ -101,15 +101,15 @@ let get_bus () = lwt () = OBus_bus.register_connection connection in return connection with exn -> - Log#exn exn "failed to create remote transport"; + lwt () = Log#exn exn "failed to create remote transport" in fail exn end | None -> try_lwt - Log#info "connecting to the krobot with the local krobot bus"; + lwt () = Log#info "connecting to the krobot with the local krobot bus" in Lazy.force bus with exn -> - Log#exn exn "failed to connect to the local krobot bus"; + lwt () = Log#exn exn "failed to connect to the local krobot bus" in fail exn let create ?peer () = @@ -163,6 +163,9 @@ let jack krobot = include MakeDevice(struct let name = "RangeFinders" end) OP_method GetCalibration : int -> int array +OP_method CalibrationStart : int -> bool -> unit +OP_method CalibrationStop : unit +OP_method CalibrationContinue : unit (* +-----------------------------------------------------------------+ | AX12 | diff --git a/PC_Mainboard/lib_krobot/krobot.mli b/PC_Mainboard/lib_krobot/krobot.mli index 86e6b08..cb468bb 100644 --- a/PC_Mainboard/lib_krobot/krobot.mli +++ b/PC_Mainboard/lib_krobot/krobot.mli @@ -55,6 +55,10 @@ val get_calibration : t -> int -> int array Lwt.t (** [get_calibration krobot num] returns the calibration of the given range finder. *) +val calibration_start : t -> int -> bool -> unit Lwt.t +val calibration_continue : t -> unit Lwt.t +val calibration_stop : t -> unit Lwt.t + (** {6 Manipulation of AX12s} *) val ax12_goto : t -> id : int -> pos : int -> speed : int -> unit Lwt.t hooks/post-receive -- krobot |
From: Jérémie D. <Ba...@us...> - 2010-02-18 19:06:49
|
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 473355d363bbc31784528a6238acd0a3baad451e (commit) from d5ab617b932411ce6d6a6d987575418bba469599 (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 473355d363bbc31784528a6238acd0a3baad451e Author: Jérémie Dimino <je...@di...> Date: Thu Feb 18 20:06:13 2010 +0100 update logging instructions ----------------------------------------------------------------------- Changes: diff --git a/PC_Mainboard/driver/card.ml b/PC_Mainboard/driver/card.ml index 1a9927c..b93e429 100644 --- a/PC_Mainboard/driver/card.ml +++ b/PC_Mainboard/driver/card.ml @@ -167,13 +167,13 @@ let rec dispatch card = return (`Error exn) end >>= function | `Error exn -> - Log#exn exn "stop dispatching on %s card" card.wrapper.name; + lwt () = Log#exn exn "stop dispatching on %s card" card.wrapper.name in lwt _ = abort card.wrapper exn in return () | `OK len -> if len <> 64 then begin let msg = Printf.sprintf "read on %s card returned %d instead of 64" card.wrapper.name len in - Log#error "%s" msg; + lwt () = Log#error "%s" msg in lwt _ = abort card.wrapper (Card_crashed msg) in return () end else begin @@ -185,7 +185,7 @@ let rec dispatch card = card.serial_pool <- card.serial_pool @ [msg.host_serial]; Lwt.wakeup wakener msg.data | None -> - Log#warning "response dropped" + LogI#warning "response dropped" end else begin match try Some(Int_map.find msg.command card.events) with Not_found -> None with | Some seq -> @@ -194,10 +194,10 @@ let rec dispatch card = try push msg.data with exn -> - Log#exn exn "pushing event %d from %s card failed with" msg.command card.wrapper.name) + LogI#exn exn "pushing event %d from %s card failed with" msg.command card.wrapper.name) seq | None -> - Log#warning "command dropped" + LogI#warning "command dropped" end; dispatch card end @@ -258,7 +258,7 @@ let send card buffer = lwt len = select [card.abort_waiter; USB.interrupt_send ~handle:card.handle ~endpoint:1 buffer 0 64] in if len <> 64 then begin let msg = Printf.sprintf "write on %s card returned %d instead of 64" card.wrapper.name len in - Log#error "%s" msg; + lwt () = Log#error "%s" msg in fail =<< abort card.wrapper (Card_crashed msg) end else return () @@ -292,7 +292,7 @@ let rec send_request wrapper command data = | Canceled -> fail Canceled | exn -> - Log#exn exn "write to %s card failed with" wrapper.name; + lwt () = Log#exn exn "write to %s card failed with" wrapper.name in fail =<< abort wrapper exn (* Send a command without waiting for the reply: *) @@ -309,7 +309,7 @@ let rec send_command wrapper command data = | Canceled -> fail Canceled | exn -> - Log#exn exn "write to %s card failed with" wrapper.name; + lwt () = Log#exn exn "write to %s card failed with" wrapper.name in fail =<< abort wrapper exn let connect wrapper command = match wrapper.state with diff --git a/PC_Mainboard/driver/commands.ml b/PC_Mainboard/driver/commands.ml index 4ca774b..44ce69d 100644 --- a/PC_Mainboard/driver/commands.ml +++ b/PC_Mainboard/driver/commands.ml @@ -71,8 +71,8 @@ struct let get_calibration card num = if num < 0 || num > 7 then invalid_arg "Commands.Range_finders.get_calibration"; let data = Card.make_buffer () in - RW.set_uint8 data Protocol.get_rangefinder_calibration; - RW.set_uint8 data num; + RW.set_uint8 data 0 Protocol.get_rangefinder_calibration; + RW.set_uint8 data 1 num; lwt data = Card.send_request card Protocol.cmd_get data in return (Array.init 8 (fun i -> RW.get_uint8 data i)) end diff --git a/PC_Mainboard/driver/driver.ml b/PC_Mainboard/driver/driver.ml index 3d7bab0..c9563e4 100644 --- a/PC_Mainboard/driver/driver.ml +++ b/PC_Mainboard/driver/driver.ml @@ -243,7 +243,7 @@ struct dev.speed_right <- 0 let move dev dist speed acc = - Log#info "motor: move(dist=%d, speed=%d, acc=%d)" dist speed acc; + lwt () = Log#info "motor: move(dist=%d, speed=%d, acc=%d)" dist speed acc in match dev.move_state with | Ms_moving _ | Ms_stopping -> fail (Failure "already moving") @@ -266,7 +266,7 @@ struct end let turn dev angle speed acc = - Log#info "motor: turn(angle=%d, speed=%d, acc=%d)" angle speed acc; + lwt () = Log#info "motor: turn(angle=%d, speed=%d, acc=%d)" angle speed acc in match dev.move_state with | Ms_moving _ | Ms_stopping -> fail (Failure "already moving") @@ -301,12 +301,12 @@ struct | `Smooth -> "smooth" let stop_motors dev motor mode = - Log#info "motor: stopping(motor=%s, mode=%s)" (string_of_motor motor) (string_of_stop_mode mode); + lwt () = Log#info "motor: stopping(motor=%s, mode=%s)" (string_of_motor motor) (string_of_stop_mode mode) in stop_move dev; Commands.Motor.stop dev.card motor mode let set_speed dev motor speed acc = - Log#info "motor: set_speed(motor=%s, speed=%d, acc=%d)" (string_of_motor motor) speed acc; + lwt () = Log#info "motor: set_speed(motor=%s, speed=%d, acc=%d)" (string_of_motor motor) speed acc in stop_move dev; let dir, abs_speed = if speed < 0 then (`Backward, -speed) else (`Forward, speed) in let date = Unix.gettimeofday () in @@ -439,7 +439,7 @@ struct state card_motor) OL_method Shutdown : OBus_connection.t -> unit = fun () connection -> - Log#info "exiting"; + lwt () = Log#info "exiting" in quit := true; lwt _ = OBus_bus.release_name connection "fr.krobot" and () = close card_interface @@ -522,10 +522,10 @@ end let rec monitor_card ~name ~vendor_id ~product_id ~set on_up on_down = match try `Handle(USB.open_device_with ~vendor_id ~product_id) with exn -> `Error exn with | `Error exn -> - Log#exn exn "failed to open %s card" name; + lwt () = Log#exn exn "failed to open %s card" name in restart_card ~name ~vendor_id ~product_id ~set on_up on_down | `Handle handle -> - Log#info "%s card opened" name; + lwt () = Log#info "%s card opened" name in begin try_lwt lwt card = Card.make name handle in @@ -534,22 +534,22 @@ let rec monitor_card ~name ~vendor_id ~product_id ~set on_up on_down = return (`Error exn) end >>= function | `Card card -> - Log#info "%s card is up and running" name; + lwt () = Log#info "%s card is up and running" name in set (Some card); lwt () = on_up card in lwt result = Card.watch card in set None; lwt () = on_down () in - begin + lwt () = match result with | `Closed -> - () + return () | `Error exn -> Log#exn exn "%s card crashed with" name - end; + in restart_card ~name ~vendor_id ~product_id ~set on_up on_down | `Error exn -> - Log#exn exn "failed to make %s card" name; + lwt () = Log#exn exn "failed to make %s card" name in restart_card ~name ~vendor_id ~product_id ~set on_up on_down and restart_card ~name ~vendor_id ~product_id ~set on_up on_down = @@ -578,7 +578,7 @@ lwt () = lwt () = try_lwt - Log#info "Killing any running driver"; + lwt () = Log#info "Killing any running driver" in OBus_connection.method_call bus ~path:["fr"; "krobot"; "Manager"] ~interface:"fr.krobot.Manager" @@ -601,13 +601,16 @@ lwt () = fail (Failure "cannot obtain the name 'fr.krobot'") in - if !foreground then - (* Running foreground, prints message on stderr: *) - Log#notice "starting krobot driver in foreground mode" - else begin - Log#notice "starting krobot driver in daemon mode"; - Lwt_daemon.daemonize () - end; + lwt () = + if !foreground then + (* Running foreground, prints message on stderr: *) + Log#notice "starting krobot driver in foreground mode" + else begin + lwt () = Log#notice "starting krobot driver in daemon mode" in + Lwt_daemon.daemonize (); + return () + end + in ignore begin monitor_card ~name:"interace" ~vendor_id:Protocol.usb_vid ~product_id:Protocol.usb_pid_robot_interface ~set:set_card_interface @@ -651,6 +654,6 @@ lwt () = Manager.OBus.export bus (); - Log#notice "ready, waiting for requests"; + LogI#notice "ready, waiting for requests"; done_waiter end diff --git a/PC_Mainboard/services/hard_stop.ml b/PC_Mainboard/services/hard_stop.ml index 825e3f0..f2352a7 100644 --- a/PC_Mainboard/services/hard_stop.ml +++ b/PC_Mainboard/services/hard_stop.ml @@ -25,12 +25,12 @@ type state = OK | Stopped let handle_collide krobot sensors = join [ (if Util.front_collide sensors then begin - Log#notice "front collision detected, inhibit motors"; + lwt () = Log#notice "front collision detected, inhibit motors" in Krobot.inhibit_forward krobot duration end else return ()); (if Util.back_collide sensors then begin - Log#notice "back collision detected, inhibit motors"; + lwt () = Log#notice "back collision detected, inhibit motors" in Krobot.inhibit_backward krobot duration end else return ()); @@ -40,9 +40,9 @@ lwt () = Arg.parse args ignore usage; if !foreground then - Log#info "starting hard_stop in foreground mode" + LogI#info "starting hard_stop in foreground mode" else begin - Log#info "starting hard_stop in daemon mode"; + LogI#info "starting hard_stop in daemon mode"; Lwt_log.default := Lwt_log.syslog ~level:(min Lwt_log.Info Lwt_log.default_level) ~facility:`Daemon hooks/post-receive -- krobot |
From: Jérémie D. <Ba...@us...> - 2010-02-18 17:40:09
|
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 d5ab617b932411ce6d6a6d987575418bba469599 (commit) from 874a7ccf8dbabec69f1172c987e9213905ab7d45 (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 d5ab617b932411ce6d6a6d987575418bba469599 Author: Jérémie Dimino <je...@di...> Date: Thu Feb 18 18:39:34 2010 +0100 [controller] logs lines in correct order ----------------------------------------------------------------------- Changes: diff --git a/PC_Mainboard/clients/controller.ml b/PC_Mainboard/clients/controller.ml index abe4a32..614cf73 100644 --- a/PC_Mainboard/clients/controller.ml +++ b/PC_Mainboard/clients/controller.ml @@ -238,7 +238,7 @@ let log_lines lines = else line :: truncate (n + 1) rest in - set_logs (lines @ truncate (List.length lines) (React.S.value logs)) + set_logs (List.rev lines @ truncate (List.length lines) (React.S.value logs)) let history_file_name = Filename.concat (try Unix.getenv "HOME" with _ -> "") ".krobot-controller-history" hooks/post-receive -- krobot |
From: Jérémie D. <Ba...@us...> - 2010-02-18 17:38:28
|
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 874a7ccf8dbabec69f1172c987e9213905ab7d45 (commit) from c4abed670c3fe59fe59c4043cc1224cb2b90a33e (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 874a7ccf8dbabec69f1172c987e9213905ab7d45 Author: Jérémie Dimino <je...@di...> Date: Thu Feb 18 18:37:56 2010 +0100 [controller] returns all calibrations at the same time ----------------------------------------------------------------------- Changes: diff --git a/PC_Mainboard/_tags b/PC_Mainboard/_tags index 6d352b3..818fd97 100644 --- a/PC_Mainboard/_tags +++ b/PC_Mainboard/_tags @@ -55,8 +55,6 @@ <tools/forward_dbus.ml>: syntax_camlp4o, pkg_lwt.syntax, pkg_lwt.syntax.log, pkg_obus.syntax <tools/forward_dbus.*>: pkg_obus -<tools/flood.ml>: syntax_camlp4o, pkg_lwt.syntax, pkg_lwt.syntax.log, pkg_obus.syntax -<tools/flood.*>: pkg_obus # +------------------------------------------------------------------+ # | Tests | diff --git a/PC_Mainboard/clients/controller.ml b/PC_Mainboard/clients/controller.ml index 32791c9..abe4a32 100644 --- a/PC_Mainboard/clients/controller.ml +++ b/PC_Mainboard/clients/controller.ml @@ -217,7 +217,7 @@ let () = (React.S.map (fun state -> state.Engine.mode) engine_state) let logs, set_logs = React.S.create [] -let log line = +let log_line line = let rec truncate n = function | [] -> [] @@ -227,7 +227,18 @@ let log line = else line :: truncate (n + 1) rest in - set_logs (line :: truncate 0 (React.S.value logs)) + set_logs (line :: truncate 1 (React.S.value logs)) +let log_lines lines = + let rec truncate n = function + | [] -> + [] + | line :: rest -> + if n = 1024 then + [] + else + line :: truncate (n + 1) rest + in + set_logs (lines @ truncate (List.length lines) (React.S.value logs)) let history_file_name = Filename.concat (try Unix.getenv "HOME" with _ -> "") ".krobot-controller-history" @@ -268,7 +279,7 @@ let rec loop krobot history = let rec copy_logs ic = lwt line = Lwt_io.read_line ic in - log line; + log_line line; copy_logs ic let redirect_stderr () = @@ -287,7 +298,7 @@ let redirect_stderr () = Lwt_log.render ~buffer ~level ~message:line ~template:"$(date): $(message)"; Buffer.contents buffer) lines in - List.iter log lines; + log_lines lines; return ()) ~close:return () diff --git a/PC_Mainboard/clients/script.ml b/PC_Mainboard/clients/script.ml index 4dc474b..1d147a3 100644 --- a/PC_Mainboard/clients/script.ml +++ b/PC_Mainboard/clients/script.ml @@ -44,7 +44,7 @@ let commands = [ { name = "reset"; args = [("card", Arg_keyword ["interface"; "sensor"; "motor"])] }; { name = "get-calibration"; - args = [("range-finder", Arg_int)] }; + args = [] }; ] let set_of_list l = List.fold_left (fun set x -> TextSet.add x set) TextSet.empty l @@ -152,8 +152,20 @@ let exec krobot line = | "sensor" -> `Sensor | _ -> failwith "Script.exec: invalid card") | "get-calibration" -> - lwt cal = Krobot.get_calibration krobot (arg_int "range-finder" 0) in - Log#notice "calibration: %s" (String.concat " " (List.map string_of_int (Array.to_list cal))); + lwt l = Lwt_list.map_p (Krobot.get_calibration krobot) [0; 1; 2; 3; 4; 5; 6; 7] in + let buffer = Buffer.create 1024 in + let _ = + List.fold_left + (fun i cal -> + Printf.bprintf buffer "calibration[%d]:" i; + for i = 0 to Array.length cal - 1 do + Printf.bprintf buffer " %d" cal.(i) + done; + Buffer.add_char buffer '\n'; + (i + 1)) + 0 l + in + Log#notice "%s" (Buffer.contents buffer); return () | _ -> Log#error "unknown command %S" action; diff --git a/PC_Mainboard/myocamlbuild.ml b/PC_Mainboard/myocamlbuild.ml index a6a42a2..b23d4cf 100644 --- a/PC_Mainboard/myocamlbuild.ml +++ b/PC_Mainboard/myocamlbuild.ml @@ -66,7 +66,6 @@ let targets = List.filter_opt (function (true, target) -> Some target | (false, (* Tools *) (have_lwt_unix && have_obus, "tools/forward_dbus.best"); - (have_lwt_unix && have_obus, "tools/flood.best"); (* Clients *) (have_lwt_unix && have_obus, "clients/info.best"); hooks/post-receive -- krobot |
From: Jérémie D. <Ba...@us...> - 2010-02-18 17:25:23
|
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 c4abed670c3fe59fe59c4043cc1224cb2b90a33e (commit) from 992d372526a6fc373535550469f66096caf4ee99 (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 c4abed670c3fe59fe59c4043cc1224cb2b90a33e Author: Jérémie Dimino <je...@di...> Date: Thu Feb 18 18:24:22 2010 +0100 Ajout d'une commande pour obtenir la calibration des télémètres ----------------------------------------------------------------------- Changes: diff --git a/PC_Mainboard/clients/script.ml b/PC_Mainboard/clients/script.ml index 24d90cc..4dc474b 100644 --- a/PC_Mainboard/clients/script.ml +++ b/PC_Mainboard/clients/script.ml @@ -43,6 +43,8 @@ let commands = [ args = [("card", Arg_keyword ["interface"; "sensor"; "motor"])] }; { name = "reset"; args = [("card", Arg_keyword ["interface"; "sensor"; "motor"])] }; + { name = "get-calibration"; + args = [("range-finder", Arg_int)] }; ] let set_of_list l = List.fold_left (fun set x -> TextSet.add x set) TextSet.empty l @@ -149,6 +151,10 @@ let exec krobot line = | "motor" -> `Motor | "sensor" -> `Sensor | _ -> failwith "Script.exec: invalid card") + | "get-calibration" -> + lwt cal = Krobot.get_calibration krobot (arg_int "range-finder" 0) in + Log#notice "calibration: %s" (String.concat " " (List.map string_of_int (Array.to_list cal))); + return () | _ -> Log#error "unknown command %S" action; return () diff --git a/PC_Mainboard/driver/commands.ml b/PC_Mainboard/driver/commands.ml index 8524f16..4ca774b 100644 --- a/PC_Mainboard/driver/commands.ml +++ b/PC_Mainboard/driver/commands.ml @@ -67,6 +67,14 @@ struct RW.set_uint8 data 0 Protocol.get_rangefinder_state; lwt data = Card.send_request card Protocol.cmd_get data in return (Array.init 8 (fun i -> RW.get_int32 data (i * 4))) + + let get_calibration card num = + if num < 0 || num > 7 then invalid_arg "Commands.Range_finders.get_calibration"; + let data = Card.make_buffer () in + RW.set_uint8 data Protocol.get_rangefinder_calibration; + RW.set_uint8 data num; + lwt data = Card.send_request card Protocol.cmd_get data in + return (Array.init 8 (fun i -> RW.get_uint8 data i)) end module Motor = diff --git a/PC_Mainboard/driver/commands.mli b/PC_Mainboard/driver/commands.mli index ac1fe16..1b7ff04 100644 --- a/PC_Mainboard/driver/commands.mli +++ b/PC_Mainboard/driver/commands.mli @@ -30,6 +30,7 @@ end module Range_finders : sig val get : Card.t -> int array Lwt.t + val get_calibration : Card.t -> int -> int array Lwt.t end module Motor : sig diff --git a/PC_Mainboard/driver/driver.ml b/PC_Mainboard/driver/driver.ml index 1a7f4f1..3d7bab0 100644 --- a/PC_Mainboard/driver/driver.ml +++ b/PC_Mainboard/driver/driver.ml @@ -149,6 +149,8 @@ struct OL_signal Value : int array OL_method Get : int array = fun dev -> return dev.data + OL_method GetCalibration : int -> int array = fun dev num -> + Commands.Range_finders.get_calibration dev.card num let rec loop dev = lwt data = Commands.Range_finders.get dev.card in diff --git a/PC_Mainboard/lib_krobot/krobot.ml b/PC_Mainboard/lib_krobot/krobot.ml index 5ecd375..8d2ec2e 100644 --- a/PC_Mainboard/lib_krobot/krobot.ml +++ b/PC_Mainboard/lib_krobot/krobot.ml @@ -157,6 +157,14 @@ let jack krobot = React.S.map (fun ls -> ls.(15)) krobot.logic_sensors (* +-----------------------------------------------------------------+ + | Range finders | + +-----------------------------------------------------------------+ *) + +include MakeDevice(struct let name = "RangeFinders" end) + +OP_method GetCalibration : int -> int array + +(* +-----------------------------------------------------------------+ | AX12 | +-----------------------------------------------------------------+ *) diff --git a/PC_Mainboard/lib_krobot/krobot.mli b/PC_Mainboard/lib_krobot/krobot.mli index 6561470..86e6b08 100644 --- a/PC_Mainboard/lib_krobot/krobot.mli +++ b/PC_Mainboard/lib_krobot/krobot.mli @@ -51,6 +51,10 @@ val jack : t -> bool React.signal val range_finders : t -> int array React.signal (** Signal holding the current range finders state *) +val get_calibration : t -> int -> int array Lwt.t + (** [get_calibration krobot num] returns the calibration of the + given range finder. *) + (** {6 Manipulation of AX12s} *) val ax12_goto : t -> id : int -> pos : int -> speed : int -> unit Lwt.t hooks/post-receive -- krobot |
From: Jérémie D. <Ba...@us...> - 2010-02-18 11:53:29
|
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 992d372526a6fc373535550469f66096caf4ee99 (commit) from 58105fc8cf98aaca1722ae26afa74968879c4b46 (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 992d372526a6fc373535550469f66096caf4ee99 Author: Jérémie Dimino <je...@di...> Date: Thu Feb 18 12:51:45 2010 +0100 [controllet] limit the frame rate to avoid Out_of_memory ----------------------------------------------------------------------- Changes: diff --git a/PC_Mainboard/_tags b/PC_Mainboard/_tags index 818fd97..6d352b3 100644 --- a/PC_Mainboard/_tags +++ b/PC_Mainboard/_tags @@ -55,6 +55,8 @@ <tools/forward_dbus.ml>: syntax_camlp4o, pkg_lwt.syntax, pkg_lwt.syntax.log, pkg_obus.syntax <tools/forward_dbus.*>: pkg_obus +<tools/flood.ml>: syntax_camlp4o, pkg_lwt.syntax, pkg_lwt.syntax.log, pkg_obus.syntax +<tools/flood.*>: pkg_obus # +------------------------------------------------------------------+ # | Tests | diff --git a/PC_Mainboard/clients/controller.ml b/PC_Mainboard/clients/controller.ml index 27b1d3f..32791c9 100644 --- a/PC_Mainboard/clients/controller.ml +++ b/PC_Mainboard/clients/controller.ml @@ -23,11 +23,12 @@ module TextSet = Set.Make(Text) let drawer_mutex = Lwt_mutex.create () (* Draw the whole screen *) -let rec draw size - (compass, logic_sensors, range_finders, team, jack) - (inhibited_forward_until, inhibited_backward_until) - (engine_state, box, logs) - (state_interface, state_sensor, state_motor) = +let rec draw + (size, + (engine_state, box, logs), + ((compass, logic_sensors, range_finders, team, jack), + (inhibited_forward_until, inhibited_backward_until), + (state_interface, state_sensor, state_motor))) = Lwt_mutex.with_lock drawer_mutex begin fun () -> if Lwt_mutex.is_empty drawer_mutex then begin (* Redraw the screen only if there is no other thread waiting to @@ -306,25 +307,28 @@ lwt () = in redirect_stderr (); let signal = - React.S.l5 draw - Lwt_term.size - (React.S.l5 (fun a b c d e -> (a, b, c, d, e)) - (Krobot.compass krobot) - (Krobot.logic_sensors krobot) - (Krobot.range_finders krobot) - (Krobot.team krobot) - (Krobot.jack krobot)) - (React.S.l2 (fun a b -> (a, b)) - (Krobot.inhibited_forward_until krobot) - (Krobot.inhibited_backward_until krobot)) + React.S.map draw (React.S.l3 (fun a b c -> (a, b, c)) - engine_state - box - logs) - (React.S.l3 (fun a b c -> (a, b, c)) - (Krobot.Card.state krobot `Interface) - (Krobot.Card.state krobot `Sensor) - (Krobot.Card.state krobot `Motor)) + Lwt_term.size + (React.S.l3 (fun a b c -> (a, b, c)) + engine_state + box + logs) + (Lwt_signal.limit (fun () -> Lwt_unix.sleep 0.1) + (React.S.l3 (fun a b c -> (a, b, c)) + (React.S.l5 (fun a b c d e -> (a, b, c, d, e)) + (Krobot.compass krobot) + (Krobot.logic_sensors krobot) + (Krobot.range_finders krobot) + (Krobot.team krobot) + (Krobot.jack krobot)) + (React.S.l2 (fun a b -> (a, b)) + (Krobot.inhibited_forward_until krobot) + (Krobot.inhibited_backward_until krobot)) + (React.S.l3 (fun a b c -> (a, b, c)) + (Krobot.Card.state krobot `Interface) + (Krobot.Card.state krobot `Sensor) + (Krobot.Card.state krobot `Motor))))) in lwt history = Lwt_read_line.load_history history_file_name in set_engine_state (Engine.init history); diff --git a/PC_Mainboard/myocamlbuild.ml b/PC_Mainboard/myocamlbuild.ml index b23d4cf..a6a42a2 100644 --- a/PC_Mainboard/myocamlbuild.ml +++ b/PC_Mainboard/myocamlbuild.ml @@ -66,6 +66,7 @@ let targets = List.filter_opt (function (true, target) -> Some target | (false, (* Tools *) (have_lwt_unix && have_obus, "tools/forward_dbus.best"); + (have_lwt_unix && have_obus, "tools/flood.best"); (* Clients *) (have_lwt_unix && have_obus, "clients/info.best"); hooks/post-receive -- krobot |
From: Jérémie D. <Ba...@us...> - 2010-02-17 20:55:33
|
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 58105fc8cf98aaca1722ae26afa74968879c4b46 (commit) from 6745156ed1597623b6b73cb4da513875f04a357c (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 58105fc8cf98aaca1722ae26afa74968879c4b46 Author: Jérémie Dimino <je...@di...> Date: Wed Feb 17 21:55:07 2010 +0100 [controller] print logs in correct order ----------------------------------------------------------------------- Changes: diff --git a/PC_Mainboard/clients/controller.ml b/PC_Mainboard/clients/controller.ml index 5b1d480..27b1d3f 100644 --- a/PC_Mainboard/clients/controller.ml +++ b/PC_Mainboard/clients/controller.ml @@ -301,7 +301,7 @@ lwt () = (fun () -> (* Dump logs on abnormal exit: *) lwt () = restore_state () in - Lwt_list.iter_s Lwt_io.printl (React.S.value logs)) + Lwt_list.iter_s Lwt_io.printl (List.rev (React.S.value logs))) Lwt_main.exit_hooks in redirect_stderr (); hooks/post-receive -- krobot |
From: Jérémie D. <Ba...@us...> - 2010-02-17 20:49:48
|
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 6745156ed1597623b6b73cb4da513875f04a357c (commit) from 8a7d0ca23efcdaef4335200e175fbe686a52c23a (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 6745156ed1597623b6b73cb4da513875f04a357c Author: Jérémie Dimino <je...@di...> Date: Wed Feb 17 21:49:14 2010 +0100 [controller] print logs on abnormal termination ----------------------------------------------------------------------- Changes: diff --git a/PC_Mainboard/clients/controller.ml b/PC_Mainboard/clients/controller.ml index 469f514..5b1d480 100644 --- a/PC_Mainboard/clients/controller.ml +++ b/PC_Mainboard/clients/controller.ml @@ -216,6 +216,17 @@ let () = (React.S.map (fun state -> state.Engine.mode) engine_state) let logs, set_logs = React.S.create [] +let log line = + let rec truncate n = function + | [] -> + [] + | line :: rest -> + if n = 1024 then + [] + else + line :: truncate (n + 1) rest + in + set_logs (line :: truncate 0 (React.S.value logs)) let history_file_name = Filename.concat (try Unix.getenv "HOME" with _ -> "") ".krobot-controller-history" @@ -256,7 +267,7 @@ let rec loop krobot history = let rec copy_logs ic = lwt line = Lwt_io.read_line ic in - set_logs (line :: React.S.value logs); + log line; copy_logs ic let redirect_stderr () = @@ -275,7 +286,7 @@ let redirect_stderr () = Lwt_log.render ~buffer ~level ~message:line ~template:"$(date): $(message)"; Buffer.contents buffer) lines in - set_logs (lines @ React.S.value logs); + List.iter log lines; return ()) ~close:return () @@ -283,35 +294,41 @@ let redirect_stderr () = lwt () = Log#notice "connecting to the krobot bus..."; lwt krobot = Krobot.create () in - try_lwt - lwt () = save_state () in - lwt () = hide_cursor () in - redirect_stderr (); - let signal = - React.S.l5 draw - Lwt_term.size - (React.S.l5 (fun a b c d e -> (a, b, c, d, e)) - (Krobot.compass krobot) - (Krobot.logic_sensors krobot) - (Krobot.range_finders krobot) - (Krobot.team krobot) - (Krobot.jack krobot)) - (React.S.l2 (fun a b -> (a, b)) - (Krobot.inhibited_forward_until krobot) - (Krobot.inhibited_backward_until krobot)) - (React.S.l3 (fun a b c -> (a, b, c)) - engine_state - box - logs) - (React.S.l3 (fun a b c -> (a, b, c)) - (Krobot.Card.state krobot `Interface) - (Krobot.Card.state krobot `Sensor) - (Krobot.Card.state krobot `Motor)) - in - (* Make the compiler happy: *) - ignore signal; - lwt history = Lwt_read_line.load_history history_file_name in - set_engine_state (Engine.init history); - Lwt_term.with_raw_mode (fun () -> loop krobot history) - finally - restore_state () + lwt () = save_state () in + lwt () = hide_cursor () in + let node = + Lwt_sequence.add_l + (fun () -> + (* Dump logs on abnormal exit: *) + lwt () = restore_state () in + Lwt_list.iter_s Lwt_io.printl (React.S.value logs)) + Lwt_main.exit_hooks + in + redirect_stderr (); + let signal = + React.S.l5 draw + Lwt_term.size + (React.S.l5 (fun a b c d e -> (a, b, c, d, e)) + (Krobot.compass krobot) + (Krobot.logic_sensors krobot) + (Krobot.range_finders krobot) + (Krobot.team krobot) + (Krobot.jack krobot)) + (React.S.l2 (fun a b -> (a, b)) + (Krobot.inhibited_forward_until krobot) + (Krobot.inhibited_backward_until krobot)) + (React.S.l3 (fun a b c -> (a, b, c)) + engine_state + box + logs) + (React.S.l3 (fun a b c -> (a, b, c)) + (Krobot.Card.state krobot `Interface) + (Krobot.Card.state krobot `Sensor) + (Krobot.Card.state krobot `Motor)) + in + lwt history = Lwt_read_line.load_history history_file_name in + set_engine_state (Engine.init history); + lwt () = Lwt_term.with_raw_mode (fun () -> loop krobot history) in + React.S.stop signal; + Lwt_sequence.remove node; + restore_state () hooks/post-receive -- krobot |
From: Jérémie D. <Ba...@us...> - 2010-02-17 20:20:56
|
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 8a7d0ca23efcdaef4335200e175fbe686a52c23a (commit) via f983d690042d57af4aacfd3939b3498914a9d3a3 (commit) from f8512130a8770901d89f22a2498e67ac6f704ea2 (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 8a7d0ca23efcdaef4335200e175fbe686a52c23a Author: Jérémie Dimino <je...@di...> Date: Wed Feb 17 21:19:47 2010 +0100 [lib_krobot] better initialisation commit f983d690042d57af4aacfd3939b3498914a9d3a3 Author: Jérémie Dimino <je...@di...> Date: Wed Feb 17 13:29:10 2010 +0100 [controller] better initialisation ----------------------------------------------------------------------- Changes: diff --git a/PC_Mainboard/clients/controller.ml b/PC_Mainboard/clients/controller.ml index 7ed5956..469f514 100644 --- a/PC_Mainboard/clients/controller.ml +++ b/PC_Mainboard/clients/controller.ml @@ -259,30 +259,34 @@ let rec copy_logs ic = set_logs (line :: React.S.value logs); copy_logs ic +let redirect_stderr () = + let fdr, fdw = Unix.pipe () in + Unix.dup2 fdw Unix.stderr; + Unix.close fdw; + ignore (copy_logs (Lwt_io.of_unix_fd ~mode:Lwt_io.input fdr)); + (* Logs to the log window: *) + Lwt_log.default := + Lwt_log.make + ~output:(fun level lines -> + let buffer = Buffer.create 128 in + let lines = + List.map (fun line -> + Buffer.clear buffer; + Lwt_log.render ~buffer ~level ~message:line ~template:"$(date): $(message)"; + Buffer.contents buffer) lines + in + set_logs (lines @ React.S.value logs); + return ()) + ~close:return + () + lwt () = - lwt () = save_state () in - lwt () = hide_cursor () in + Log#notice "connecting to the krobot bus..."; + lwt krobot = Krobot.create () in try_lwt - let fdr, fdw = Unix.pipe () in - Unix.dup2 fdw Unix.stderr; - Unix.close fdw; - ignore (copy_logs (Lwt_io.of_unix_fd ~mode:Lwt_io.input fdr)); - (* Logs to the log window: *) - Lwt_log.default := - Lwt_log.make - ~output:(fun level lines -> - let buffer = Buffer.create 128 in - let lines = - List.map (fun line -> - Buffer.clear buffer; - Lwt_log.render ~buffer ~level ~message:line ~template:"$(date): $(message)"; - Buffer.contents buffer) lines - in - set_logs (lines @ React.S.value logs); - return ()) - ~close:return - (); - lwt krobot = Krobot.create () in + lwt () = save_state () in + lwt () = hide_cursor () in + redirect_stderr (); let signal = React.S.l5 draw Lwt_term.size diff --git a/PC_Mainboard/driver/driver.ml b/PC_Mainboard/driver/driver.ml index adc9951..1a7f4f1 100644 --- a/PC_Mainboard/driver/driver.ml +++ b/PC_Mainboard/driver/driver.ml @@ -427,6 +427,15 @@ struct | Some card -> Card.close card + OL_method CardStates : OBus_connection.t -> Types.card_state * Types.card_state * Types.card_state = fun () connection -> + let state card = match React.S.value card with + | Some _ -> `Present + | None -> `Absent + in + return (state card_interface, + state card_sensor, + state card_motor) + OL_method Shutdown : OBus_connection.t -> unit = fun () connection -> Log#info "exiting"; quit := true; diff --git a/PC_Mainboard/lib_krobot/krobot.ml b/PC_Mainboard/lib_krobot/krobot.ml index 8be64e7..5ecd375 100644 --- a/PC_Mainboard/lib_krobot/krobot.ml +++ b/PC_Mainboard/lib_krobot/krobot.ml @@ -54,15 +54,27 @@ module MakeDevice(Name : sig val name : string end) = let name = "fr.krobot.Device." ^ Name.name end) -let make_dev_signal ~peer ~name ~update ~typ ~initial = +let make_dev_signal ~peer ~name ~get ~update ~typ ~default = let proxy = OBus_proxy.make peer ["fr"; "krobot"; "Devices"; name] in let interface = "fr.krobot.Device." ^ name in - React.S.hold initial (OBus_signal.connect proxy ~interface ~member:update typ)#event + lwt initial = + try_lwt + OBus_proxy.method_call proxy ~interface ~member:get (OBus_type.reply typ) + with exn -> + return default + in + return (React.S.hold initial (OBus_signal.connect proxy ~interface ~member:update typ)#event) -let make_card_signal ~peer ~name ~update ~typ ~initial = +let make_card_signal ~peer ~name ~get ~update ~typ ~default = let proxy = OBus_proxy.make peer ["fr"; "krobot"; "Cards"; name] in let interface = "fr.krobot.Card" in - React.S.hold initial (OBus_signal.connect proxy ~interface ~member:update typ)#event + lwt initial = + try_lwt + OBus_proxy.method_call proxy ~interface ~member:get (OBus_type.reply typ) + with exn -> + return default + in + return (React.S.hold initial (OBus_signal.connect proxy ~interface ~member:update typ)#event) (* +-----------------------------------------------------------------+ | Creation | @@ -108,16 +120,24 @@ let create ?peer () = lwt bus = get_bus () in return (OBus_peer.make bus "fr.krobot") in + lwt compass = make_dev_signal peer "Compass" "Get" "Value" <:obus_type< int >> 0 + and logic_sensors = make_dev_signal peer "LogicSensors" "Get" "Value" <:obus_type< bool array >> (Array.make 16 false) + and range_finders = make_dev_signal peer "RangeFinders" "Get" "Value" <:obus_type< int array >> (Array.make 8 0) + and inhibited_forward_until = make_dev_signal peer "Motors" "InhibitedForward" "InhibitedForwardChanged" <:obus_type< float >> 0. + and inhibited_backward_until = make_dev_signal peer "Motors" "InhibitedBackward" "InhibitedBackwardChanged" <:obus_type< float >> 0. + and card_interface = make_card_signal peer "Interface" "GetState" "StateChanged" <:obus_type< Types.card_state >> `Absent + and card_sensor = make_card_signal peer "Sensor" "GetState" "StateChanged" <:obus_type< Types.card_state >> `Absent + and card_motor = make_card_signal peer "Motor" "GetState" "StateChanged" <:obus_type< Types.card_state >> `Absent in return { peer = peer; - compass = make_dev_signal peer "Compass" "Value" <:obus_type< int >> 0; - logic_sensors = make_dev_signal peer "LogicSensors" "Value" <:obus_type< bool array >> (Array.make 16 false); - range_finders = make_dev_signal peer "RangeFinders" "Value" <:obus_type< int array >> (Array.make 8 0); - inhibited_forward_until = make_dev_signal peer "Motors" "InhibitedForwardChanged" <:obus_type< float >> 0.; - inhibited_backward_until = make_dev_signal peer "Motors" "InhibitedBackwardChanged" <:obus_type< float >> 0.; - interface = { card_state = make_card_signal peer "Interface" "StateChanged" <:obus_type< Types.card_state >> `Absent }; - sensor = { card_state = make_card_signal peer "Sensor" "StateChanged" <:obus_type< Types.card_state >> `Absent }; - motor = { card_state = make_card_signal peer "Motor" "StateChanged" <:obus_type< Types.card_state >> `Absent }; + compass = compass; + logic_sensors = logic_sensors; + range_finders = range_finders; + inhibited_forward_until = inhibited_forward_until; + inhibited_backward_until = inhibited_backward_until; + interface = { card_state = card_interface }; + sensor = { card_state = card_sensor }; + motor = { card_state = card_motor }; } (* +-----------------------------------------------------------------+ hooks/post-receive -- krobot |
From: Jérémie D. <Ba...@us...> - 2010-02-17 10:53:50
|
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 f8512130a8770901d89f22a2498e67ac6f704ea2 (commit) from d69354ad74e6873b0ace333f84262823423a22f5 (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 f8512130a8770901d89f22a2498e67ac6f704ea2 Author: Jérémie Dimino <je...@di...> Date: Wed Feb 17 11:53:22 2010 +0100 [controller] add history saving/loading ----------------------------------------------------------------------- Changes: diff --git a/PC_Mainboard/clients/controller.ml b/PC_Mainboard/clients/controller.ml index ac3f1ad..7ed5956 100644 --- a/PC_Mainboard/clients/controller.ml +++ b/PC_Mainboard/clients/controller.ml @@ -217,16 +217,22 @@ let () = let logs, set_logs = React.S.create [] +let history_file_name = + Filename.concat (try Unix.getenv "HOME" with _ -> "") ".krobot-controller-history" + +let save_history history = + Lwt_read_line.save_history history_file_name history + let rec loop krobot history = lwt key = read_key () in if key = key_escape then - return () + save_history history else match Command.of_key key with | Command.Accept_line -> let line = Text.strip (Engine.all_input (React.S.value engine_state)) in if line = "exit" then - return () + save_history history else begin let history = Lwt_read_line.add_entry line history in set_engine_state (Engine.init history); @@ -300,6 +306,8 @@ lwt () = in (* Make the compiler happy: *) ignore signal; - Lwt_term.with_raw_mode (fun () -> loop krobot []) + lwt history = Lwt_read_line.load_history history_file_name in + set_engine_state (Engine.init history); + Lwt_term.with_raw_mode (fun () -> loop krobot history) finally restore_state () hooks/post-receive -- krobot |
From: Jérémie D. <Ba...@us...> - 2010-02-17 10:41:01
|
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 d69354ad74e6873b0ace333f84262823423a22f5 (commit) from f154a57184070e984b23b05b8254f0240b691a0f (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 d69354ad74e6873b0ace333f84262823423a22f5 Author: Jérémie Dimino <je...@di...> Date: Wed Feb 17 11:39:38 2010 +0100 [lib_krobot] handle the case when cards are initially absent ----------------------------------------------------------------------- Changes: diff --git a/PC_Mainboard/clients/script.ml b/PC_Mainboard/clients/script.ml index d9999d2..24d90cc 100644 --- a/PC_Mainboard/clients/script.ml +++ b/PC_Mainboard/clients/script.ml @@ -89,7 +89,7 @@ let complete ~before ~after = end | `Arg(before, name, args, `Nothing) -> raise Exit - with Exit -> + with Exit | Script_lexer.Parse_failure _ -> { Lwt_read_line.comp_state = (before, after); Lwt_read_line.comp_words = TextSet.empty } @@ -152,6 +152,13 @@ let exec krobot line = | _ -> Log#error "unknown command %S" action; return () - with exn -> - Log#exn exn "command failed with"; - fail exn + with + | Script_lexer.Parse_failure msg -> + Log#error "parse failure: %s" msg; + return () + | Failure msg -> + Log#error "command failed: %s" msg; + return () + | exn -> + Log#exn exn "command failed with"; + return () diff --git a/PC_Mainboard/clients/script_lexer.mll b/PC_Mainboard/clients/script_lexer.mll index 14f71a2..00676ce 100644 --- a/PC_Mainboard/clients/script_lexer.mll +++ b/PC_Mainboard/clients/script_lexer.mll @@ -9,6 +9,8 @@ { module TextSet = Set.Make(Text) + + exception Parse_failure of string } let lower = ['a'-'z'] let upper = ['A'-'Z'] @@ -39,7 +41,7 @@ rule command = parse let args, last = arguments buf lexbuf in `Arg(Buffer.contents buf, command, args, last) } | "" - { raise Exit } + { raise (Parse_failure "command expceted") } and arguments buf = parse | (blank+ as before) (maybe_ident as key) eof @@ -59,7 +61,7 @@ and whole_command = parse | blank* (ident as command) { (command, whole_arguments lexbuf) } | "" - { raise Exit } + { raise (Parse_failure "command expceted") } and whole_arguments = parse | blank+ (ident as key) blank* "=" blank* (value as value) diff --git a/PC_Mainboard/lib_krobot/krobot.ml b/PC_Mainboard/lib_krobot/krobot.ml index 6ff6b4b..8be64e7 100644 --- a/PC_Mainboard/lib_krobot/krobot.ml +++ b/PC_Mainboard/lib_krobot/krobot.ml @@ -54,22 +54,15 @@ module MakeDevice(Name : sig val name : string end) = let name = "fr.krobot.Device." ^ Name.name end) -(* Create a reactive signal from: - - - a [get] method - - an [update] signal -*) -let make_dev_signal ~peer ~name ~get ~update ~typ = +let make_dev_signal ~peer ~name ~update ~typ ~initial = let proxy = OBus_proxy.make peer ["fr"; "krobot"; "Devices"; name] in let interface = "fr.krobot.Device." ^ name in - lwt initial = OBus_proxy.method_call proxy ~interface ~member:get (OBus_type.reply typ) in - return (React.S.hold initial (OBus_signal.connect proxy ~interface ~member:update typ)#event) + React.S.hold initial (OBus_signal.connect proxy ~interface ~member:update typ)#event -let make_card_signal ~peer ~name ~get ~update ~typ = +let make_card_signal ~peer ~name ~update ~typ ~initial = let proxy = OBus_proxy.make peer ["fr"; "krobot"; "Cards"; name] in let interface = "fr.krobot.Card" in - lwt initial = OBus_proxy.method_call proxy ~interface ~member:get (OBus_type.reply typ) in - return (React.S.hold initial (OBus_signal.connect proxy ~interface ~member:update typ)#event) + React.S.hold initial (OBus_signal.connect proxy ~interface ~member:update typ)#event (* +-----------------------------------------------------------------+ | Creation | @@ -115,25 +108,16 @@ let create ?peer () = lwt bus = get_bus () in return (OBus_peer.make bus "fr.krobot") in - lwt compass = make_dev_signal peer "Compass" "Get" "Value" <:obus_type< int >> - and logic_sensors = make_dev_signal peer "LogicSensors" "Get" "Value" <:obus_type< bool array >> - and range_finders = make_dev_signal peer "RangeFinders" "Get" "Value" <:obus_type< int array >> - and interface_state = make_card_signal peer "Interface" "GetState" "StateChanged" <:obus_type< Types.card_state >> - and sensor_state = make_card_signal peer "Sensor" "GetState" "StateChanged" <:obus_type< Types.card_state >> - and motor_state = make_card_signal peer "Motor" "GetState" "StateChanged" <:obus_type< Types.card_state >> - and inhibited_forward_until = make_dev_signal peer "Motors" "InhibitedForward" "InhibitedForwardChanged" <:obus_type< float >> - and inhibited_backward_until = make_dev_signal peer "Motors" "InhibitedBackward" "InhibitedBackwardChanged" <:obus_type< float >> - in return { peer = peer; - compass = compass; - logic_sensors = logic_sensors; - range_finders = range_finders; - inhibited_forward_until = inhibited_forward_until; - inhibited_backward_until = inhibited_backward_until; - interface = { card_state = interface_state }; - sensor = { card_state = sensor_state }; - motor = { card_state = motor_state }; + compass = make_dev_signal peer "Compass" "Value" <:obus_type< int >> 0; + logic_sensors = make_dev_signal peer "LogicSensors" "Value" <:obus_type< bool array >> (Array.make 16 false); + range_finders = make_dev_signal peer "RangeFinders" "Value" <:obus_type< int array >> (Array.make 8 0); + inhibited_forward_until = make_dev_signal peer "Motors" "InhibitedForwardChanged" <:obus_type< float >> 0.; + inhibited_backward_until = make_dev_signal peer "Motors" "InhibitedBackwardChanged" <:obus_type< float >> 0.; + interface = { card_state = make_card_signal peer "Interface" "StateChanged" <:obus_type< Types.card_state >> `Absent }; + sensor = { card_state = make_card_signal peer "Sensor" "StateChanged" <:obus_type< Types.card_state >> `Absent }; + motor = { card_state = make_card_signal peer "Motor" "StateChanged" <:obus_type< Types.card_state >> `Absent }; } (* +-----------------------------------------------------------------+ hooks/post-receive -- krobot |
From: Jérémie D. <Ba...@us...> - 2010-02-17 09:14:48
|
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 f154a57184070e984b23b05b8254f0240b691a0f (commit) from 285fe8ac86e7530b38627aa816aa6c3dbd893d10 (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 f154a57184070e984b23b05b8254f0240b691a0f Author: Jérémie Dimino <je...@di...> Date: Wed Feb 17 10:14:24 2010 +0100 [controller] remvoe some old stuff ----------------------------------------------------------------------- Changes: diff --git a/PC_Mainboard/clients/controller.ml b/PC_Mainboard/clients/controller.ml index f694bba..ac3f1ad 100644 --- a/PC_Mainboard/clients/controller.ml +++ b/PC_Mainboard/clients/controller.ml @@ -19,41 +19,6 @@ module TextSet = Set.Make(Text) | Drawing | +-----------------------------------------------------------------+ *) -type section = { - screen : point array array; - x : int; - y : int; - w : int; - h : int; -} - -let get_point clip x y = - if x >= 0 && x < clip.w && y >= 0 && y < clip.h then - clip.screen.(clip.y + y).(clip.x + x) - else - blank - -let set_point clip x y point = - if x >= 0 && x < clip.w && y >= 0 && y < clip.h then - clip.screen.(clip.y + y).(clip.x + x) <- point - -let draw_text clip ?style x y txt = - if y >= 0 && y < clip.h && x < clip.w then - let rec loop x ptr = match Text.next ptr with - | None -> - () - | Some(ch, ptr) -> - if x >= 0 && x < clip.w then begin - match style with - | Some style -> - clip.screen.(clip.y + y).(clip.x + x) <- { char = ch; style = style } - | None -> - clip.screen.(clip.y + y).(clip.x + x) <- { blank with char = ch }; - end; - loop (x + 1) ptr - in - loop x (Text.pointer_l txt) - (* Prevent concurrent drawing: *) let drawer_mutex = Lwt_mutex.create () hooks/post-receive -- krobot |
From: Jérémie D. <Ba...@us...> - 2010-02-16 22:44:37
|
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 285fe8ac86e7530b38627aa816aa6c3dbd893d10 (commit) via db7de41d9108ecb6f06cccd0bdd90b634fe1dc4a (commit) via 10e03dcc5eec1847693344621c54cc9caa486b13 (commit) from 60ddcdf6fc72e9ca1906fb6b470b5ee4d98ed6ca (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 285fe8ac86e7530b38627aa816aa6c3dbd893d10 Author: Jérémie Dimino <je...@di...> Date: Tue Feb 16 23:43:56 2010 +0100 [joy_contorl] bugfixes commit db7de41d9108ecb6f06cccd0bdd90b634fe1dc4a Author: Jérémie Dimino <je...@di...> Date: Tue Feb 16 22:35:39 2010 +0100 Bugfixes in manual control commit 10e03dcc5eec1847693344621c54cc9caa486b13 Author: Jérémie Dimino <je...@di...> Date: Tue Feb 16 21:50:10 2010 +0100 [driver] stop motors on inactivity ----------------------------------------------------------------------- Changes: diff --git a/PC_Mainboard/clients/joy_control.ml b/PC_Mainboard/clients/joy_control.ml index 8c01b87..0eace2d 100644 --- a/PC_Mainboard/clients/joy_control.ml +++ b/PC_Mainboard/clients/joy_control.ml @@ -124,31 +124,56 @@ let try_call action f = Log#error "action %s failed with: %s" action msg; return () +let rec set_speed action krobot motor speed abort_waiter = + lwt () = choose [abort_waiter; try_call action (fun () -> Krobot.set_speed krobot ~motor ~speed ~acc:acceleration)] in + if speed = 0 then + return () + else begin + lwt () = select [abort_waiter; Lwt_unix.sleep (Config.stop_motors_delay /. 2.)] in + set_speed action krobot motor speed abort_waiter + end + let parent_loop krobot pipe = let rstop = ref false and lstop = ref false in + let rthread = ref (return ()) and lthread = ref (return ()) in + let rabort_wakener = ref None and labort_wakener = ref None in let rec loop () = Lwt_io.read_value pipe >>= function | KeyPressed KEY_ESCAPE -> return () | JoyRAxis n -> - if not !rstop then - lwt () = try_call "set-speed-right" (fun () -> Krobot.set_speed krobot ~motor:`Right ~speed:(n * axis_coef) ~acc:acceleration) in + if not !rstop then begin + begin match !rabort_wakener with + | None -> () + | Some w -> wakeup_exn w Exit + end; + let waiter, wakener = Lwt.wait () in + rabort_wakener := Some wakener; + rthread := set_speed "set-speed-right" krobot `Right (n * axis_coef) waiter; loop () - else + end else loop () | JoyLAxis n -> - if not !lstop then - lwt () = try_call "set-speed-left" (fun () -> Krobot.set_speed krobot ~motor:`Left ~speed:(n * axis_coef) ~acc:acceleration) in + if not !lstop then begin + begin match !labort_wakener with + | None -> () + | Some w -> wakeup_exn w Exit + end; + let waiter, wakener = Lwt.wait () in + labort_wakener := Some wakener; + lthread := set_speed "set-speed-left" krobot `Left (n * axis_coef) waiter; loop () - else + end else loop () | JoyButtonPressed ButtonL2 -> lstop := true; + cancel !lthread; lwt () = try_call "stop-left-motor" (fun () -> Krobot.stop_motors krobot ~motor:`Left ~mode:`Abrupt) in ignore (lwt () = Lwt_unix.sleep 1.0 in lstop := false; return ()); loop () | JoyButtonPressed ButtonR2 -> rstop := true; + cancel !rthread; lwt () = try_call "stop-right-motor" (fun () -> Krobot.stop_motors krobot ~motor:`Right ~mode:`Abrupt) in ignore (lwt () = Lwt_unix.sleep 1.0 in rstop := false; return ()); loop () diff --git a/PC_Mainboard/common/config.ml b/PC_Mainboard/common/config.ml index c248d6e..6c73d1d 100644 --- a/PC_Mainboard/common/config.ml +++ b/PC_Mainboard/common/config.ml @@ -13,3 +13,4 @@ let initial_position = 200 let bus_address = "unix:abstract=krobot" let update_delay = 0.05 let reopen_delay = 1.0 +let stop_motors_delay = 0.2 diff --git a/PC_Mainboard/common/config.mli b/PC_Mainboard/common/config.mli index 645ac10..f43c1eb 100644 --- a/PC_Mainboard/common/config.mli +++ b/PC_Mainboard/common/config.mli @@ -26,3 +26,7 @@ val update_delay : float val reopen_delay : float (** Time to wait before retrying to open a card *) + +val stop_motors_delay : float + (** Amount of time to wait after a set-speed command to stop the + motors *) diff --git a/PC_Mainboard/driver/driver.ml b/PC_Mainboard/driver/driver.ml index bd69ec1..adc9951 100644 --- a/PC_Mainboard/driver/driver.ml +++ b/PC_Mainboard/driver/driver.ml @@ -210,6 +210,12 @@ struct mutable speed_left : int; mutable speed_right : int; (* Speed when manually controlled (by the joystick for example) *) + + mutable stop_rthread : unit Lwt.t; + mutable stop_lthread : unit Lwt.t; + (* When manually setting speed with [set_speed], these threads stop + motors after a small delay, unless a new command is + received. *) } module OBus = OBus_object.Make(struct @@ -316,7 +322,21 @@ struct end else Commands.Motor.traj_change_velocity dev.card motor abs_speed dir in - Commands.Motor.traj_start dev.card motor + lwt () = Commands.Motor.traj_start dev.card motor in + (* Stop motors after a small delay *) + if motor = `Both || motor = `Left then begin + cancel dev.stop_lthread; + if speed <> 0 then + dev.stop_lthread <- (lwt () = Lwt_unix.sleep Config.stop_motors_delay in + stop_motors dev `Left `Smooth) + end; + if motor = `Both || motor = `Right then begin + cancel dev.stop_rthread; + if speed <> 0 then + dev.stop_rthread <- (lwt () = Lwt_unix.sleep Config.stop_motors_delay in + stop_motors dev `Right `Smooth) + end; + return () end OL_method StopMotors : Types.motor -> Types.stop_mode -> unit @@ -374,6 +394,8 @@ struct traj_completed = React.E.filter ((=) Protocol.traj_completed) commands; speed_left = 0; speed_right = 0; + stop_rthread = return (); + stop_lthread = return (); } in return dev end hooks/post-receive -- krobot |
From: Jérémie D. <Ba...@us...> - 2010-02-16 19:35:51
|
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 60ddcdf6fc72e9ca1906fb6b470b5ee4d98ed6ca (commit) via 459275da1eec8e551b033c2e280904a94ef05d56 (commit) from 31a63cff42edcdc0ad0302eb62a3bd4fad21bc26 (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 60ddcdf6fc72e9ca1906fb6b470b5ee4d98ed6ca Author: Olivier BICHLER <oli...@en...> Date: Tue Feb 16 20:34:42 2010 +0100 [driver] bugfixes commit 459275da1eec8e551b033c2e280904a94ef05d56 Author: Jérémie Dimino <je...@di...> Date: Tue Feb 16 19:18:10 2010 +0100 typos ----------------------------------------------------------------------- Changes: diff --git a/PC_Mainboard/clients/controller.ml b/PC_Mainboard/clients/controller.ml index f8817b0..f694bba 100644 --- a/PC_Mainboard/clients/controller.ml +++ b/PC_Mainboard/clients/controller.ml @@ -116,7 +116,7 @@ let rec draw size Draw.textf zone x 2 "compass = %d" compass; let text_of_state name = function | `Absent -> [fg lred; textf "%s card is absent" name] - | `Present -> [fg lred; textf "%s card is present" name] + | `Present -> [textf "%s card is present" name] in Draw.textc zone x 3 (text_of_state "interface" state_interface); Draw.textc zone x 4 (text_of_state "sensor" state_sensor); diff --git a/PC_Mainboard/driver/card.ml b/PC_Mainboard/driver/card.ml index cd8c920..1a9927c 100644 --- a/PC_Mainboard/driver/card.ml +++ b/PC_Mainboard/driver/card.ml @@ -167,7 +167,7 @@ let rec dispatch card = return (`Error exn) end >>= function | `Error exn -> - Log#exn exn "stop dispatching on %s card: %s" card.wrapper.name (Printexc.to_string exn); + Log#exn exn "stop dispatching on %s card" card.wrapper.name; lwt _ = abort card.wrapper exn in return () | `OK len -> diff --git a/PC_Mainboard/driver/driver.ml b/PC_Mainboard/driver/driver.ml index 06e11a1..bd69ec1 100644 --- a/PC_Mainboard/driver/driver.ml +++ b/PC_Mainboard/driver/driver.ml @@ -193,9 +193,6 @@ struct mutable acceleration : int; (* The current acceleration *) - mutable state : unit React.signal; - (* Reinit [acceleraation] to None when the card state changes *) - mutable inhibit_forward_until : float; mutable inhibit_backward_until : float; (* Date after which motor's inhition should be stopped *) @@ -370,7 +367,6 @@ struct obus = OBus_object.make path; card = card; acceleration = 0; - state = React.S.const (); inhibit_forward_until = 0.0; inhibit_backward_until = 0.0; move_state = Ms_static; @@ -491,40 +487,45 @@ end (* Continously try to open the card with given parameters *) let rec monitor_card ~name ~vendor_id ~product_id ~set on_up on_down = - try_bind - (fun () -> - return (USB.open_device_with ~vendor_id ~product_id)) - (fun handle -> - Log#info "%s card opened" name; - lwt () = - try_lwt - lwt card = Card.make name handle in - set (Some card); - Log#info "%s card is up and running" name; - lwt () = on_up card in - lwt result = Card.watch card in - set None; - lwt () = on_down () in - match result with - | `Closed -> - return () - | `Error exn -> - Log#exn exn "%s card crashed with" name; - return () - with exn -> - Log#exn exn "failed to initialise %s card" name; - return () - in - if !quit then - return () - else - monitor_card ~name ~vendor_id ~product_id ~set on_up on_down) - (fun exn -> - Log#exn exn "failed to open %s card" name; - if !quit then - return () - else - monitor_card ~name ~vendor_id ~product_id ~set on_up on_down) + match try `Handle(USB.open_device_with ~vendor_id ~product_id) with exn -> `Error exn with + | `Error exn -> + Log#exn exn "failed to open %s card" name; + restart_card ~name ~vendor_id ~product_id ~set on_up on_down + | `Handle handle -> + Log#info "%s card opened" name; + begin + try_lwt + lwt card = Card.make name handle in + return (`Card card) + with exn -> + return (`Error exn) + end >>= function + | `Card card -> + Log#info "%s card is up and running" name; + set (Some card); + lwt () = on_up card in + lwt result = Card.watch card in + set None; + lwt () = on_down () in + begin + match result with + | `Closed -> + () + | `Error exn -> + Log#exn exn "%s card crashed with" name + end; + restart_card ~name ~vendor_id ~product_id ~set on_up on_down + | `Error exn -> + Log#exn exn "failed to make %s card" name; + restart_card ~name ~vendor_id ~product_id ~set on_up on_down + +and restart_card ~name ~vendor_id ~product_id ~set on_up on_down = + if !quit then + return () + else begin + lwt () = Lwt_unix.sleep Config.reopen_delay in + monitor_card ~name ~vendor_id ~product_id ~set on_up on_down + end (* +-----------------------------------------------------------------+ | Entry point | @@ -583,7 +584,6 @@ lwt () = and () = AX12.OBus.export bus =|< AX12.make card ["fr"; "krobot"; "Devices"; "AX12"] in return ()) (fun () -> - OBus_object.remove_by_path bus ["fr"; "krobot"; "Cards"; "Interface"]; OBus_object.remove_by_path bus ["fr"; "krobot"; "Devices"; "Compass"]; OBus_object.remove_by_path bus ["fr"; "krobot"; "Devices"; "AX12"]; return ()) @@ -596,7 +596,6 @@ lwt () = and () = Range_finders.OBus.export bus =|< Range_finders.make card ["fr"; "krobot"; "Devices"; "RangeFinders"] in return ()) (fun () -> - OBus_object.remove_by_path bus ["fr"; "krobot"; "Cards"; "Sensor"]; OBus_object.remove_by_path bus ["fr"; "krobot"; "Devices"; "LogicSensors"]; OBus_object.remove_by_path bus ["fr"; "krobot"; "Devices"; "RangeFinders"]; return ()) @@ -609,7 +608,6 @@ lwt () = lwt () = Motors.OBus.export bus =|< Motors.make card ["fr"; "krobot"; "Devices"; "Motors"] in return ()) (fun () -> - OBus_object.remove_by_path bus ["fr"; "krobot"; "Cards"; "Motor"]; OBus_object.remove_by_path bus ["fr"; "krobot"; "Devices"; "Motors"]; return ()) end; @@ -620,6 +618,6 @@ lwt () = Manager.OBus.export bus (); - Log#info "ready, waiting for requests"; + Log#notice "ready, waiting for requests"; done_waiter end hooks/post-receive -- krobot |
From: Jérémie D. <Ba...@us...> - 2010-02-16 18:11:06
|
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 31a63cff42edcdc0ad0302eb62a3bd4fad21bc26 (commit) from 17e2475914c006b1b54860036bb0bf9f65aa4c0d (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 31a63cff42edcdc0ad0302eb62a3bd4fad21bc26 Author: Jérémie Dimino <je...@di...> Date: Tue Feb 16 19:10:36 2010 +0100 Adapt clients for the new driver ----------------------------------------------------------------------- Changes: diff --git a/PC_Mainboard/clients/controller.ml b/PC_Mainboard/clients/controller.ml index 29d6c3e..f8817b0 100644 --- a/PC_Mainboard/clients/controller.ml +++ b/PC_Mainboard/clients/controller.ml @@ -114,14 +114,13 @@ let rec draw size Draw.textf zone x 0 "team = %s" (match team with Krobot.Team_red -> "red" | Krobot.Team_green -> "green"); Draw.textf zone x 1 "jack = %s" (if jack then "present" else "absent"); Draw.textf zone x 2 "compass = %d" compass; - let string_of_state = function - | `Running -> "running" - | `Opening -> "opening" - | `Closed -> "closed" + let text_of_state name = function + | `Absent -> [fg lred; textf "%s card is absent" name] + | `Present -> [fg lred; textf "%s card is present" name] in - Draw.textf zone x 3 "interface card is %s" (string_of_state state_interface); - Draw.textf zone x 4 "sensor card is %s" (string_of_state state_sensor); - Draw.textf zone x 5 "motor card is %s" (string_of_state state_motor); + Draw.textc zone x 3 (text_of_state "interface" state_interface); + Draw.textc zone x 4 (text_of_state "sensor" state_sensor); + Draw.textc zone x 5 (text_of_state "motor" state_motor); let date = Unix.gettimeofday () in let string_of_motor_state until = if date < until then diff --git a/PC_Mainboard/clients/info.ml b/PC_Mainboard/clients/info.ml index 3fee081..99519db 100644 --- a/PC_Mainboard/clients/info.ml +++ b/PC_Mainboard/clients/info.ml @@ -14,19 +14,18 @@ open Lwt_io let print_card krobot card = match React.S.value (Krobot.Card.state krobot card) with - | `Running -> + | `Present -> lwt firmware_build = Krobot.Card.get_firmware_build krobot card and board_info = Krobot.Card.get_board_info krobot card in let name = Krobot.Card.name card in lwt () = printl "==========" in - lwt () = printlf "card.%s.state = running" name in + lwt () = printlf "card.%s.state = present" name in lwt () = printlf "card.%s.firmware_build = %s" name firmware_build in lwt () = printlf "card.%s.board_info = %s" name board_info in return () - | `Opening -> - printlf "card.%s.state = opening" (Krobot.Card.name card) - | `Closed -> - printlf "card.%s.state = closed" (Krobot.Card.name card) + | `Absent -> + lwt () = printl "==========" in + printlf "card.%s.state = absent" (Krobot.Card.name card) lwt () = lwt krobot = Krobot.create () in diff --git a/PC_Mainboard/common/types.ml b/PC_Mainboard/common/types.ml index cb42817..0a4f80a 100644 --- a/PC_Mainboard/common/types.ml +++ b/PC_Mainboard/common/types.ml @@ -28,9 +28,8 @@ let obus_stop_mode = OBus_type.mapping obus_int (`Abrupt, 1); (`Smooth, 2)] -type card_state = [ `Running | `Opening | `Closed ] +type card_state = [ `Present | `Absent ] let obus_card_state = OBus_type.mapping obus_int - [(`Running, 0); - (`Opening, 1); - (`Closed, 2)] + [(`Present, 0); + (`Absent, 1)] diff --git a/PC_Mainboard/common/types.mli b/PC_Mainboard/common/types.mli index 35eed37..53a3511 100644 --- a/PC_Mainboard/common/types.mli +++ b/PC_Mainboard/common/types.mli @@ -25,5 +25,5 @@ type motor = [ `Left | `Right | `Both ] with obus(basic) type stop_mode = [ `Off | `Abrupt | `Smooth ] with obus(basic) (** Mode for stopping motors *) -type card_state = [ `Running | `Opening | `Closed ] with obus(basic) +type card_state = [ `Present | `Absent ] with obus(basic) (** State of a card *) diff --git a/PC_Mainboard/driver/driver.ml b/PC_Mainboard/driver/driver.ml index f103fb2..06e11a1 100644 --- a/PC_Mainboard/driver/driver.ml +++ b/PC_Mainboard/driver/driver.ml @@ -12,8 +12,6 @@ open OBus_pervasives open Lwt -let crashed card = fail (Failure(Printf.sprintf "%s card has crashed" (Card.name card))) - (* +-----------------------------------------------------------------+ | Compass | +-----------------------------------------------------------------+ *) @@ -390,9 +388,9 @@ end let done_waiter, done_wakener = Lwt.wait () let quit = ref false -let card_interface = ref None -let card_sensor = ref None -let card_motor = ref None +let card_interface, set_card_interface = React.S.create None +let card_sensor, set_card_sensor = React.S.create None +let card_motor, set_card_motor = React.S.create None module Manager = struct @@ -405,7 +403,7 @@ struct include OBus.MakeInterface(struct let name = "fr.krobot.Manager" end) - let close card = match !card with + let close card = match React.S.value card with | None -> return () | Some card -> @@ -429,8 +427,10 @@ end module MCard = struct type t = { - card : Card.t; + card : Card.t option React.signal; obus : OBus_object.t; + name : string; + mutable state : unit Lwt.t React.signal; } module OBus = OBus_object.Make(struct @@ -440,26 +440,49 @@ struct include OBus.MakeInterface(struct let name = "fr.krobot.Card" end) - OL_property_r Name : string = fun card -> - return (Card.name card.card) + let get_card dev = match React.S.value dev.card with + | None -> + Printf.ksprintf failwith "%s card is not available" dev.name + | Some card -> + card + + OL_property_r Name : string = fun dev -> + return (Card.name (get_card dev)) + + OL_method GetState : Types.card_state = fun dev -> + match React.S.value dev.card with + | None -> + return `Absent + | Some _ -> + return `Present OL_method GetFirmwareBuild : string = fun dev -> - Commands.get_firmware_build dev.card + Commands.get_firmware_build (get_card dev) OL_method GetBoardInfo : string = fun dev -> - Commands.get_board_info dev.card + Commands.get_board_info (get_card dev) OL_method Bootloader : unit = fun dev -> - Commands.bootloader dev.card + Commands.bootloader (get_card dev) OL_method Reset : unit = fun dev -> - Commands.reset dev.card + Commands.reset (get_card dev) - let make card path = - return { + OL_signal StateChanged : Types.card_state + + let make name card path = + let dev = { card = card; obus = OBus_object.make path; - } + name = name; + state = React.S.const (return ()); + } in + dev.state <- React.S.map (function + | None -> + state_changed dev `Absent + | Some _ -> + state_changed dev `Present) card; + dev end (* +-----------------------------------------------------------------+ @@ -467,7 +490,7 @@ end +-----------------------------------------------------------------+ *) (* Continously try to open the card with given parameters *) -let rec monitor_card ~name ~vendor_id ~product_id ~var on_up on_down = +let rec monitor_card ~name ~vendor_id ~product_id ~set on_up on_down = try_bind (fun () -> return (USB.open_device_with ~vendor_id ~product_id)) @@ -476,11 +499,11 @@ let rec monitor_card ~name ~vendor_id ~product_id ~var on_up on_down = lwt () = try_lwt lwt card = Card.make name handle in - var := Some card; + set (Some card); Log#info "%s card is up and running" name; lwt () = on_up card in lwt result = Card.watch card in - var := None; + set None; lwt () = on_down () in match result with | `Closed -> @@ -495,13 +518,13 @@ let rec monitor_card ~name ~vendor_id ~product_id ~var on_up on_down = if !quit then return () else - monitor_card ~name ~vendor_id ~product_id ~var on_up on_down) + monitor_card ~name ~vendor_id ~product_id ~set on_up on_down) (fun exn -> Log#exn exn "failed to open %s card" name; if !quit then return () else - monitor_card ~name ~vendor_id ~product_id ~var on_up on_down) + monitor_card ~name ~vendor_id ~product_id ~set on_up on_down) (* +-----------------------------------------------------------------+ | Entry point | @@ -553,11 +576,10 @@ lwt () = end; ignore begin - monitor_card ~name:"interace" ~vendor_id:Protocol.usb_vid ~product_id:Protocol.usb_pid_robot_interface ~var:card_interface + monitor_card ~name:"interace" ~vendor_id:Protocol.usb_vid ~product_id:Protocol.usb_pid_robot_interface ~set:set_card_interface (fun card -> lwt () = Commands.Motor.enable card in - lwt () = MCard.OBus.export bus =|< MCard.make card ["fr"; "krobot"; "Cards"; "Interface"] - and () = Compass.OBus.export bus =|< Compass.make card ["fr"; "krobot"; "Devices"; "Compass"] + lwt () = Compass.OBus.export bus =|< Compass.make card ["fr"; "krobot"; "Devices"; "Compass"] and () = AX12.OBus.export bus =|< AX12.make card ["fr"; "krobot"; "Devices"; "AX12"] in return ()) (fun () -> @@ -568,32 +590,34 @@ lwt () = end; ignore begin - monitor_card ~name:"motor" ~vendor_id:Protocol.usb_vid ~product_id:Protocol.usb_pid_motor_controller ~var:card_motor + monitor_card ~name:"sensor" ~vendor_id:Protocol.usb_vid ~product_id:Protocol.usb_pid_proximity_sensor ~set:set_card_sensor (fun card -> - lwt () = Commands.Motor.enable card and () = Commands.Motor.init_lm629 card in - lwt () = MCard.OBus.export bus =|< MCard.make card ["fr"; "krobot"; "Cards"; "Motor"] - and () = Motors.OBus.export bus =|< Motors.make card ["fr"; "krobot"; "Devices"; "Motors"] in + lwt () = Logic_sensors.OBus.export bus =|< Logic_sensors.make card ["fr"; "krobot"; "Devices"; "LogicSensors"] + and () = Range_finders.OBus.export bus =|< Range_finders.make card ["fr"; "krobot"; "Devices"; "RangeFinders"] in return ()) (fun () -> - OBus_object.remove_by_path bus ["fr"; "krobot"; "Cards"; "Motor"]; - OBus_object.remove_by_path bus ["fr"; "krobot"; "Devices"; "Motors"]; + OBus_object.remove_by_path bus ["fr"; "krobot"; "Cards"; "Sensor"]; + OBus_object.remove_by_path bus ["fr"; "krobot"; "Devices"; "LogicSensors"]; + OBus_object.remove_by_path bus ["fr"; "krobot"; "Devices"; "RangeFinders"]; return ()) end; ignore begin - monitor_card ~name:"sensor" ~vendor_id:Protocol.usb_vid ~product_id:Protocol.usb_pid_proximity_sensor ~var:card_sensor + monitor_card ~name:"motor" ~vendor_id:Protocol.usb_vid ~product_id:Protocol.usb_pid_motor_controller ~set:set_card_motor (fun card -> - lwt () = MCard.OBus.export bus =|< MCard.make card ["fr"; "krobot"; "Cards"; "Sensor"] - and () = Logic_sensors.OBus.export bus =|< Logic_sensors.make card ["fr"; "krobot"; "Devices"; "LogicSensors"] - and () = Range_finders.OBus.export bus =|< Range_finders.make card ["fr"; "krobot"; "Devices"; "RangeFinders"] in + lwt () = Commands.Motor.enable card and () = Commands.Motor.init_lm629 card in + lwt () = Motors.OBus.export bus =|< Motors.make card ["fr"; "krobot"; "Devices"; "Motors"] in return ()) (fun () -> - OBus_object.remove_by_path bus ["fr"; "krobot"; "Cards"; "Sensor"]; - OBus_object.remove_by_path bus ["fr"; "krobot"; "Devices"; "LogicSensors"]; - OBus_object.remove_by_path bus ["fr"; "krobot"; "Devices"; "RangeFinders"]; + OBus_object.remove_by_path bus ["fr"; "krobot"; "Cards"; "Motor"]; + OBus_object.remove_by_path bus ["fr"; "krobot"; "Devices"; "Motors"]; return ()) end; + MCard.OBus.export bus (MCard.make "interface" card_interface ["fr"; "krobot"; "Cards"; "Interface"]); + MCard.OBus.export bus (MCard.make "sensor" card_sensor ["fr"; "krobot"; "Cards"; "Sensor"]); + MCard.OBus.export bus (MCard.make "motor" card_motor ["fr"; "krobot"; "Cards"; "Motor"]); + Manager.OBus.export bus (); Log#info "ready, waiting for requests"; diff --git a/PC_Mainboard/lib_krobot/krobot.ml b/PC_Mainboard/lib_krobot/krobot.ml index 409f4ea..6ff6b4b 100644 --- a/PC_Mainboard/lib_krobot/krobot.ml +++ b/PC_Mainboard/lib_krobot/krobot.ml @@ -17,7 +17,7 @@ open Lwt type team = Team_red | Team_green type card = { - card_state : [ `Running | `Opening | `Closed ] React.signal; + card_state : Types.card_state React.signal; } type t = { diff --git a/PC_Mainboard/services/hard_stop.ml b/PC_Mainboard/services/hard_stop.ml index d2ee376..825e3f0 100644 --- a/PC_Mainboard/services/hard_stop.ml +++ b/PC_Mainboard/services/hard_stop.ml @@ -47,7 +47,7 @@ lwt () = ~level:(min Lwt_log.Info Lwt_log.default_level) ~facility:`Daemon (); - Lwt_unix.daemonize ~keep_stderr:true () + Lwt_daemon.daemonize () end; lwt krobot = Krobot.create () in hooks/post-receive -- krobot |