From: Jérémie D. <Ba...@us...> - 2011-03-29 10:05:40
|
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 e6cd96db90c7985e0c0daabcdf4f37b5092dee02 (commit) from a6796d7cb6dffc2bf443214c459f9df9922163b1 (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 e6cd96db90c7985e0c0daabcdf4f37b5092dee02 Author: Jérémie Dimino <je...@di...> Date: Tue Mar 29 12:04:16 2011 +0200 [info] add a simulator It is an adaptation of the simulator of last year. ----------------------------------------------------------------------- Changes: diff --git a/info/control2011/_oasis b/info/control2011/_oasis index d883c70..710ebee 100644 --- a/info/control2011/_oasis +++ b/info/control2011/_oasis @@ -127,6 +127,13 @@ Executable "krobot-viewer" MainIs: krobot_viewer.ml BuildDepends: krobot, lwt.syntax, cairo.lablgtk2, lwt.glib, threads, lablgtk2.glade +Executable "krobot-simulator" + Path: src/tools + Install: true + CompiledObject: best + MainIs: krobot_simulator.ml + BuildDepends: krobot, lwt.syntax + # +-------------------------------------------------------------------+ # | Examples | # +-------------------------------------------------------------------+ diff --git a/info/control2011/_tags b/info/control2011/_tags index 34b9c0b..20baf17 100644 --- a/info/control2011/_tags +++ b/info/control2011/_tags @@ -2,7 +2,7 @@ <src/interfaces/*.ml>: -syntax_camlp4o # OASIS_START -# DO NOT EDIT (digest: 8a8ef494b18055a22e7cd7b9c87b8a13) +# DO NOT EDIT (digest: 255c5daac028047b8fd81335cc7a3a1d) # Library krobot-interfaces "src/interfaces": include "src/interfaces/krobot-interfaces.cmxs": use_krobot-interfaces @@ -117,12 +117,18 @@ <src/tools/krobot_plot.{native,byte}>: pkg_lwt.syntax <src/tools/krobot_plot.{native,byte}>: pkg_lwt.glib <src/tools/krobot_plot.{native,byte}>: pkg_cairo.lablgtk2 +<src/tools/*.ml{,i}>: pkg_threads +<src/tools/*.ml{,i}>: pkg_lwt.glib +<src/tools/*.ml{,i}>: pkg_cairo.lablgtk2 +# Executable krobot-simulator +<src/tools/krobot_simulator.{native,byte}>: use_krobot +<src/tools/krobot_simulator.{native,byte}>: use_krobot-interfaces +<src/tools/krobot_simulator.{native,byte}>: pkg_obus +<src/tools/krobot_simulator.{native,byte}>: pkg_lwt.unix +<src/tools/krobot_simulator.{native,byte}>: pkg_lwt.syntax <src/tools/*.ml{,i}>: use_krobot <src/tools/*.ml{,i}>: use_krobot-interfaces -<src/tools/*.ml{,i}>: pkg_threads <src/tools/*.ml{,i}>: pkg_obus <src/tools/*.ml{,i}>: pkg_lwt.unix <src/tools/*.ml{,i}>: pkg_lwt.syntax -<src/tools/*.ml{,i}>: pkg_lwt.glib -<src/tools/*.ml{,i}>: pkg_cairo.lablgtk2 # OASIS_STOP diff --git a/info/control2011/myocamlbuild.ml b/info/control2011/myocamlbuild.ml index 58c15ed..08cc900 100644 --- a/info/control2011/myocamlbuild.ml +++ b/info/control2011/myocamlbuild.ml @@ -1,7 +1,7 @@ (* OASIS_START *) -(* DO NOT EDIT (digest: 7b180d572761c507057af7fdf11b0222) *) +(* DO NOT EDIT (digest: 570b31c8f48685aca9662d28e560f425) *) module OASISGettext = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/oasis/OASISGettext.ml" +# 21 "/home/dim/sources/oasis/src/oasis/OASISGettext.ml" let ns_ str = str @@ -24,7 +24,7 @@ module OASISGettext = struct end module OASISExpr = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/oasis/OASISExpr.ml" +# 21 "/home/dim/sources/oasis/src/oasis/OASISExpr.ml" @@ -115,7 +115,7 @@ end module BaseEnvLight = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/base/BaseEnvLight.ml" +# 21 "/home/dim/sources/oasis/src/base/BaseEnvLight.ml" module MapString = Map.Make(String) @@ -212,7 +212,7 @@ end module MyOCamlbuildFindlib = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/plugins/ocamlbuild/MyOCamlbuildFindlib.ml" +# 21 "/home/dim/sources/oasis/src/plugins/ocamlbuild/MyOCamlbuildFindlib.ml" (** OCamlbuild extension, copied from * http://brion.inria.fr/gallium/index.php/Using_ocamlfind_with_ocamlbuild @@ -320,7 +320,7 @@ module MyOCamlbuildFindlib = struct end module MyOCamlbuildBase = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/plugins/ocamlbuild/MyOCamlbuildBase.ml" +# 21 "/home/dim/sources/oasis/src/plugins/ocamlbuild/MyOCamlbuildBase.ml" (** Base functions for writing myocamlbuild.ml @author Sylvain Le Gall @@ -335,7 +335,7 @@ module MyOCamlbuildBase = struct type name = string type tag = string -# 55 "/home/krobot/ocaml-stuff/oasis/src/plugins/ocamlbuild/MyOCamlbuildBase.ml" +# 55 "/home/dim/sources/oasis/src/plugins/ocamlbuild/MyOCamlbuildBase.ml" type t = { diff --git a/info/control2011/setup.ml b/info/control2011/setup.ml index 650e561..6f7ed53 100644 --- a/info/control2011/setup.ml +++ b/info/control2011/setup.ml @@ -1,14 +1,14 @@ (* setup.ml generated for the first time by OASIS v0.2.0~alpha1 *) (* OASIS_START *) -(* DO NOT EDIT (digest: 2a8cc2d164b159f24cb072891525da9a) *) +(* DO NOT EDIT (digest: 4353dde9f1283d0e97c3df83edda68fd) *) (* Regenerated by OASIS v0.2.0 Visit http://oasis.forge.ocamlcore.org for more information and documentation about functions used in this file. *) module OASISGettext = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/oasis/OASISGettext.ml" +# 21 "/home/dim/sources/oasis/src/oasis/OASISGettext.ml" let ns_ str = str @@ -31,7 +31,7 @@ module OASISGettext = struct end module OASISContext = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/oasis/OASISContext.ml" +# 21 "/home/dim/sources/oasis/src/oasis/OASISContext.ml" open OASISGettext @@ -90,7 +90,7 @@ module OASISContext = struct end module OASISUtils = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/oasis/OASISUtils.ml" +# 21 "/home/dim/sources/oasis/src/oasis/OASISUtils.ml" module MapString = Map.Make(String) @@ -242,7 +242,7 @@ module OASISUtils = struct end module PropList = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/oasis/PropList.ml" +# 21 "/home/dim/sources/oasis/src/oasis/PropList.ml" open OASISGettext @@ -277,7 +277,7 @@ module PropList = struct let clear t = Hashtbl.clear t -# 59 "/home/krobot/ocaml-stuff/oasis/src/oasis/PropList.ml" +# 59 "/home/dim/sources/oasis/src/oasis/PropList.ml" end module Schema = @@ -518,7 +518,7 @@ module PropList = struct end module OASISMessage = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/oasis/OASISMessage.ml" +# 21 "/home/dim/sources/oasis/src/oasis/OASISMessage.ml" open OASISGettext @@ -567,7 +567,7 @@ module OASISMessage = struct end module OASISVersion = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/oasis/OASISVersion.ml" +# 21 "/home/dim/sources/oasis/src/oasis/OASISVersion.ml" open OASISGettext @@ -751,7 +751,7 @@ module OASISVersion = struct end module OASISLicense = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/oasis/OASISLicense.ml" +# 21 "/home/dim/sources/oasis/src/oasis/OASISLicense.ml" (** License for _oasis fields @author Sylvain Le Gall @@ -784,7 +784,7 @@ module OASISLicense = struct end module OASISExpr = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/oasis/OASISExpr.ml" +# 21 "/home/dim/sources/oasis/src/oasis/OASISExpr.ml" @@ -874,7 +874,7 @@ module OASISExpr = struct end module OASISTypes = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/oasis/OASISTypes.ml" +# 21 "/home/dim/sources/oasis/src/oasis/OASISTypes.ml" @@ -951,7 +951,7 @@ module OASISTypes = struct type plugin_data = (all_plugin * plugin_data_purpose * (unit -> unit)) list -# 102 "/home/krobot/ocaml-stuff/oasis/src/oasis/OASISTypes.ml" +# 102 "/home/dim/sources/oasis/src/oasis/OASISTypes.ml" type 'a conditional = 'a OASISExpr.choices @@ -1105,7 +1105,7 @@ module OASISTypes = struct end module OASISUnixPath = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/oasis/OASISUnixPath.ml" +# 21 "/home/dim/sources/oasis/src/oasis/OASISUnixPath.ml" type unix_filename = string type unix_dirname = string @@ -1184,7 +1184,7 @@ module OASISUnixPath = struct end module OASISSection = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/oasis/OASISSection.ml" +# 21 "/home/dim/sources/oasis/src/oasis/OASISSection.ml" (** Manipulate section @author Sylvain Le Gall @@ -1246,12 +1246,12 @@ module OASISSection = struct end module OASISBuildSection = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/oasis/OASISBuildSection.ml" +# 21 "/home/dim/sources/oasis/src/oasis/OASISBuildSection.ml" end module OASISExecutable = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/oasis/OASISExecutable.ml" +# 21 "/home/dim/sources/oasis/src/oasis/OASISExecutable.ml" open OASISTypes @@ -1282,7 +1282,7 @@ module OASISExecutable = struct end module OASISLibrary = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/oasis/OASISLibrary.ml" +# 21 "/home/dim/sources/oasis/src/oasis/OASISLibrary.ml" open OASISTypes open OASISUtils @@ -1573,33 +1573,33 @@ module OASISLibrary = struct end module OASISFlag = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/oasis/OASISFlag.ml" +# 21 "/home/dim/sources/oasis/src/oasis/OASISFlag.ml" end module OASISPackage = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/oasis/OASISPackage.ml" +# 21 "/home/dim/sources/oasis/src/oasis/OASISPackage.ml" end module OASISSourceRepository = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/oasis/OASISSourceRepository.ml" +# 21 "/home/dim/sources/oasis/src/oasis/OASISSourceRepository.ml" end module OASISTest = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/oasis/OASISTest.ml" +# 21 "/home/dim/sources/oasis/src/oasis/OASISTest.ml" end module OASISDocument = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/oasis/OASISDocument.ml" +# 21 "/home/dim/sources/oasis/src/oasis/OASISDocument.ml" end module BaseEnvLight = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/base/BaseEnvLight.ml" +# 21 "/home/dim/sources/oasis/src/base/BaseEnvLight.ml" module MapString = Map.Make(String) @@ -1696,7 +1696,7 @@ end module BaseContext = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/base/BaseContext.ml" +# 21 "/home/dim/sources/oasis/src/base/BaseContext.ml" open OASISContext @@ -1707,7 +1707,7 @@ module BaseContext = struct end module BaseMessage = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/base/BaseMessage.ml" +# 21 "/home/dim/sources/oasis/src/base/BaseMessage.ml" (** Message to user, overrid for Base @author Sylvain Le Gall @@ -1728,7 +1728,7 @@ module BaseMessage = struct end module BaseFilePath = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/base/BaseFilePath.ml" +# 21 "/home/dim/sources/oasis/src/base/BaseFilePath.ml" open Filename @@ -1760,7 +1760,7 @@ module BaseFilePath = struct end module BaseEnv = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/base/BaseEnv.ml" +# 21 "/home/dim/sources/oasis/src/base/BaseEnv.ml" open OASISTypes open OASISGettext @@ -2219,7 +2219,7 @@ module BaseEnv = struct end module BaseExec = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/base/BaseExec.ml" +# 21 "/home/dim/sources/oasis/src/base/BaseExec.ml" open OASISGettext open OASISUtils @@ -2279,7 +2279,7 @@ module BaseExec = struct end module BaseFileUtil = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/base/BaseFileUtil.ml" +# 21 "/home/dim/sources/oasis/src/base/BaseFileUtil.ml" open OASISGettext @@ -2457,7 +2457,7 @@ module BaseFileUtil = struct end module BaseArgExt = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/base/BaseArgExt.ml" +# 21 "/home/dim/sources/oasis/src/base/BaseArgExt.ml" open OASISUtils open OASISGettext @@ -2485,7 +2485,7 @@ module BaseArgExt = struct end module BaseCheck = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/base/BaseCheck.ml" +# 21 "/home/dim/sources/oasis/src/base/BaseCheck.ml" open BaseEnv open BaseMessage @@ -2611,7 +2611,7 @@ module BaseCheck = struct end module BaseOCamlcConfig = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/base/BaseOCamlcConfig.ml" +# 21 "/home/dim/sources/oasis/src/base/BaseOCamlcConfig.ml" open BaseEnv @@ -2713,7 +2713,7 @@ module BaseOCamlcConfig = struct end module BaseStandardVar = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/base/BaseStandardVar.ml" +# 21 "/home/dim/sources/oasis/src/base/BaseStandardVar.ml" open OASISGettext @@ -2973,7 +2973,7 @@ module BaseStandardVar = struct end module BaseFileAB = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/base/BaseFileAB.ml" +# 21 "/home/dim/sources/oasis/src/base/BaseFileAB.ml" open BaseEnv open OASISGettext @@ -3021,7 +3021,7 @@ module BaseFileAB = struct end module BaseLog = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/base/BaseLog.ml" +# 21 "/home/dim/sources/oasis/src/base/BaseLog.ml" open OASISUtils @@ -3140,7 +3140,7 @@ module BaseLog = struct end module BaseBuilt = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/base/BaseBuilt.ml" +# 21 "/home/dim/sources/oasis/src/base/BaseBuilt.ml" open OASISTypes open OASISGettext @@ -3287,7 +3287,7 @@ module BaseBuilt = struct end module BaseCustom = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/base/BaseCustom.ml" +# 21 "/home/dim/sources/oasis/src/base/BaseCustom.ml" open BaseEnv open BaseMessage @@ -3337,7 +3337,7 @@ module BaseCustom = struct end module BaseDynVar = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/base/BaseDynVar.ml" +# 21 "/home/dim/sources/oasis/src/base/BaseDynVar.ml" open OASISTypes @@ -3381,7 +3381,7 @@ module BaseDynVar = struct end module BaseTest = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/base/BaseTest.ml" +# 21 "/home/dim/sources/oasis/src/base/BaseTest.ml" open BaseEnv open BaseMessage @@ -3463,7 +3463,7 @@ module BaseTest = struct end module BaseDoc = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/base/BaseDoc.ml" +# 21 "/home/dim/sources/oasis/src/base/BaseDoc.ml" open BaseEnv open BaseMessage @@ -3493,7 +3493,7 @@ module BaseDoc = struct end module BaseSetup = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/base/BaseSetup.ml" +# 21 "/home/dim/sources/oasis/src/base/BaseSetup.ml" open BaseEnv open BaseMessage @@ -3911,7 +3911,7 @@ module BaseSetup = struct end module BaseDev = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/base/BaseDev.ml" +# 21 "/home/dim/sources/oasis/src/base/BaseDev.ml" @@ -3969,7 +3969,7 @@ end module InternalConfigurePlugin = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/plugins/internal/InternalConfigurePlugin.ml" +# 21 "/home/dim/sources/oasis/src/plugins/internal/InternalConfigurePlugin.ml" (** Configure using internal scheme @author Sylvain Le Gall @@ -4185,7 +4185,7 @@ module InternalConfigurePlugin = struct end module InternalInstallPlugin = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/plugins/internal/InternalInstallPlugin.ml" +# 21 "/home/dim/sources/oasis/src/plugins/internal/InternalInstallPlugin.ml" (** Install using internal scheme @author Sylvain Le Gall @@ -4584,7 +4584,7 @@ end module OCamlbuildCommon = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/plugins/ocamlbuild/OCamlbuildCommon.ml" +# 21 "/home/dim/sources/oasis/src/plugins/ocamlbuild/OCamlbuildCommon.ml" (** Functions common to OCamlbuild build and doc plugin *) @@ -4684,7 +4684,7 @@ module OCamlbuildCommon = struct end module OCamlbuildPlugin = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/plugins/ocamlbuild/OCamlbuildPlugin.ml" +# 21 "/home/dim/sources/oasis/src/plugins/ocamlbuild/OCamlbuildPlugin.ml" (** Build using ocamlbuild @author Sylvain Le Gall @@ -4928,7 +4928,7 @@ module OCamlbuildPlugin = struct end module OCamlbuildDocPlugin = struct -# 21 "/home/krobot/ocaml-stuff/oasis/src/plugins/ocamlbuild/OCamlbuildDocPlugin.ml" +# 21 "/home/dim/sources/oasis/src/plugins/ocamlbuild/OCamlbuildDocPlugin.ml" (* Create documentation using ocamlbuild .odocl files @author Sylvain Le Gall @@ -5504,7 +5504,37 @@ let setup_t = bs_byteopt = [(OASISExpr.EBool true, [])]; bs_nativeopt = [(OASISExpr.EBool true, [])]; }, - {exec_custom = false; exec_main_is = "krobot_plot.ml"; }) + {exec_custom = false; exec_main_is = "krobot_plot.ml"; }); + Executable + ({ + cs_name = "krobot-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_simulator.ml"; + }) ]; plugins = [(`Extra, "DevFiles", Some "0.2"); (`Extra, "META", Some "0.2")]; diff --git a/info/control2011/src/lib/krobot_config.ml b/info/control2011/src/lib/krobot_config.ml new file mode 100644 index 0000000..05e699d --- /dev/null +++ b/info/control2011/src/lib/krobot_config.ml @@ -0,0 +1,14 @@ +(* + * krobot_config.ml + * ---------------- + * Copyright : (c) 2011, Jeremie Dimino <je...@di...> + * Licence : BSD3 + * + * This file is a part of [kro]bot. + *) + +let world_height = 2.1 +let world_width = 3. +let robot_size = 0.3 +let wheels_diameter = 0.098 +let wheels_distance = 0.259 diff --git a/info/control2011/src/lib/krobot_config.mli b/info/control2011/src/lib/krobot_config.mli new file mode 100644 index 0000000..7876fdd --- /dev/null +++ b/info/control2011/src/lib/krobot_config.mli @@ -0,0 +1,25 @@ +(* + * krobot_config.mli + * ----------------- + * Copyright : (c) 2011, Jeremie Dimino <je...@di...> + * Licence : BSD3 + * + * This file is a part of [kro]bot. + *) + +(** Parameters *) + +val world_width : float + (** The width of the board. *) + +val world_height : float + (** THe height of the board. *) + +val robot_size : float + (** The size of the robot, which is a square. *) + +val wheels_diameter : float + (** The diameter of the wheels. *) + +val wheels_distance : float + (** The distance between the two wheels. *) diff --git a/info/control2011/src/lib/krobot_message.ml b/info/control2011/src/lib/krobot_message.ml index 76eccc5..debdc1d 100644 --- a/info/control2011/src/lib/krobot_message.ml +++ b/info/control2011/src/lib/krobot_message.ml @@ -203,9 +203,9 @@ let decode frame = float (get_uint16 frame.data 6) /. 1000.) | 202 -> Motor_turn - (float (get_sint32 frame.data 0) *. pi /. 1800., - float (get_uint16 frame.data 4) *. pi /. 1800., - float (get_uint16 frame.data 6) *. pi /. 1800.) + (float (get_sint32 frame.data 0) *. pi /. 18000., + float (get_uint16 frame.data 4) *. pi /. 18000., + float (get_uint16 frame.data 6) *. pi /. 18000.) | _ -> Unknown frame diff --git a/info/control2011/src/tools/krobot_simulator.ml b/info/control2011/src/tools/krobot_simulator.ml new file mode 100644 index 0000000..c2f1f68 --- /dev/null +++ b/info/control2011/src/tools/krobot_simulator.ml @@ -0,0 +1,214 @@ +(* + * krobot_simulator.ml + * ------------------- + * Copyright : (c) 2011, Jeremie Dimino <je...@di...> + * Licence : BSD3 + * + * This file is a part of [kro]bot. + *) + +(* Simulate the robot. *) + +open Lwt +open Lwt_react +open Krobot_config +open Krobot_message + +(* +-----------------------------------------------------------------+ + | Types | + +-----------------------------------------------------------------+ *) + +(* State of the robot. *) +type state = { + x : float; + y : float; + theta : float; +} + +type internal_state = { + theta_l : float; + theta_r : float; +} + +type command = + | Speed of float * float * float * float + (* [Speed(start_time, end_time, left_velocity, right_velocity)] *) + | Turn of float * float * float * float + (* [Turn(start_time, t_acc, end_time, velocity)] *) + | Move of float * float * float * float + (* [Move(start_time, t_acc, end_time, velocity)] *) + +(* Type of simulators. *) +type simulator = { + mutable state : state; + mutable internal_state : internal_state; + mutable command : command; + mutable time : float; +} + +(* +-----------------------------------------------------------------+ + | Simulation | + +-----------------------------------------------------------------+ *) + +let sim_step = 0.01 + +let velocities_of_command cmd time = + match cmd with + | Speed (start, tend, l_v, r_v) -> + if time < start || time > tend then + (0., 0.) + else + ((l_v +. r_v) *. wheels_diameter /. 4., (l_v -. r_v) *. wheels_diameter /. wheels_distance) + | Turn (start, t_acc, tend, vel) -> + if time < start || time > tend then + (0., 0.) + else if time < (start +. t_acc) then + (0., vel *. (time -. start) /. t_acc) + else if time < (tend -. t_acc) then + (0., vel) + else + (0., vel *. (tend -. time) /. t_acc) + | Move (start, t_acc, tend, vel) -> + if time < start || time > tend then + (0., 0.) + else if time < (start +. t_acc) then + (vel *. (time -. start) /. t_acc, 0.) + else if time < (tend -. t_acc) then + (vel, 0.) + else + (vel *. (tend -. time) /. t_acc, 0.) + +let move sim distance velocity acceleration = + let t_acc = velocity /. acceleration in + let t_end = (velocity *. velocity +. distance *. acceleration) /. (velocity *. acceleration) in + sim.command <- + if t_end > 2. *. t_acc + then + Move (sim.time, t_acc, sim.time +. t_end, velocity) + else begin + let t_acc = sqrt (distance /. acceleration) in + let t_end = 2. *. t_acc in + let velocity = acceleration *. t_acc in + Move (sim.time, t_acc, sim.time +. t_end, velocity) + end + +let turn sim angle velocity acceleration = + let t_acc = velocity /. acceleration in + let t_end = (velocity *. velocity +. angle *. acceleration) /. (velocity *. acceleration) in + sim.command <- + if t_end > 2. *. t_acc + then + Turn (sim.time, t_acc, sim.time +. t_end, velocity) + else begin + let t_acc = sqrt (angle /. acceleration) in + let t_end = 2. *. t_acc in + let velocity = acceleration *. t_acc in + Turn (sim.time, t_acc, sim.time +. t_end, velocity) + end + +let set_velocities sim left_velocity right_velocity duration = + sim.command <- Speed (sim.time, sim.time +. duration, left_velocity, right_velocity) + +let get_velocities sim = + let (u1, u2) = velocities_of_command sim.command sim.time in + let l_v = (4. *. u1 +. wheels_distance *. u2) /. (2. *. wheels_diameter) + and r_v = (4. *. u1 -. wheels_distance *. u2) /. (2. *. wheels_diameter) in + (l_v, r_v) + +let get_state sim = + sim.state + +let get_encoders sim = + let (theta_l, theta_r) = (sim.internal_state.theta_l, sim.internal_state.theta_r) in + (theta_l *. wheels_diameter /. 2., theta_r *. wheels_diameter /. 2.) + +(* +-----------------------------------------------------------------+ + | Entry point | + +-----------------------------------------------------------------+ *) + +let print sim = + Lwt_log.debug_f " +time = %f +state: + x = %f + y = %f + theta = %f +internal_state: + theta_l = %f + theta_r = %f +command = %s +" + sim.time + sim.state.x + sim.state.y + sim.state.theta + sim.internal_state.theta_l + sim.internal_state.theta_r + (match sim.command with + | Speed(s, e, l, r) -> + Printf.sprintf "Speed(%f, %f, %f, %f)" s e l r + | Move(s, x, e, a) -> + Printf.sprintf "Move(%f, %f, %f, %f)" s x e a + | Turn(s, x, e, a) -> + Printf.sprintf "Turn(%f, %f, %f, %f)" s x e a) + +lwt () = + lwt bus = Krobot_bus.get () in + + let sim = { + state = { x = 0.; y = 0.; theta = 0. }; + internal_state = { theta_l = 0.; theta_r = 0. }; + command = Speed(0., 0., 0., 0.); + time = Unix.gettimeofday (); + } in + + (* Handle commands. *) + E.keep + (E.map_s + (fun (ts, msg) -> + match msg with + | Motor_move(dist, speed, acc) -> + lwt () = Lwt_log.info_f "received: move(%f, %f, %f)" dist speed acc in + move sim dist speed acc; + return () + | Motor_turn(angle, speed, acc) -> + lwt () = Lwt_log.info_f "received: turn(%f, %f, %f)" angle speed acc in + turn sim angle speed acc; + return () + | Req_motor_status -> + let s, e = + match sim.command with + | Speed(s, e, _, _) -> (s, e) + | Move(s, _, e, _) -> (s, e) + | Turn(s, _, e, _) -> (s, e) + in + let t= Unix.gettimeofday () in + Krobot_message.send bus (t, Motor_status(s <= t && t < e)) + | _ -> + return ()) + (Krobot_message.recv bus)); + + while_lwt true do + sim.time <- Unix.gettimeofday (); + + (* Sends the state of the robot. *) + lwt () = Krobot_message.send bus (sim.time, Odometry(sim.state.x, sim.state.y, sim.state.theta)) in + + lwt () = print sim in + + let (u1, u2) = velocities_of_command sim.command sim.time in + let dx = u1 *. (cos sim.state.theta) + and dy = u1 *. (sin sim.state.theta) + and dtheta = u2 in + sim.state <- { + x = sim.state.x +. dx *. sim_step; + y = sim.state.y +. dy *. sim_step; + theta = sim.state.theta +. dtheta *. sim_step; + }; + sim.internal_state <- { + theta_l = sim.internal_state.theta_l +. sim_step *. (u1 *. 4. +. u2 *. wheels_distance) /. (2. *. wheels_diameter); + theta_r = sim.internal_state.theta_r +. sim_step *. (u1 *. 4. -. u2 *. wheels_distance) /. (2. *. wheels_diameter); + }; + + Lwt_unix.sleep sim_step + done diff --git a/info/control2011/src/tools/krobot_viewer.ml b/info/control2011/src/tools/krobot_viewer.ml index cd1b61f..0bbe687 100644 --- a/info/control2011/src/tools/krobot_viewer.ml +++ b/info/control2011/src/tools/krobot_viewer.ml @@ -166,6 +166,8 @@ end +-----------------------------------------------------------------+ *) module Board = struct + open Krobot_config + type state = { x : float; y : float; @@ -180,14 +182,6 @@ module Board = struct mutable event : unit event; } - let world_height = 2.1 - let world_width = 3. - let robot_size = 0.3 - let wheels_diam = 0.098 - let wheels_dist = 0.259 - let sim_step = 0.01 - let time = ref 0. - type color = | Black | White hooks/post-receive -- krobot |