From: Xavier L. <Ba...@us...> - 2010-03-20 14:39: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, motor-nurbs has been updated via 9f4b4583c8aa2e1bd14038afcbd19e061060734b (commit) via f2213bbbf674944c0d841ddb4a7e71d25010bb2e (commit) via 6d667aa1190fcbab5bf284bb921129d239df39b9 (commit) via 0f754d34defcbaa0180012827c71847682968dd9 (commit) via 42ee6b34f06bbb6522cda0d5984944c331e8efa1 (commit) via 2a9f596f387f876e0b9b2aceed83511abb9424fc (commit) via b0f2e736cd7b641239b051f3cffd96e827fccfdb (commit) via 629b4193197faaabf9d7805973df102491af678f (commit) via 53a4fc48142731ae7b198ba19c3fb25e5db1f677 (commit) via f1d6828404338c20cc8d364f6d7b91781326c1aa (commit) via ae44815bfc0c54ff4b99e56c1ed95498973bbc49 (commit) via 1a98cc1a882658e4100bc99f990fd972304ed99e (commit) via 634f84d90d057f6820a840877038335e9984c830 (commit) via 93013eb819e3abe48ddd1b9794f2d1178395dc68 (commit) via cfc472d8d590b902b4cd16f2d931f62f5677666d (commit) via edf08efe16e1a8a7154641c1fd3005da2f729eeb (commit) via 6a511b012683824b3ec4a3a6b8efda3ee6a237ae (commit) via 58d387423da6e5090bd789065925eac1bf937c5c (commit) via 6795c8d0a9e01b24e1762dd433acc9c48591d393 (commit) via 1df5dc2b427b81fa86804859729ac50f2bcc4377 (commit) via bef19507734097c59756c638a4e7c3b5c8a93371 (commit) via e19264e5e9597d461f24a930b74a1e5034a3a1e4 (commit) via 0c7d257797c48e7e3c60e1c39832214d3cb6f1a4 (commit) via d86af02d7116d36400cf76eaf1b67ffde1a25691 (commit) via 2b26e9ac62a42f86b2e0f92f45b747077ad115f4 (commit) via 43e3061d573cb3f9d03581fc101dc4da46a6941a (commit) via 40d7e9b7b1788708da82a356bd671dd6dbccf68f (commit) via 973aff6d5670f48ceba7442182bcfbdd46e1cf33 (commit) via 88400b5b6737719639fd1ee69fc4b1a9567ab6f3 (commit) via d1bc3f760c9bcaabdb89b83a2d757777a262448d (commit) via bba0433fac2aeb548186bb883b0016fa3583f8c1 (commit) via 6979c0aaac3d8e3225bde86295cbf178e973dafc (commit) via 241c1227982a011ed5387a18dfeae7386e3e9255 (commit) via 3e1aae398963d2424a80c545b19fb0ce3a336c52 (commit) via c654c37eb3a98e2e6178aea67ede87f45f06e2b5 (commit) via ccf8cfd83333c0cbaa929ed8290b564b9401ec7e (commit) via a35db5cb7075a815e8b9d6b3d82529886dd5b70c (commit) via d329a635dc981f9c3cfc984f950dc8eaa9a1fbce (commit) via 94e87a11b68b9753ed5725e75bec5b8298cbe67b (commit) via 1d5ebfa1823c3bccc8dbd250c9b231aaedaa7887 (commit) via 2a834df76aa8ddbca0617408865686f18f99dbab (commit) via 64de58caa3d4bfea3fb420871ae0f090080b694a (commit) via 61f9eb71c06e9e9f33994eef5a47029db8a07baa (commit) via 898dd1a410781431143f0c21e6158de5c4b7624c (commit) via 8902813f33971db1de012160557c87b34a52e8c7 (commit) via ea6ee177b5f55f2c5c1c62c647962596786000a0 (commit) via 6c4e8c5630ad64620ea8228a0a4c56d50b02571f (commit) via 19398dd4d385b2ce50f474cb573743d6ec7f70a6 (commit) via 34e5436fb905872556fa9d0c2f83be2c5764f9d6 (commit) via c0fdebb20f076b97225e3f4ceeb12a25e8895a12 (commit) via 8cc04bff36432dd8189d7c78585e8dd3bfead7aa (commit) via a6e8536a3b19b3d0de30a97cf8ea60ccfddce72e (commit) via 3f23696522eefa513a92a375459c998e5899df2d (commit) via 47260998a8e90353bc2184ad640df1993da7c630 (commit) via 80fe5918d44c802611d6240b92b308dac6bb229a (commit) via a9944f99ef133be4a4f19cb4855833c1648ef6d3 (commit) via 53198a8d5d1d8f51dc3d817a03443aebc4987cce (commit) via 9958104ae2f54521a51358de5ed2ceda0b9b9ba4 (commit) via cdc425a8c48cc4414de80fd9f8c695c2ad92ef7d (commit) via f210a0e3676c019eec203c614a66a685a24d1f7a (commit) via 605fdc677788b43a9549798ac4e4afc0702e1aee (commit) via ec4edc47e210a512d7cb447fb93b4428a5c93cf3 (commit) via ed8ac2f3d06d5a45df789be0c871e252a08ff60c (commit) via f3121e926476263b9b9a082afdfbbd93643149de (commit) via beb30006c75b3a879ce8bbef232f68675743d55a (commit) via 3d05cb1b4e6b5a7976548aab8e639572d47d57ab (commit) via 2e41773908b10cad366a5395fa1f35b5477a1b6a (commit) via d0d1b4f316d589f5b6fe73acb68a160acda7bc7c (commit) via 59f35c0d7c2f0bd92c9ac23fc6d0c6d347833723 (commit) via 81a5f63a2c90f5b3fa53cbc452e6764619d920fa (commit) via dd313e5ea3e145e3516b4765ab9028d78f8d0dc7 (commit) from 5f1263fc05729c7457e97b0c697a120101edfa93 (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 9f4b4583c8aa2e1bd14038afcbd19e061060734b Merge: 5f1263fc05729c7457e97b0c697a120101edfa93 f2213bbbf674944c0d841ddb4a7e71d25010bb2e Author: Xavier Lagorce <Xav...@cr...> Date: Sat Mar 20 15:38:24 2010 +0100 Merge branch 'master' into motor-nurbs Binary firmwares were rebuild and are firmwares from the current merged branch ----------------------------------------------------------------------- Changes: diff --git a/PC_Mainboard/META b/PC_Mainboard/META new file mode 100644 index 0000000..3a4d1c1 --- /dev/null +++ b/PC_Mainboard/META @@ -0,0 +1,9 @@ +# -*- conf -*- +name = "krobot" +version = "0.1" +description = "Krobot client library" +requires = "obus" +archive(byte) = "krobot.cma" +archive(native) = "krobot.cmxa" +archive(plugin,byte) = "krobot.cma" +archive(plugin,native) = "krobot.cmxs" diff --git a/PC_Mainboard/Makefile b/PC_Mainboard/Makefile index 96a8d60..026a6a4 100644 --- a/PC_Mainboard/Makefile +++ b/PC_Mainboard/Makefile @@ -24,6 +24,14 @@ clean: .PHONY: install install: + $(OF) install krobot META \ + lib_krobot/krobot.mli \ + $(wildcard _build/lib_krobot/*.cmi) \ + $(wildcard _build/lib_krobot/*.cmx) \ + $(wildcard _build/*.cma) \ + $(wildcard _build/*.cmxa) \ + $(wildcard _build/*.cmxs) \ + $(wildcard _build/*.a) install -m 0755 _build/card_tools/send_firmware.best $(PREFIX)/bin/krobot-send-firmware install -m 0755 _build/card_tools/dump_memory.best $(PREFIX)/bin/krobot-dump-memory install -m 0755 _build/tools/forward_dbus.best $(PREFIX)/bin/krobot-forward-dbus @@ -35,6 +43,7 @@ install: .PHONY: uninstall uninstall: + $(OF) remove krobot rm -vf $(PREFIX)/bin/krobot-* .PHONY: reinstall diff --git a/PC_Mainboard/_tags b/PC_Mainboard/_tags index 2b3245a..0d628c0 100644 --- a/PC_Mainboard/_tags +++ b/PC_Mainboard/_tags @@ -38,8 +38,8 @@ # | Common | # +------------------------------------------------------------------+ -<common/{types,util}.{ml,mli}>: syntax_camlp4o, pkg_obus.syntax, pkg_lwt.syntax -<common/{types,util}.*>: pkg_obus +<common/{krobot_types,util}.{ml,mli}>: syntax_camlp4o, pkg_obus.syntax, pkg_lwt.syntax +<common/{krobot_types,util}.*>: pkg_obus # +------------------------------------------------------------------+ # | Driver | diff --git a/PC_Mainboard/card_tools/boardname.mll b/PC_Mainboard/card_tools/boardname.mll index 30f99cf..08df665 100644 --- a/PC_Mainboard/card_tools/boardname.mll +++ b/PC_Mainboard/card_tools/boardname.mll @@ -8,7 +8,7 @@ *) -let boardname_regex = ("Carte " | "Robot Interface") [^'\n']+ +let boardname_regex = ("Carte " | "Robot Interface" | "Battery Monitoring ") [^'\n']+ rule boardname = parse | (boardname_regex as name) '\n' { Some name } diff --git a/PC_Mainboard/card_tools/send_firmware.ml b/PC_Mainboard/card_tools/send_firmware.ml index 443036a..321edb6 100644 --- a/PC_Mainboard/card_tools/send_firmware.ml +++ b/PC_Mainboard/card_tools/send_firmware.ml @@ -41,7 +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 + lwt () = Bootloader.reset_board k in return () let _ = diff --git a/PC_Mainboard/clients/controller.ml b/PC_Mainboard/clients/controller.ml index a253a34..329f205 100644 --- a/PC_Mainboard/clients/controller.ml +++ b/PC_Mainboard/clients/controller.ml @@ -191,6 +191,8 @@ let rec draw krobot = fg line_color; text " ]─┬─[ "; fg name_color; text "Services"; fg line_color; text " ]─┬─[ "; + fg name_color; text "Cards"; + fg line_color; text " ]─┬─[ "; fg name_color; text "Status"; fg line_color; text " ]─"]; points.(9).(0) <- { line with char = "├" }; @@ -201,15 +203,16 @@ let rec draw krobot = for i = 1 to 8 do points.(i).(20) <- { line with char = "│" }; points.(i).(40) <- { line with char = "│" }; - points.(i).(55) <- { line with char = "│" } + points.(i).(55) <- { line with char = "│" }; + points.(i).(67) <- { line with char = "│" } done; - Draw.textc screen 1 9 [fg line_color; text "───────────────────┴───────────────────┴──────────────┴"]; + Draw.textc screen 1 9 [fg line_color; text "───────────────────┴───────────────────┴──────────────┴───────────┴"]; let zone = Zone.inner screen in let range_finders = React.S.value (Krobot.range_finders krobot) in for i = 0 to Array.length range_finders - 1 do - Draw.textf zone 0 i "%d : %d" i range_finders.(i) + Draw.textc zone 0 i [textf "%d : " i; text (Text.repeat (range_finders.(i) * 14 / 3146) "=")] done; let logic_sensors = React.S.value (Krobot.logic_sensors krobot) in @@ -231,18 +234,20 @@ let rec draw krobot = loop 0 (TextSet.elements (React.S.value services)); let x = 55 in + let text_of_state name = function + | `Absent -> [fg lred; text name] + | `Present -> [text name] + in + Draw.textc zone x 0 (text_of_state "interface" (React.S.value (Krobot.Card.state (krobot, `Interface)))); + Draw.textc zone x 1 (text_of_state "sensor" (React.S.value (Krobot.Card.state (krobot, `Sensor)))); + Draw.textc zone x 2 (text_of_state "motor" (React.S.value (Krobot.Card.state (krobot, `Motor)))); + Draw.textc zone x 3 (text_of_state "monitoring" (React.S.value (Krobot.Card.state (krobot, `Monitoring)))); + let x = x + 12 in Draw.textf zone x 0 "team = %s" (match React.S.value (Krobot.team krobot) with | Krobot.Team_red -> "red" | Krobot.Team_green -> "green"); Draw.textf zone x 1 "jack = %s" (if React.S.value (Krobot.jack krobot) then "present" else "absent"); Draw.textf zone x 2 "compass = %d" (React.S.value (Krobot.compass krobot)); - let text_of_state name = function - | `Absent -> [fg lred; textf "%s card is absent" name] - | `Present -> [textf "%s card is present" name] - in - Draw.textc zone x 3 (text_of_state "interface" (React.S.value (Krobot.Card.state krobot `Interface))); - Draw.textc zone x 4 (text_of_state "sensor" (React.S.value (Krobot.Card.state krobot `Sensor))); - Draw.textc zone x 5 (text_of_state "motor" (React.S.value (Krobot.Card.state krobot `Motor))); let date = Unix.gettimeofday () in let text_of_motor_state mode until = if date < until then @@ -250,8 +255,8 @@ let rec draw krobot = else [text mode; text "OK"] in - Draw.textc zone x 6 (text_of_motor_state "move forward: " (React.S.value (Krobot.inhibited_forward_until krobot))); - Draw.textc zone x 7 (text_of_motor_state "move backward: " (React.S.value (Krobot.inhibited_backward_until krobot))); + Draw.textc zone x 3 (text_of_motor_state "move forward: " (React.S.value (Krobot.inhibited_forward_until krobot))); + Draw.textc zone x 4 (text_of_motor_state "move backward: " (React.S.value (Krobot.inhibited_backward_until krobot))); (* ===== History ===== *) @@ -361,7 +366,7 @@ let refresh krobot = return () else begin refresh_needed := true; - lwt () = Lwt_main.fast_yield () in + lwt () = Lwt.pause () in refresh_needed := false; draw krobot; return () @@ -415,9 +420,9 @@ lwt () = notify (Krobot.jack krobot); notify (Krobot.inhibited_forward_until krobot); notify (Krobot.inhibited_backward_until krobot); - notify (Krobot.Card.state krobot `Interface); - notify (Krobot.Card.state krobot `Sensor); - notify (Krobot.Card.state krobot `Motor); + notify (Krobot.Card.state (krobot, `Interface)); + notify (Krobot.Card.state (krobot, `Sensor)); + notify (Krobot.Card.state (krobot, `Motor)); notify services; (* Redraw immedlatly the screen when [signal] changes: *) diff --git a/PC_Mainboard/clients/info.ml b/PC_Mainboard/clients/info.ml index 99519db..f2e8501 100644 --- a/PC_Mainboard/clients/info.ml +++ b/PC_Mainboard/clients/info.ml @@ -13,10 +13,10 @@ open Lwt open Lwt_io let print_card krobot card = - match React.S.value (Krobot.Card.state krobot card) with + match React.S.value (Krobot.Card.state (krobot , card)) with | `Present -> - lwt firmware_build = Krobot.Card.get_firmware_build krobot card - and board_info = Krobot.Card.get_board_info krobot card in + 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 = present" name in @@ -32,4 +32,5 @@ lwt () = lwt () = print_card krobot `Interface in lwt () = print_card krobot `Sensor in lwt () = print_card krobot `Motor in + lwt () = print_card krobot `Monitoring in return () diff --git a/PC_Mainboard/clients/init_position.ml b/PC_Mainboard/clients/init_position.ml index 0a4e6d9..4e74d75 100644 --- a/PC_Mainboard/clients/init_position.ml +++ b/PC_Mainboard/clients/init_position.ml @@ -28,7 +28,7 @@ lwt () = lwt () = move_backward_slowly krobot in lwt () = Log.notice "going to initial position on first axis" in - lwt _ = Krobot.move krobot ~distance:Config.initial_position ~velocity:400 ~acceleration:800 in + lwt _ = Krobot.move krobot ~distance:Krobot_config.initial_position ~velocity:400 ~acceleration:800 in lwt () = Log.notice "turning" in lwt _ = Krobot.turn krobot ~angle:(-90) ~velocity:400 ~acceleration:800 in @@ -36,7 +36,7 @@ lwt () = lwt () = move_backward_slowly krobot in lwt () = Log.notice "going to initial position on second axis" in - lwt _ = Krobot.move krobot ~distance:Config.initial_position ~velocity:400 ~acceleration:800 in + lwt _ = Krobot.move krobot ~distance:Krobot_config.initial_position ~velocity:400 ~acceleration:800 in lwt () = Log.notice "turning" in lwt _ = Krobot.turn krobot ~angle:45 ~velocity:400 ~acceleration:800 in diff --git a/PC_Mainboard/clients/script.ml b/PC_Mainboard/clients/script.ml index 614e73c..d38ea46 100644 --- a/PC_Mainboard/clients/script.ml +++ b/PC_Mainboard/clients/script.ml @@ -44,15 +44,20 @@ let args_of_command name = let rec after_prefix prefix path = match prefix, path with - | [], p -> Some p - | e1 :: p1, e2 :: p2 when e1 = e2 -> after_prefix p1 p2 - | _ -> None + | [], path -> + Some path + | e1 :: p1, e2 :: p2 when e1 = e2 -> + after_prefix p1 p2 + | [e1], e2 :: p2 when Text.starts_with e2 e1 -> + Some path + | _ -> + None let complete ~before ~after = try match Script_lexer.partial_command (Lexing.from_string before) with | `Command(before, name) -> begin - let full_path, path, name = + let full_path, path, basename = match Text.rev_split ~sep:"." ~max:2 name with | [] -> ("", [], "") @@ -75,12 +80,15 @@ let complete ~before ~after = (TextSet.add name paths, names)) (TextSet.empty, TextSet.empty) !commands) in - let prefix, words = Lwt_read_line.lookup name names in + let prefix, words = Lwt_read_line.lookup basename (TextSet.union paths names) in match TextSet.cardinal words with | 0 -> - Lwt_read_line.complete ~suffix:"." (before ^ full_path) name after paths + { Lwt_read_line.comp_state = (before ^ name, after); + Lwt_read_line.comp_words = words } | 1 -> - { Lwt_read_line.comp_state = (before ^ full_path ^ prefix ^ " ", after); + { Lwt_read_line.comp_state = (before ^ full_path ^ prefix ^ + (if TextSet.mem (TextSet.choose words) paths then "." else " "), + after); Lwt_read_line.comp_words = words } | _ -> { Lwt_read_line.comp_state = (before ^ full_path ^ prefix, after); @@ -183,12 +191,13 @@ let () = register "right" (f3 angle velocity acceleration) (fun logger krobot angle velocity acceleration -> Krobot.turn krobot (-angle) velocity acceleration >>= move_result logger); - register "goto" (f6 - (int ~default:0 "x") (int ~default:0 "y") velocity acceleration - (keyword ~default:`Straight "mode" [("straight", `Straight); - ("curve-left", `Curve_left); - ("curve-right", `Curve_right)]) - (int ~default:0 "bypass-distance")) + register"goto" + (f6 + (int ~default:0 "x") (int ~default:0 "y") velocity acceleration + (keyword ~default:`Straight "mode" [("straight", `Straight); + ("curve-left", `Curve_left); + ("curve-right", `Curve_right)]) + (int ~default:0 "bypass-distance")) (fun logger krobot x y velocity acceleration mode bypass -> Krobot.goto krobot x y velocity acceleration mode bypass >>= move_result logger); @@ -222,20 +231,21 @@ let () = let card = keyword "card" [("interface", `Interface); ("motor", `Motor); - ("sensor", `Sensor)] in + ("sensor", `Sensor); + ("monitoring", `Monitoring)] in - register "bootloader" (f1 card) - (fun logger -> Krobot.Card.bootloader); - register "reset" (f1 card) - (fun logger -> Krobot.Card.reset); - register "test" (f1 card) - (fun logger -> Krobot.Card.test); + register ~path:["card"] "bootloader" (f1 card) + (fun logger krobot card -> Krobot.Card.bootloader (krobot, card)); + register ~path:["card"] "reset" (f1 card) + (fun logger krobot card -> Krobot.Card.reset (krobot, card)); + register ~path:["card"] "test" (f1 card) + (fun logger krobot card -> Krobot.Card.test (krobot, card)); (* +---------------------------------------------------------------+ | Range finders | +---------------------------------------------------------------+ *) - register "get-calibration" f0 + register ~path:["calibration"] "get" f0 (fun logger krobot -> lwt cals = Lwt_list.map_p (Krobot.get_calibration krobot) [0; 1; 2; 3; 4; 5; 6; 7] in let rec loop i = function @@ -252,11 +262,11 @@ let () = in loop 0 cals); - register "calibration-start" (f2 (int "range-finder") (keyword "skip-meas" [("true", true); ("false", false)])) + register ~path:["calibration"] "start" (f2 (int "range-finder") (keyword "skip-meas" [("true", true); ("false", false)])) (fun logger -> Krobot.calibration_start); - register "calibration-stop" f0 + register ~path:["calibration"] "stop" f0 (fun logger -> Krobot.calibration_stop); - register "calibration-continue" f0 + register ~path:["calibration"] "continue" f0 (fun logger -> Krobot.calibration_continue); (* +---------------------------------------------------------------+ @@ -265,7 +275,7 @@ let () = let id = int "id" and position = int "position" - and velocity = int ~default:50 "velocity" + and velocity = int ~default:Krobot_config.ax12_default_velocity "velocity" and timeout = int ~default:100 "timeout" and goto_mode = keyword ~default:`Now "mode" [("now", `Now); ("action", `Action)] in @@ -292,16 +302,28 @@ let () = register ~path:["ax12"] "get-stats" (f2 id timeout) (fun logger krobot id timeout -> lwt stats = Krobot_unsafe.AX12.get_stats krobot id timeout in - lwt () = logger [textf "ax12[%d] position = %d" id stats.Types.ax12_position] in - lwt () = logger [textf "ax12[%d] velocity = %d" id stats.Types.ax12_velocity] in - lwt () = logger [textf "ax12[%d] torque = %d" id stats.Types.ax12_torque] in - lwt () = logger [textf "ax12[%d] voltage = %d" id stats.Types.ax12_voltage] in - lwt () = logger [textf "ax12[%d] temperature = %d" id stats.Types.ax12_temperature] in - lwt () = logger [textf "ax12[%d] cw-angle-limit = %d" id stats.Types.ax12_cw_angle_limit] in - lwt () = logger [textf "ax12[%d] ccw-angle-limit = %d" id stats.Types.ax12_ccw_angle_limit] in + lwt () = logger [textf "ax12[%d] position = %d" id stats.Krobot_types.ax12_position] in + lwt () = logger [textf "ax12[%d] velocity = %d" id stats.Krobot_types.ax12_velocity] in + lwt () = logger [textf "ax12[%d] torque = %d" id stats.Krobot_types.ax12_torque] in + lwt () = logger [textf "ax12[%d] voltage = %d" id stats.Krobot_types.ax12_voltage] in + lwt () = logger [textf "ax12[%d] temperature = %d" id stats.Krobot_types.ax12_temperature] in + lwt () = logger [textf "ax12[%d] cw-angle-limit = %d" id stats.Krobot_types.ax12_cw_angle_limit] in + lwt () = logger [textf "ax12[%d] ccw-angle-limit = %d" id stats.Krobot_types.ax12_ccw_angle_limit] in return ()); register ~path:["ax12"] "action" (f1 (int ~default:254 "id")) (fun logger krobot id -> - Krobot_unsafe.AX12.action krobot id) + Krobot_unsafe.AX12.action krobot id); + + (* +---------------------------------------------------------------+ + | Grip | + +---------------------------------------------------------------+ *) + + register ~path:["grip"] "up" f0 + (fun logger krobot -> + Krobot.grip_up krobot); + register ~path:["grip"] "down" f0 + (fun logger krobot -> + Krobot.grip_down krobot) + let () = Script_unsafe.register () diff --git a/PC_Mainboard/clients/script_commands.ml b/PC_Mainboard/clients/script_commands.ml index b7369a4..0c92b84 100644 --- a/PC_Mainboard/clients/script_commands.ml +++ b/PC_Mainboard/clients/script_commands.ml @@ -9,7 +9,7 @@ (* +-----------------------------------------------------------------+ - | Types | + | Krobot_types | +-----------------------------------------------------------------+ *) type logger = Lwt_term.styled_text -> unit Lwt.t @@ -18,6 +18,7 @@ type logger = Lwt_term.styled_text -> unit Lwt.t type arg_type = | Int | Float + | String | Keyword of string list type command = { @@ -130,6 +131,13 @@ let int ?default name = { a_default = default; } +let string ?default name = { + a_name = name; + a_type = String; + a_cast = (fun str -> str); + a_default = default; +} + let float ?default name = { a_name = name; a_type = Float; diff --git a/PC_Mainboard/common/PcInterface.h b/PC_Mainboard/common/PcInterface.h index e79e8fa..a24b00c 100644 --- a/PC_Mainboard/common/PcInterface.h +++ b/PC_Mainboard/common/PcInterface.h @@ -61,6 +61,7 @@ typedef struct _UP { #define CMD_TRAJ 10 ///< Transmet une trajetoire au Krobot #define CMD_MOTOR 11 ///< Gestion des moteurs #define CMD_MOTOR_TOR 12 +#define CMD_LCD 13 ///< Commande de l'afficheur LCD // CMD_GET arguments #define GET_RESET_SOURCE 0 ///< Demande au PIC la source du Reset @@ -79,6 +80,7 @@ typedef struct _UP { #define GET_POWER_STATE 13 ///< Etat de l'alimentation de puissance (On/Off) [Battery Monitoring] #define GET_BATTERY_STATE 14 ///< Etat des batteries (Pleine charge/Charge moyenne/Charge faible) [Battery Monitoring] #define GET_CURRENT_SPEED 15 ///< Demande au PIC la valeur actuelle d'un moteur [Carte d'asservissement] +#define GET_INTEGRATION_SUM 16 ///< Demande au PIC la valeur actuelle du terme integration de l'asservissement [Carte d'asservissement] // CMD_ERR arguments #define ERR_UNKNOWN_CMD 1 ///< Commande inconnue @@ -90,6 +92,9 @@ typedef struct _UP { #define ERR_AX12_CHKSUM 7 #define ERR_CMP03_NOT_RESPONDING 8 #define ERR_ADJD_S371_NOT_RESPONDING 9 +#define ERR_LM_COMMAND_ERROR 10 +#define ERR_LM_POSITION_ERROR 11 +#define ERR_INVALID_AXIS 12 // CMD_SET arguments #define SET_PORTS_CONFIG_INPUTS 0x00 ///< Dnir les entr du PIC @@ -119,16 +124,18 @@ typedef struct _UP { #define RESET_SOURCE_MCLR 0x07 ///< Master Clear Reset // CMD_AX12 -#define AX12_PING 0x01 -#define AX12_READ 0x02 -#define AX12_WRITE 0x03 -#define AX12_GOTO 0x04 -#define AX12_GET_POS 0x05 -#define AX12_GET_SPEED 0x06 -#define AX12_GET_LOAD 0x07 -#define AX12_GET_STATS 0x08 -#define AX12_WRITE_REG 0x09 -#define AX12_ACTION 0x10 +#define AX12_PING 1 +#define AX12_READ 2 +#define AX12_WRITE 3 +#define AX12_GOTO 4 +#define AX12_GET_POS 5 +#define AX12_GET_SPEED 6 +#define AX12_GET_LOAD 7 +#define AX12_GET_STATS 8 +#define AX12_WRITE_REG 9 +#define AX12_ACTION 10 +#define AX12_RESET 11 +#define AX12_CONFIG 12 #define AX12_VALUE8 0x00 #define AX12_VALUE16 0x01 @@ -136,6 +143,16 @@ typedef struct _UP { #define AX12_EXEC_NOW 0x00 #define AX12_EXEC_ACTION 0x01 +// CMD_LCD +#define LCD_CLEAR 0x00 +#define LCD_CURSOR_ON 0x01 +#define LCD_CURSOR_OFF 0x02 +#define LCD_BACKLIGHT_ON 0x03 +#define LCD_BACKLIGHT_OFF 0x04 +#define LCD_GOTO_POS 0x05 +#define LCD_WRITE 0x06 +#define LCD_WRITE_LINE 0x07 + // CMD_TRAJ #define TRAJ_INIT 0x00 #define TRAJ_FORWARD 0x01 @@ -153,6 +170,7 @@ typedef struct _UP { #define TRAJ_START 0x0D #define TRAJ_GET_REL_POS 0x0E #define TRAJ_READ_CONFIG 0x0F +#define TRAJ_TURN 0x10 #define TRAJ_NOT_COMPLETED 0x00 #define TRAJ_COMPLETED 0x01 @@ -166,9 +184,9 @@ typedef struct _UP { #define MOTOR_DISABLE 2 #define MOTOR_MOVE 3 -#define MOTOR_RIGHT 0 ///< Sction du moteur de droite (moteur 1) -#define MOTOR_LEFT 1 ///< Sction du moteur de gauche (moteur 2) -#define MOTOR_BOTH 2 ///< Sction des 2 moteurs simultannt +#define MOTOR_RIGHT 1 ///< Sction du moteur de droite (moteur 1) +#define MOTOR_LEFT 2 ///< Sction du moteur de gauche (moteur 2) +#define MOTOR_BOTH 3 ///< Sction des 2 moteurs simultannt // XXX omplr #define READ_VERSION 0x00 diff --git a/PC_Mainboard/common/config.ml b/PC_Mainboard/common/config.ml deleted file mode 100644 index c248d6e..0000000 --- a/PC_Mainboard/common/config.ml +++ /dev/null @@ -1,15 +0,0 @@ -(* - * config.ml - * --------- - * Copyright : (c) 2010, Jeremie Dimino <je...@di...> - * Licence : BSD3 - * - * This file is a part of [kro]bot. - *) - -let back_sensors = [3; 6; 7; 10] -let front_sensors = [0; 1; 2; 4; 5; 8; 9; 11; 12; 13; 14; 15] -let initial_position = 200 -let bus_address = "unix:abstract=krobot" -let update_delay = 0.05 -let reopen_delay = 1.0 diff --git a/PC_Mainboard/common/config.mli b/PC_Mainboard/common/config.mli deleted file mode 100644 index 645ac10..0000000 --- a/PC_Mainboard/common/config.mli +++ /dev/null @@ -1,28 +0,0 @@ -(* - * config.mli - * ---------- - * Copyright : (c) 2010, Jeremie Dimino <je...@di...> - * Licence : BSD3 - * - * This file is a part of [kro]bot. - *) - -(** Krobot parameters *) - -val front_sensors : int list - (** List of front sensors *) - -val back_sensors : int list - (** List of back sensors *) - -val initial_position : int - (** Position to borders at the beginning of the match *) - -val bus_address : string - (** Default address of the krobot dbus daemon *) - -val update_delay : float - (** Time to wait between updates *) - -val reopen_delay : float - (** Time to wait before retrying to open a card *) diff --git a/PC_Mainboard/common/krobot_config.ml b/PC_Mainboard/common/krobot_config.ml new file mode 100644 index 0000000..1895a58 --- /dev/null +++ b/PC_Mainboard/common/krobot_config.ml @@ -0,0 +1,20 @@ +(* + * krobot_config.ml + * ---------------- + * Copyright : (c) 2010, Jeremie Dimino <je...@di...> + * Licence : BSD3 + * + * This file is a part of [kro]bot. + *) + +let back_sensors = [3; 6; 7; 10] +let front_sensors = [0; 1; 2; 4; 5; 8; 9; 11; 12; 13; 14; 15] +let initial_position = 200 +let bus_address = "unix:abstract=krobot" +let update_delay = 0.05 +let reopen_delay = 1.0 + +let ax12_grip_up_down = 1 +let grip_up_position = 880 +let grip_down_position = 580 +let ax12_default_velocity = 50 diff --git a/PC_Mainboard/common/krobot_config.mli b/PC_Mainboard/common/krobot_config.mli new file mode 100644 index 0000000..aa34719 --- /dev/null +++ b/PC_Mainboard/common/krobot_config.mli @@ -0,0 +1,33 @@ +(* + * krobot_config.mli + * ----------------- + * Copyright : (c) 2010, Jeremie Dimino <je...@di...> + * Licence : BSD3 + * + * This file is a part of [kro]bot. + *) + +(** Krobot parameters *) + +val front_sensors : int list + (** List of front sensors *) + +val back_sensors : int list + (** List of back sensors *) + +val initial_position : int + (** Position to borders at the beginning of the match *) + +val bus_address : string + (** Default address of the krobot dbus daemon *) + +val update_delay : float + (** Time to wait between updates *) + +val reopen_delay : float + (** Time to wait before retrying to open a card *) + +val ax12_grip_up_down : int +val grip_up_position : int +val grip_down_position : int +val ax12_default_velocity : int diff --git a/PC_Mainboard/common/krobot_types.ml b/PC_Mainboard/common/krobot_types.ml new file mode 100644 index 0000000..b10800c --- /dev/null +++ b/PC_Mainboard/common/krobot_types.ml @@ -0,0 +1,75 @@ +(* + * krobot_types.ml + * --------------- + * Copyright : (c) 2010, Jeremie Dimino <je...@di...> + * Licence : BSD3 + * + * This file is a part of [kro]bot. + *) + +open OBus_pervasives + +type move_result = [ `OK | `Stopped ] + +let obus_move_result = + OBus_type.mapping obus_int [(`OK, 0); (`Stopped, 1)] + +type motor = [ `Left | `Right | `Both ] + +let obus_motor = OBus_type.mapping obus_int + [(`Left, -1); + (`Both, 0); + (`Right, 1)] + +type stop_mode = [ `Off | `Abrupt | `Smooth ] + +let obus_stop_mode = OBus_type.mapping obus_int + [(`Off, 0); + (`Abrupt, 1); + (`Smooth, 2)] + +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)] + +type ax12_stats = { + ax12_position : int; + ax12_velocity : int; + ax12_torque : int; + ax12_voltage : int; + ax12_temperature : int; + ax12_cw_angle_limit : int; + ax12_ccw_angle_limit : int; +} with obus + +type exec_mode = [ `Now | `Action ] + +let obus_exec_mode = OBus_type.mapping obus_int + [(`Now, 0); (`Action, 1)] + +type direction = [ `Forward | `Backward ] + +let obus_direction = OBus_type.mapping obus_int + [(`Forward, 0); (`Backward, 1)] + +type ax12_action = { + aa_id : int; + aa_position : int; + aa_velocity : int; +} with obus + +type motor_config = { + motor_kp : int; + motor_ki : int; + motor_kd : int; + motor_li : int; +} with obus diff --git a/PC_Mainboard/common/krobot_types.mli b/PC_Mainboard/common/krobot_types.mli new file mode 100644 index 0000000..56d042b --- /dev/null +++ b/PC_Mainboard/common/krobot_types.mli @@ -0,0 +1,62 @@ +(* + * krobot_types.mli + * ---------------- + * Copyright : (c) 2010, Jeremie Dimino <je...@di...> + * Licence : BSD3 + * + * This file is a part of [kro]bot. + *) + +(** Common types with their obus type combinators *) + +(** This types are used by the driver and the client-side krobot + library. + + Putting in a module shared by the client and the server prevents + typos in conversions. *) + +type move_result = [ `OK | `Stopped ] with obus(basic) + (** Result of a movement started by [Krobot.move] or + [Krobot.turn] *) + +type motor = [ `Left | `Right | `Both ] with obus(basic) + (** Motors *) + +type stop_mode = [ `Off | `Abrupt | `Smooth ] with obus(basic) + (** Mode for stopping motors *) + +type direction = [ `Forward | `Backward ] 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 *) + +type exec_mode = [ `Now | `Action ] with obus(basic) + (** Mode of execution of the goto command for ax12 *) + +type ax12_stats = { + ax12_position : int; + ax12_velocity : int; + ax12_torque : int; + ax12_voltage : int; + ax12_temperature : int; + ax12_cw_angle_limit : int; + ax12_ccw_angle_limit : int; +} with obus(sequence) + +(** Action on an AX12: *) +type ax12_action = { + aa_id : int; + aa_position : int; + aa_velocity : int; +} with obus(sequence) + +(** Motor configuration *) +type motor_config = { + motor_kp : int; + motor_ki : int; + motor_kd : int; + motor_li : int; +} with obus(sequence) diff --git a/PC_Mainboard/common/types.ml b/PC_Mainboard/common/types.ml deleted file mode 100644 index 3f970ca..0000000 --- a/PC_Mainboard/common/types.ml +++ /dev/null @@ -1,68 +0,0 @@ -(* - * types.ml - * -------- - * Copyright : (c) 2010, Jeremie Dimino <je...@di...> - * Licence : BSD3 - * - * This file is a part of [kro]bot. - *) - -open OBus_pervasives - -type move_result = [ `OK | `Stopped ] - -let obus_move_result = - OBus_type.mapping obus_int [(`OK, 0); (`Stopped, 1)] - -type motor = [ `Left | `Right | `Both ] - -let obus_motor = OBus_type.mapping obus_int - [(`Left, -1); - (`Both, 0); - (`Right, 1)] - -type stop_mode = [ `Off | `Abrupt | `Smooth ] - -let obus_stop_mode = OBus_type.mapping obus_int - [(`Off, 0); - (`Abrupt, 1); - (`Smooth, 2)] - -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)] - -type ax12_stats = { - ax12_position : int; - ax12_velocity : int; - ax12_torque : int; - ax12_voltage : int; - ax12_temperature : int; - ax12_cw_angle_limit : int; - ax12_ccw_angle_limit : int; -} with obus - -type exec_mode = [ `Now | `Action ] - -let obus_exec_mode = OBus_type.mapping obus_int - [(`Now, 0); (`Action, 1)] - -type direction = [ `Forward | `Backward ] - -let obus_direction = OBus_type.mapping obus_int - [(`Forward, 0); (`Backward, 1)] - -type ax12_action = { - aa_id : int; - aa_position : int; - aa_velocity : int; -} with obus diff --git a/PC_Mainboard/common/types.mli b/PC_Mainboard/common/types.mli deleted file mode 100644 index 6fa04c8..0000000 --- a/PC_Mainboard/common/types.mli +++ /dev/null @@ -1,54 +0,0 @@ -(* - * types.mli - * --------- - * Copyright : (c) 2010, Jeremie Dimino <je...@di...> - * Licence : BSD3 - * - * This file is a part of [kro]bot. - *) - -(** Common types with their obus type combinators *) - -(** This types are used by the driver and the client-side krobot - library. - - Putting in a module shared by the client and the server prevents - typos in conversions. *) - -type move_result = [ `OK | `Stopped ] with obus(basic) - (** Result of a movement started by [Krobot.move] or - [Krobot.turn] *) - -type motor = [ `Left | `Right | `Both ] with obus(basic) - (** Motors *) - -type stop_mode = [ `Off | `Abrupt | `Smooth ] with obus(basic) - (** Mode for stopping motors *) - -type direction = [ `Forward | `Backward ] 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 *) - -type exec_mode = [ `Now | `Action ] with obus(basic) - (** Mode of execution of the goto command for ax12 *) - -type ax12_stats = { - ax12_position : int; - ax12_velocity : int; - ax12_torque : int; - ax12_voltage : int; - ax12_temperature : int; - ax12_cw_angle_limit : int; - ax12_ccw_angle_limit : int; -} with obus(sequence) - -(** Action on an AX12: *) -type ax12_action = { - aa_id : int; - aa_position : int; - aa_velocity : int; -} with obus(sequence) diff --git a/PC_Mainboard/common/util.ml b/PC_Mainboard/common/util.ml index 705623f..1f3ca4f 100644 --- a/PC_Mainboard/common/util.ml +++ b/PC_Mainboard/common/util.ml @@ -13,7 +13,7 @@ let front_collide sensors = if Array.length sensors <> 16 then invalid_arg "Until.front_collide"; let rec loop = function | 16 -> false - | n -> (sensors.(n) && List.mem n Config.front_sensors) || loop (n + 1) + | n -> (sensors.(n) && List.mem n Krobot_config.front_sensors) || loop (n + 1) in loop 0 @@ -21,7 +21,7 @@ let back_collide sensors = if Array.length sensors <> 16 then invalid_arg "Until.back_collide"; let rec loop = function | 16 -> false - | n -> (sensors.(n) && List.mem n Config.back_sensors) || loop (n + 1) + | n -> (sensors.(n) && List.mem n Krobot_config.back_sensors) || loop (n + 1) in loop 0 diff --git a/PC_Mainboard/driver/bus.conf b/PC_Mainboard/driver/bus.conf index 9808b8e..0fb7c62 100644 --- a/PC_Mainboard/driver/bus.conf +++ b/PC_Mainboard/driver/bus.conf @@ -1,5 +1,5 @@ -<!-- Configuration for the dbus daemon --> -<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN" +<!-- Krobot_configuration for the dbus daemon --> +<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Krobot_configuration 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> <busconfig> <keep_umask/> diff --git a/PC_Mainboard/driver/driver.ml b/PC_Mainboard/driver/driver.ml index eae08a2..8705b76 100644 --- a/PC_Mainboard/driver/driver.ml +++ b/PC_Mainboard/driver/driver.ml @@ -12,10 +12,35 @@ module Log = Lwt_log.Make(struct let section = "driver" end) open OBus_pervasives -open Types +open Krobot_types open Lwt (* +-----------------------------------------------------------------+ + | Battery monitoring | + +-----------------------------------------------------------------+ *) + +module Power = +struct + type t = { + obus : OBus_object.t; + card : Krobot_card.t; + } + + module OBus = OBus_object.Make(struct + type obj = t + let cast obj = obj.obus + end) + + module Unsafe = DBus_exports.Power(OBus)(struct let get dev = dev.card end) + + let make card path = + return { + obus = OBus.make ~interfaces:[Unsafe.ol_interface] path; + card = card; + } +end + +(* +-----------------------------------------------------------------+ | Compass | +-----------------------------------------------------------------+ *) @@ -29,31 +54,31 @@ struct module OBus = OBus_object.Make(struct type obj = t - let get obj = obj.obus + let cast obj = obj.obus end) - include DBus_exports.Compass(OBus)(struct let get dev = dev.card end) + module Unsafe = DBus_exports.Compass(OBus)(struct let get dev = dev.card end) - include OBus.MakeInterface(struct let name = "fr.krobot.Device.Compass" end) + let ol_interface = OBus.make_interface "fr.krobot.Device.Compass" OL_signal Value : int OL_method Get : int = fun dev -> return dev.data let rec loop dev = - lwt data = USB_commands.Compass.get dev.card in + lwt _, data = USB_commands.Compass.get dev.card in if data <> dev.data then begin dev.data <- data; lwt () = value dev data in - lwt () = Lwt_unix.sleep Config.update_delay in + lwt () = Lwt_unix.sleep Krobot_config.update_delay in loop dev end else - lwt () = Lwt_unix.sleep Config.update_delay in + lwt () = Lwt_unix.sleep Krobot_config.update_delay in loop dev let make card path = - lwt data = USB_commands.Compass.get card in + lwt _, data = USB_commands.Compass.get card in let dev = { - obus = OBus_object.make path; + obus = OBus.make ~interfaces:[Unsafe.ol_interface; ol_interface] path; card = card; data = data; } in @@ -62,6 +87,53 @@ struct end (* +-----------------------------------------------------------------+ + | LCD | + +-----------------------------------------------------------------+ *) + +module LCD = +struct + type t = { + obus : OBus_object.t; + card : Krobot_card.t; + } + + module OBus = OBus_object.Make(struct + type obj = t + let cast obj = obj.obus + end) + + module Unsafe = DBus_exports.LCD(OBus)(struct let get dev = dev.card end) + + let ol_interface = OBus.make_interface "fr.krobot.Device.LCD" + + OL_method SetLCD : string list -> unit = fun dev lines -> + if List.length lines > 4 || List.exists (fun line -> String.length line > 20) lines then + invalid_arg "SetLCD" + else begin + lwt () = Unsafe.clear dev in + lwt () = Unsafe.cursor_off dev in + let rec loop i = function + | [] -> + return () + | line :: lines -> + lwt () = Unsafe.write_line dev i line in + loop (i + 1) lines + in + loop 1 lines + end + + OL_method BacklightOn : unit = Unsafe.backlight_on + OL_method BacklightOff : unit = Unsafe.backlight_off + + let make card path = + let dev = { + obus = OBus.make ~interfaces:[Unsafe.ol_interface; ol_interface] path; + card = card; + } in + return dev +end + +(* +-----------------------------------------------------------------+ | AX12 | +-----------------------------------------------------------------+ *) @@ -74,14 +146,14 @@ struct module OBus = OBus_object.Make(struct type obj = t - let get obj = obj.obus + let cast obj = obj.obus end) - include DBus_exports.AX12(OBus)(struct let get dev = dev.card end) + module Unsafe = DBus_exports.AX12(OBus)(struct let get dev = dev.card end) - include OBus.MakeInterface(struct let name = "fr.krobot.Device.AX12" end) + let ol_interface = OBus.make_interface "fr.krobot.Device.AX12" - OL_method SetAX12 : Types.ax12_action structure list -> unit = fun dev actions -> + OL_method SetAX12 : Krobot_types.ax12_action structure list -> unit = fun dev actions -> lwt () = Lwt_list.iter_p (fun action -> @@ -95,9 +167,15 @@ struct in USB_commands.AX12.action dev.card ~id:0xfe + OL_method GripUp : unit = fun dev -> + set_ax12 dev [{ aa_id = Krobot_config.ax12_grip_up_down; aa_position = Krobot_config.grip_up_position; aa_velocity = Krobot_config.ax12_default_velocity }] + + OL_method GripDown : unit = fun dev -> + set_ax12 dev [{ aa_id = Krobot_config.ax12_grip_up_down; aa_position = Krobot_config.grip_down_position; aa_velocity = Krobot_config.ax12_default_velocity }] + let make card path = return { - obus = OBus_object.make path; + obus = OBus.make ~interfaces:[Unsafe.ol_interface; ol_interface] path; card = card; } end @@ -116,12 +194,12 @@ struct module OBus = OBus_object.Make(struct type obj = t - let get obj = obj.obus + let cast obj = obj.obus end) - include DBus_exports.Logic_sensors(OBus)(struct let get dev = dev.card end) + module Unsafe = DBus_exports.Logic_sensors(OBus)(struct let get dev = dev.card end) - include OBus.MakeInterface(struct let name = "fr.krobot.Device.LogicSensors" end) + let ol_interface = OBus.make_interface "fr.krobot.Device.LogicSensors" OL_signal Value : bool array OL_method Get : bool array = fun dev -> return dev.data @@ -131,15 +209,15 @@ struct if data <> dev.data then begin dev.data <- data; lwt () = value dev data in - lwt () = Lwt_unix.sleep Config.update_delay in + lwt () = Lwt_unix.sleep Krobot_config.update_delay in loop dev end else - lwt () = Lwt_unix.sleep Config.update_delay in + lwt () = Lwt_unix.sleep Krobot_config.update_delay in loop dev let make card path = let dev = { - obus = OBus_object.make path; + obus = OBus.make ~interfaces:[Unsafe.ol_interface; ol_interface] path; card = card; data = Array.create 16 false; } in @@ -161,12 +239,12 @@ struct module OBus = OBus_object.Make(struct type obj = t - let get obj = obj.obus + let cast obj = obj.obus end) - include DBus_exports.Range_finders(OBus)(struct let get dev = dev.card end) + module Unsafe = DBus_exports.Range_finders(OBus)(struct let get dev = dev.card end) - include OBus.MakeInterface(struct let name = "fr.krobot.Device.RangeFinders" end) + let ol_interface = OBus.make_interface "fr.krobot.Device.RangeFinders" OL_signal Value : int array OL_method Get : int array = fun dev -> return dev.data @@ -185,15 +263,15 @@ struct if data <> dev.data then begin dev.data <- data; lwt () = value dev data in - lwt () = Lwt_unix.sleep Config.update_delay in + lwt () = Lwt_unix.sleep Krobot_config.update_delay in loop dev end else - lwt () = Lwt_unix.sleep Config.update_delay in + lwt () = Lwt_unix.sleep Krobot_config.update_delay in loop dev let make card path = let dev = { - obus = OBus_object.make path; + obus = OBus.make ~interfaces:[Unsafe.ol_interface; ol_interface] path; card = card; data = Array.create 8 0; } in @@ -250,12 +328,12 @@ struct module OBus = OBus_object.Make(struct type obj = t - let get obj = obj.obus + let cast obj = obj.obus end) - include DBus_exports.Motors(OBus)(struct let get dev = dev.card end) + module Unsafe = DBus_exports.Motors(OBus)(struct let get dev = dev.card end) - include OBus.MakeInterface(struct let name = "fr.krobot.Device.Motors" end) + let ol_interface = OBus.make_interface "fr.krobot.Device.Motors" let string_of_direction = function | `Forward -> "forward" @@ -310,14 +388,14 @@ struct dev.state <- Trajectory trajectory; let thread = Lwt_event.next dev.traj_completed >> return () in lwt () = - select [waiter; - (lwt () = - if dist > 0 then - USB_commands.Motors.forward dev.card dist velocity acc - else - USB_commands.Motors.backward dev.card (-dist) velocity acc - in - thread)] + pick [waiter; + (lwt () = + if dist > 0 then + USB_commands.Motors.forward dev.card dist velocity acc + else + USB_commands.Motors.backward dev.card (-dist) velocity acc + in + thread)] in dev.state <- Static; return (if trajectory.stopped then `Stopped else `OK) @@ -346,14 +424,14 @@ struct dev.state <- Trajectory trajectory; let thread = Lwt_event.next dev.traj_completed >> return () in lwt () = - select [waiter; - (lwt () = - if angle > 0 then - USB_commands.Motors.left dev.card angle velocity acc - else - USB_commands.Motors.right dev.card (-angle) velocity acc - in - thread)] + pick [waiter; + (lwt () = + if angle > 0 then + USB_commands.Motors.left dev.card angle velocity acc + else + USB_commands.Motors.right dev.card (-angle) velocity acc + in + thread)] in dev.state <- Static; return (if trajectory.stopped then `Stopped else `OK) @@ -390,24 +468,24 @@ struct dev.state <- Trajectory trajectory; let thread = Lwt_event.next dev.traj_completed >> return () in lwt () = - select [waiter; - (lwt () = - USB_commands.Motors.goto dev.card - ~x ~y - ~velocity:velocity - ~acceleration:acc - ~mode - ~bypass_distance - in - thread)] + pick [waiter; + (lwt () = + USB_commands.Motors.goto dev.card + ~x ~y + ~velocity:velocity + ~acceleration:acc + ~mode + ~bypass_distance + in + thread)] in dev.state <- Static; return (if trajectory.stopped then `Stopped else `OK) end - 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 + OL_method Turn : int -> int -> int -> Krobot_types.move_result + OL_method Move : int -> int -> int -> Krobot_types.move_result + OL_method Goto : int -> int -> int -> int -> Krobot_types.goto_mode -> int -> Krobot_types.move_result (* +---------------------------------------------------------------+ | Manually sets the velocity and acceleration of each motor | @@ -485,7 +563,7 @@ struct let static = { velocity = 0; acceleration = 0; direction = `Forward } in _set_velocities dev (return ()) (static, static) velocities accelerations duration - OL_method StopMotors : Types.stop_mode -> unit + OL_method StopMotors : Krobot_types.stop_mode -> unit OL_method SetVelocities : int * int -> int * int -> float -> unit (* +---------------------------------------------------------------+ @@ -534,7 +612,7 @@ struct let make card path = let commands = React.E.map (fun data -> Char.code data.[0]) (Krobot_card.connect card PcInterface.cmd_traj)#event in let dev = { - obus = OBus_object.make path; + obus = OBus.make ~interfaces:[Unsafe.ol_interface; ol_interface] path; card = card; inhibit_forward_until = 0.0; inhibit_backward_until = 0.0; @@ -551,19 +629,13 @@ end let done_waiter, done_wakener = Lwt.wait () let quit = ref false let card_interface, set_card_interface = React.S.create None +let card_monitoring, set_card_monitoring = 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 - let manager = OBus_object.make ["fr"; "krobot"; "Manager"] - - module OBus = OBus_object.Make(struct - type obj = unit - let get _ = manager - end) - - include OBus.MakeInterface(struct let name = "fr.krobot.Manager" end) + let ol_interface = OBus_object.make_interface "fr.krobot.Manager" let close card = match React.S.value card with | None -> @@ -571,24 +643,28 @@ struct | Some card -> Krobot_card.close card - OL_method CardStates : OBus_connection.t -> Types.card_state * Types.card_state * Types.card_state = fun () connection -> + OL_method CardStates : OBus_connection.t -> Krobot_types.card_state * Krobot_types.card_state * Krobot_types.card_state * Krobot_types.card_state = fun manager 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) + state card_motor, + state card_monitoring) - OL_method Shutdown : OBus_connection.t -> unit = fun () connection -> + OL_method Shutdown : OBus_connection.t -> unit = fun manager connection -> lwt () = Log.info "exiting" in quit := true; lwt () = close card_interface and () = close card_sensor - and () = close card_motor in + and () = close card_motor + and () = close card_monitoring in lwt _ = OBus_bus.release_name connection "fr.krobot.Driver" in Lwt.wakeup done_wakener (); return () + + let manager = OBus_object.make ~interfaces:[ol_interface] ["fr"; "krobot"; "Manager"] end (* +-----------------------------------------------------------------+ @@ -606,7 +682,7 @@ struct module OBus = OBus_object.Make(struct type obj = t - let get obj = obj.obus + let cast obj = obj.obus end) let get_card dev = match React.S.value dev.card with @@ -615,14 +691,14 @@ struct | Some card -> card - include DBus_exports.Card(OBus)(struct let get = get_card end) + module Unsafe = DBus_exports.Card(OBus)(struct let get = get_card end) - include OBus.MakeInterface(struct let name = "fr.krobot.Card" end) + let ol_interface = OBus.make_interface "fr.krobot.Card" OL_property_r Name : string = fun dev -> return (Krobot_card.name (get_card dev)) - OL_method GetState : Types.card_state = fun dev -> + OL_method GetState : Krobot_types.card_state = fun dev -> match React.S.value dev.card with | None -> return `Absent @@ -644,12 +720,12 @@ struct OL_method Test : unit = fun dev -> USB_commands.Card.test (get_card dev) - OL_signal StateChanged : Types.card_state + OL_signal StateChanged : Krobot_types.card_state let make name card path = let dev = { card = card; - obus = OBus_object.make path; + obus = OBus.make ~interfaces:[Unsafe.ol_interface; ol_interface] path; name = name; state = React.S.const (return ()); } in @@ -703,7 +779,7 @@ 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 + lwt () = Lwt_unix.sleep Krobot_config.reopen_delay in monitor_card ~name ~vendor_id ~product_id ~set on_up on_down end @@ -721,7 +797,7 @@ lwt () = Arg.parse args ignore usage_msg; (* Open the krobot message bus *) - lwt bus = OBus_bus.of_addresses (OBus_address.of_string Config.bus_address) in + lwt bus = OBus_bus.of_addresses (OBus_address.of_string Krobot_config.bus_address) in lwt () = try_lwt @@ -757,13 +833,25 @@ lwt () = ignore begin monitor_card ~name:"interace" ~vendor_id:PcInterface.usb_vid ~product_id:PcInterface.usb_pid_robot_interface ~set:set_card_interface (fun card -> - lwt () = USB_commands.Motors.enable card `Both in + lwt () = USB_commands.Servo.enable card `Both in 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 + and () = AX12.OBus.export bus =|< AX12.make card ["fr"; "krobot"; "Devices"; "AX12"] + and () = LCD.OBus.export bus =|< LCD.make card ["fr"; "krobot"; "Devices"; "LCD"] in return ()) (fun () -> OBus_object.remove_by_path bus ["fr"; "krobot"; "Devices"; "Compass"]; OBus_object.remove_by_path bus ["fr"; "krobot"; "Devices"; "AX12"]; + OBus_object.remove_by_path bus ["fr"; "krobot"; "Devices"; "LCD"]; + return ()) + end; + + ignore begin + monitor_card ~name:"monitoring" ~vendor_id:PcInterface.usb_vid ~product_id:PcInterface.usb_pid_battery_monitoring ~set:set_card_monitoring + (fun card -> + lwt () = Power.OBus.export bus =|< Power.make card ["fr"; "krobot"; "Devices"; "Power"] in + return ()) + (fun () -> + OBus_object.remove_by_path bus ["fr"; "krobot"; "Devices"; "Power"]; return ()) end; @@ -793,8 +881,9 @@ lwt () = Card.OBus.export bus (Card.make "interface" card_interface ["fr"; "krobot"; "Cards"; "Interface"]); Card.OBus.export bus (Card.make "sensor" card_sensor ["fr"; "krobot"; "Cards"; "Sensor"]); Card.OBus.export bus (Card.make "motor" card_motor ["fr"; "krobot"; "Cards"; "Motor"]); + Card.OBus.export bus (Card.make "monitoring" card_monitoring ["fr"; "krobot"; "Cards"; "Monitoring"]); - Manager.OBus.export bus (); + OBus_object.export bus Manager.manager; lwt () = Log.notice "ready, waiting for requests" in lwt () = done_waiter in diff --git a/PC_Mainboard/driver/krobot_card.ml b/PC_Mainboard/driver/krobot_card.ml index a2ba1be..d89b116 100644 --- a/PC_Mainboard/driver/krobot_card.ml +++ b/PC_Mainboard/driver/krobot_card.ml @@ -11,6 +11,29 @@ module Log = Lwt_log.Make(struct let section = "card" end) open Lwt +let error_messages = [ + PcInterface.err_unknown_cmd, "unknown command"; + PcInterface.err_unknown_get, "unknown get request"; + PcInterface.err_unknown_set, "unknown set request"; + PcInterface.err_invalid_response, "invalid response"; + PcInterface.err_ax12_wrong_packet, "inva... [truncated message content] |