|
From: Xavier L. <Ba...@us...> - 2013-04-17 16:05: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 db4524176b7945fb99beaf8d3f7c306d1bd461cf (commit)
from 155f88832102bf2e0dccf85c195cfefa13887571 (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 db4524176b7945fb99beaf8d3f7c306d1bd461cf
Author: Xavier Lagorce <Xav...@cr...>
Date: Wed Apr 17 18:06:38 2013 +0200
[info/krobot-io-simulator] First minimal versio of the input/output simulator
(with a skeleton for Urg data simulation)
-----------------------------------------------------------------------
Changes:
diff --git a/info/control2011/_oasis b/info/control2011/_oasis
index fb0111d..be457fb 100644
--- a/info/control2011/_oasis
+++ b/info/control2011/_oasis
@@ -183,6 +183,13 @@ Executable "krobot-mc-simulator"
MainIs: krobot_mc_simulator.ml
BuildDepends: krobot, lwt.syntax
+Executable "krobot-io-simulator"
+ Path: src/tools
+ Install: true
+ CompiledObject: best
+ MainIs: krobot_io_simulator.ml
+ BuildDepends: krobot, lwt.syntax
+
Executable "krobot-planner"
Path: src/tools
Install: true
diff --git a/info/control2011/_tags b/info/control2011/_tags
index 4b665fc..9af45e4 100644
--- a/info/control2011/_tags
+++ b/info/control2011/_tags
@@ -2,7 +2,7 @@
<src/interfaces/*.ml>: -syntax_camlp4o
# OASIS_START
-# DO NOT EDIT (digest: 68e14c8d43423b2050fb1cf67d1938cc)
+# DO NOT EDIT (digest: 44c1536155bea156ff4e324744cffda8)
# Library krobot
"src/lib": include
<src/lib/krobot.{cma,cmxa}>: use_libkrobot
@@ -260,6 +260,11 @@
<src/tools/krobot_homologation.{native,byte}>: pkg_lwt.unix
<src/tools/krobot_homologation.{native,byte}>: pkg_lwt.syntax
<src/tools/krobot_homologation.{native,byte}>: pkg_lwt.react
+# Executable krobot-io-simulator
+<src/tools/krobot_io_simulator.{native,byte}>: use_krobot
+<src/tools/krobot_io_simulator.{native,byte}>: pkg_lwt.unix
+<src/tools/krobot_io_simulator.{native,byte}>: pkg_lwt.syntax
+<src/tools/krobot_io_simulator.{native,byte}>: pkg_lwt.react
# Executable krobot-pet
<src/tools/krobot_pet.{native,byte}>: use_krobot
<src/tools/krobot_pet.{native,byte}>: pkg_lwt.unix
diff --git a/info/control2011/setup.ml b/info/control2011/setup.ml
index 18934ac..2b5c6f0 100644
--- a/info/control2011/setup.ml
+++ b/info/control2011/setup.ml
@@ -8,7 +8,7 @@
*)
(* OASIS_START *)
-(* DO NOT EDIT (digest: 868e08593bf53c96a1f79923d193b872) *)
+(* DO NOT EDIT (digest: bf059af587069cdcfbcb6e820bb05831) *)
(*
Regenerated by OASIS v0.2.0
Visit http://oasis.forge.ocamlcore.org for more information and
@@ -6226,6 +6226,36 @@ let setup_t =
});
Executable
({
+ cs_name = "krobot-io-simulator";
+ cs_data = PropList.Data.create ();
+ cs_plugin_data = [];
+ },
+ {
+ bs_build = [(OASISExpr.EBool true, true)];
+ bs_install = [(OASISExpr.EBool true, true)];
+ bs_path = "src/tools";
+ bs_compiled_object = Best;
+ bs_build_depends =
+ [
+ InternalLibrary "krobot";
+ FindlibPackage ("lwt.syntax", None)
+ ];
+ bs_build_tools = [ExternalTool "ocamlbuild"];
+ bs_c_sources = [];
+ bs_data_files = [];
+ bs_ccopt = [(OASISExpr.EBool true, [])];
+ bs_cclib = [(OASISExpr.EBool true, [])];
+ bs_dlllib = [(OASISExpr.EBool true, [])];
+ bs_dllpath = [(OASISExpr.EBool true, [])];
+ bs_byteopt = [(OASISExpr.EBool true, [])];
+ bs_nativeopt = [(OASISExpr.EBool true, [])];
+ },
+ {
+ exec_custom = false;
+ exec_main_is = "krobot_io_simulator.ml";
+ });
+ Executable
+ ({
cs_name = "krobot-pet";
cs_data = PropList.Data.create ();
cs_plugin_data = [];
diff --git a/info/control2011/src/tools/krobot_io_simulator.ml b/info/control2011/src/tools/krobot_io_simulator.ml
new file mode 100644
index 0000000..9c37c01
--- /dev/null
+++ b/info/control2011/src/tools/krobot_io_simulator.ml
@@ -0,0 +1,116 @@
+(*
+ * krobot_io_simulator.ml
+ * ----------------
+ * Copyright : (c) 2013, Xavier Lagorce <Xav...@cr...>
+ * Licence : BSD3
+ *
+ * This file is a part of [kro]bot.
+ *)
+
+(* Service simulating all inputs/outputs from the robot *)
+
+open Lwt
+open Lwt_react
+open Lwt_preemptive
+open Krobot_bus
+open Krobot_message
+open Krobot_geom
+
+let section = Lwt_log.Section.make "krobot(io_simulator)"
+
+(* +-----------------------------------------------------------------+
+ | Types |
+ +-----------------------------------------------------------------+ *)
+
+(* State of the robot. *)
+type state = {
+ s_x : float;
+ s_y : float;
+ theta : float;
+}
+
+let robot = ref { s_x = 0.; s_y = 0.; theta = 0.}
+
+(* +-----------------------------------------------------------------+
+ | read/send loop |
+ +-----------------------------------------------------------------+ *)
+
+let gen_data robot =
+ let dim = Array.length Krobot_config.urg_angles in
+ let l = ref [] in
+ for i = 0 to dim - 1 do
+ let angle = Krobot_config.urg_angles.(i) in
+ let x = 1. *. cos angle in
+ let y = 1. *. sin angle in
+ l := {x;y} :: !l
+ done;
+ Array.of_list !l
+
+let loop bus =
+ let rec aux () =
+ let time = Unix.gettimeofday () in
+ let msg = Urg (gen_data robot) in
+ lwt () = Krobot_bus.send bus (time, msg) in
+ lwt () = Lwt_unix.sleep 0.01 in
+ aux () in
+ aux ()
+
+(* +-----------------------------------------------------------------+
+ | Message handling |
+ +-----------------------------------------------------------------+ *)
+
+let handle_message (timestamp, message) =
+ match message with
+ | Kill "io_simulator" ->
+ exit 0
+ | CAN(_, frame) -> begin
+ match decode frame with
+ | Odometry(x, y, theta) ->
+ robot := { s_x = x; s_y = y; theta }
+ | _ ->
+ ()
+ end
+ | _ ->
+ ()
+
+(* +-----------------------------------------------------------------+
+ | Command-line arguments |
+ +-----------------------------------------------------------------+ *)
+
+let fork = ref true
+
+let options = Arg.align [
+ "-no-fork", Arg.Clear fork, " Run in foreground";
+]
+
+let usage = "\
+Usage: krobot-io-simulator [options]
+options are:"
+
+(* +-----------------------------------------------------------------+
+ | Entry point |
+ +-----------------------------------------------------------------+ *)
+
+lwt () =
+ Arg.parse options ignore usage;
+
+ (* Display all informative messages. *)
+ Lwt_log.append_rule "*" Lwt_log.Info;
+
+ (* Open the krobot bus. *)
+ lwt bus = Krobot_bus.get () in
+
+ (* Fork if not prevented. *)
+ if !fork then Krobot_daemon.daemonize bus;
+
+ (* Handle krobot message. *)
+ E.keep (E.map (handle_message) (Krobot_bus.recv bus));
+
+ (* Kill any running io_simulator. *)
+ lwt () = Krobot_bus.send bus (Unix.gettimeofday (), Krobot_bus.Kill "io_simulator") in
+
+ (* Wait a bit to let the other handler release the connection *)
+ lwt () = Lwt_unix.sleep 0.4 in
+
+ (* Loop forever. *)
+ Lwt_unix.run (loop bus)
hooks/post-receive
--
krobot
|