From: Jérémie D. <Ba...@us...> - 2010-03-28 17:59:35
|
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 a4c94e5b7dfe71df192312cc0b5edc83bd678e1f (commit) from 0ecd473b933a4ea03a9d4e72f818441bb3406c5a (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 a4c94e5b7dfe71df192312cc0b5edc83bd678e1f Author: Jérémie Dimino <je...@di...> Date: Sun Mar 28 18:58:53 2010 +0200 add a tool for interactive control of the ax12s ----------------------------------------------------------------------- Changes: diff --git a/PC_Mainboard/Makefile b/PC_Mainboard/Makefile index 9435bbb..bbaf447 100644 --- a/PC_Mainboard/Makefile +++ b/PC_Mainboard/Makefile @@ -40,6 +40,7 @@ install: install -m 0755 _build/clients/krobot_controller.best $(PREFIX)/bin/krobot-controller install -m 0755 _build/services/krobot_hard_stop.best $(PREFIX)/bin/krobot-hard-stop install -m 0755 _build/driver/krobot_driver.best $(PREFIX)/bin/krobot-driver + install -m 0755 _build/clients/krobot_ax12.best $(PREFIX)/bin/krobot-ax12 .PHONY: uninstall uninstall: diff --git a/PC_Mainboard/_tags b/PC_Mainboard/_tags index 4f33d64..bf46a8a 100644 --- a/PC_Mainboard/_tags +++ b/PC_Mainboard/_tags @@ -26,6 +26,7 @@ <clients/krobot_joy_control.*>: pkg_sdl <clients/krobot_controller.*>: pkg_lwt.text <clients/krobot_script*>: pkg_text +<clients/krobot_ax12.*>: pkg_lwt.text # +------------------------------------------------------------------+ # | Services | diff --git a/PC_Mainboard/clients/krobot_ax12.ml b/PC_Mainboard/clients/krobot_ax12.ml new file mode 100644 index 0000000..439ac38 --- /dev/null +++ b/PC_Mainboard/clients/krobot_ax12.ml @@ -0,0 +1,83 @@ +(* + * krobot_ax12.ml + * -------------- + * Copyright : (c) 2010, Jeremie Dimino <je...@di...> + * Licence : BSD3 + * + * This file is a part of [kro]bot. + *) + +(* AX12 interactive controller *) + +open Lwt +open Lwt_io +open Lwt_term + +let render positions selected = + let size = React.S.value Lwt_term.size in + let zone = Zone.make ~width:size.columns ~height:size.lines in + let x = (size.columns / 2) - 7 in + let y = (size.lines / 2) - (Array.length positions / 2) in + for i = 0 to Array.length positions - 1 do + if i = selected then + Draw.textc ~zone ~x ~y:(y + i * 2) + ~text:[inverse; textf "ax12[%d] : %4d" (i + 1) positions.(i)] + else + Draw.textc ~zone ~x ~y:(y + i * 2) + ~text:[textf "ax12[%d] : %4d" (i + 1) positions.(i)] + done; + Lwt_term.render (Zone.points zone) + +lwt () = + lwt krobot = Krobot.create () in + + lwt () = Lwt_log.notice "reading current ax12 positions" in + lwt pos1 = Krobot_unsafe.AX12.get_position krobot ~id:1 ~timeout:100 + and pos2 = Krobot_unsafe.AX12.get_position krobot ~id:2 ~timeout:100 + and pos3 = Krobot_unsafe.AX12.get_position krobot ~id:3 ~timeout:100 in + lwt () = Lwt_log.notice "done" in + + let positions = [|pos1; pos2; pos3|] in + + let rec loop selected = + lwt () = render positions selected in + Lwt_term.read_key () >>= function + | Key_up -> + if selected > 0 then + loop (selected - 1) + else + loop selected + | Key_down -> + if selected < Array.length positions - 1 then + loop (selected + 1) + else + loop selected + | Key_left -> + positions.(selected) <- max 0 (positions.(selected) - 10); + lwt () = Krobot_unsafe.AX12.goto krobot ~id:(selected + 1) ~position:positions.(selected) ~velocity:50 ~mode:`Now in + loop selected + | Key_right -> + positions.(selected) <- min 1023 (positions.(selected) + 10); + lwt () = Krobot_unsafe.AX12.goto krobot ~id:(selected + 1) ~position:positions.(selected) ~velocity:50 ~mode:`Now in + loop selected + | Key ("\027[d" | "\027[1;2D") -> + positions.(selected) <- max 0 (positions.(selected) - 1); + lwt () = Krobot_unsafe.AX12.goto krobot ~id:(selected + 1) ~position:positions.(selected) ~velocity:50 ~mode:`Now in + loop selected + | Key ("\027[c" | "\027[1;2C") -> + positions.(selected) <- min 1023 (positions.(selected) + 1); + lwt () = Krobot_unsafe.AX12.goto krobot ~id:(selected + 1) ~position:positions.(selected) ~velocity:50 ~mode:`Now in + loop selected + | Key_control '[' -> + return () + | _ -> + loop selected + in + + lwt () = Lwt_term.enter_drawing_mode () in + lwt () = Lwt_term.hide_cursor () in + + try_lwt + loop 0 + finally + Lwt_term.leave_drawing_mode () diff --git a/PC_Mainboard/myocamlbuild.ml b/PC_Mainboard/myocamlbuild.ml index 42a97e6..4a083c6 100644 --- a/PC_Mainboard/myocamlbuild.ml +++ b/PC_Mainboard/myocamlbuild.ml @@ -73,6 +73,7 @@ let targets = List.filter_opt (function (true, target) -> Some target | (false, (have_lwt_unix && have_obus, "clients/krobot_init_position.best"); (have_lwt_unix && have_obus && have_lwt_text, "clients/krobot_controller.best"); (have_lwt_unix && have_obus && have_sdl, "clients/krobot_joy_control.best"); + (have_lwt_unix && have_obus && have_lwt_text, "clients/krobot_ax12.best"); (* Services *) (have_lwt_unix && have_obus, "services/krobot_hard_stop.best"); hooks/post-receive -- krobot |