From: Jérémie D. <Ba...@us...> - 2011-06-16 17:41:26
|
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 5403b5850fb9dd5aadbb3350764821280e44de0e (commit) from 3f6b2f56b27416cf35ffbc0d5fa6d67eb8b6b0ea (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 5403b5850fb9dd5aadbb3350764821280e44de0e Author: Jérémie Dimino <je...@di...> Date: Thu Jun 16 19:40:36 2011 +0200 [info] integrates the rest of krobot_run into krobot_vm/action ----------------------------------------------------------------------- Changes: diff --git a/info/control2011/src/lib/krobot_action.ml b/info/control2011/src/lib/krobot_action.ml index 6255e48..6e1dd3c 100644 --- a/info/control2011/src/lib/krobot_action.ml +++ b/info/control2011/src/lib/krobot_action.ml @@ -22,9 +22,24 @@ type t = | Wait_for_moving of bool | Reset_odometry of [ `Red | `Blue | `Auto ] | Wait_for_odometry of [ `Eq | `Gt | `Ge | `Lt | `Le ] * int + | Load of [ `Front | `Back ] + | Lift_down of [ `Front | `Back ] + | Lift_up of [ `Front | `Back ] + | Open_grip_low of [ `Front | `Back ] + | Close_grip_low of [ `Front | `Back ] + | Open_grip_high of [ `Front | `Back ] + | Close_grip_high of [ `Front | `Back ] + | Wait_for of float + | Wait_until of float + | Wait_for_grip_open_low of [ `Front | `Back ] + | Wait_for_grip_close_low of [ `Front | `Back ] let string_of_vertice { x; y } = sprintf "{ x = %f; y = %f }" x y +let string_of_face = function + | `Front -> "`Front" + | `Back -> "`Back" + let rec to_string = function | Node l -> sprintf "Node [%s]" (String.concat "; " (List.map to_string l)) @@ -69,3 +84,25 @@ let rec to_string = function | `Lt -> "Lt" | `Le -> "Le") value + | Load face -> + sprintf "Load %s" (string_of_face face) + | Lift_down face -> + sprintf "Lift_down %s" (string_of_face face) + | Lift_up face -> + sprintf "Lift_up %s" (string_of_face face) + | Open_grip_low face -> + sprintf "Open_grip_low %s" (string_of_face face) + | Close_grip_low face -> + sprintf "Close_grip_low %s" (string_of_face face) + | Open_grip_high face -> + sprintf "Open_grip_high %s" (string_of_face face) + | Close_grip_high face -> + sprintf "Close_grip_high %s" (string_of_face face) + | Wait_for t -> + sprintf "Wait_for %f" t + | Wait_until t -> + sprintf "Wait_until %f" t + | Wait_for_grip_open_low face -> + sprintf "Wait_for_grip_open_low %S" (string_of_face face) + | Wait_for_grip_close_low face -> + sprintf "Wait_for_grip_close_low %S" (string_of_face face) diff --git a/info/control2011/src/lib/krobot_action.mli b/info/control2011/src/lib/krobot_action.mli index 72e953a..f103559 100644 --- a/info/control2011/src/lib/krobot_action.mli +++ b/info/control2011/src/lib/krobot_action.mli @@ -40,6 +40,28 @@ type t = | Wait_for_odometry of [ `Eq | `Gt | `Ge | `Lt | `Le ] * int (** Wait for the curve parameter of the odometry to reach the given state. *) + | Load of [ `Front | `Back ] + (** Load a pawn. *) + | Lift_down of [ `Front | `Back ] + (** Move the front or back lift down. *) + | Lift_up of [ `Front | `Back ] + (** Move the front or back lift up. *) + | Open_grip_low of [ `Front | `Back ] + (** Open the front or back low grip. *) + | Close_grip_low of [ `Front | `Back ] + (** Close the front or back low grip. *) + | Open_grip_high of [ `Front | `Back ] + (** Open the front or back low grip. *) + | Close_grip_high of [ `Front | `Back ] + (** Close the front or back low grip. *) + | Wait_for of float + (** Wait for the given number of seconds. *) + | Wait_until of float + (** Wait until the given date. *) + | Wait_for_grip_open_low of [ `Front | `Back ] + (** Wait for the given low grip to be opened. *) + | Wait_for_grip_close_low of [ `Front | `Back ] + (** Wait for the given low grip to be opened. *) val to_string : t -> string (** [to_string action] returns the string representation of the diff --git a/info/control2011/src/tools/krobot_vm.ml b/info/control2011/src/tools/krobot_vm.ml index 9d67145..d4dc507 100644 --- a/info/control2011/src/tools/krobot_vm.ml +++ b/info/control2011/src/tools/krobot_vm.ml @@ -21,6 +21,13 @@ open Krobot_action | Types | +-----------------------------------------------------------------+ *) +(* State of an AX12. *) +type ax12 = { + mutable ax12_position : int; + mutable ax12_speed : int; + mutable ax12_torque : int; +} + (* Type of robots. *) type robot = { bus : Krobot_bus.t; @@ -68,6 +75,16 @@ type robot = { mutable team : [ `Red | `Blue ]; (* The state of the team selector. *) + + ax12_front_low_left : ax12; + ax12_front_low_right : ax12; + ax12_front_high_left : ax12; + ax12_front_high_right : ax12; + ax12_back_low_left : ax12; + ax12_back_low_right : ax12; + ax12_back_high_left : ax12; + ax12_back_high_right : ax12; + (* State of AX12s. *) } (* +-----------------------------------------------------------------+ @@ -100,6 +117,20 @@ let handle_message robot (timestamp, message) = | Switch1_status(b, _, _, _, _, _, _, _) -> robot.jack <- not b + | Ax12_State(id, position, speed, torque) -> begin + let set ax12 = + ax12.ax12_position <- position; + ax12.ax12_speed <- speed; + ax12.ax12_torque <- torque + in + match id with + | 1 -> set robot.ax12_front_low_left + | 2 -> set robot.ax12_front_low_right + | 3 -> set robot.ax12_front_high_left + | 4 -> set robot.ax12_front_high_right + | _ -> () + end + | _ -> () end @@ -198,6 +229,13 @@ let rec exec robot actions = exec robot rest else (actions, Wait) + | Wait_for t :: rest -> + exec robot (Wait_until (Unix.gettimeofday () +. t) :: rest) + | Wait_until t :: rest -> + if Unix.gettimeofday () >= t then + exec robot rest + else + (actions, Wait) | Set_curve None :: rest -> reset robot; exec robot rest @@ -278,8 +316,26 @@ let rec exec robot actions = Set_odometry(0.215 -. robot_size /. 2. +. wheels_position, 1.885, 0.) | `Blue, _ | `Auto, `Blue -> Set_odometry(2.77, 1.915, pi))) + | Load face :: rest -> + exec robot (Node [ + Lift_down face; + Open_grip_low face; + Wait_for_grip_open_low face; + Wait_for 0.5; + (* Move_to_pawn *) + Close_grip_low face; + Lift_up face; + Wait_for_grip_close_low face; + Wait_for 0.5; + ] :: rest) + | Lift_down `Front :: rest -> + (rest, Send(Elevator(0., -1.))) + | Lift_up `Front :: rest -> + (rest, Send(Elevator(1., -1.))) | Think :: rest -> exec robot rest + | _ :: rest -> + exec robot rest (* +-----------------------------------------------------------------+ | Main loop | @@ -390,6 +446,14 @@ lwt () = beacon = None; date_seen_beacon = 0.; team = `Red; + ax12_front_low_left = { ax12_position = 0; ax12_speed = 0; ax12_torque = 0 }; + ax12_front_low_right = { ax12_position = 0; ax12_speed = 0; ax12_torque = 0 }; + ax12_front_high_left = { ax12_position = 0; ax12_speed = 0; ax12_torque = 0 }; + ax12_front_high_right = { ax12_position = 0; ax12_speed = 0; ax12_torque = 0 }; + ax12_back_low_left = { ax12_position = 0; ax12_speed = 0; ax12_torque = 0 }; + ax12_back_low_right = { ax12_position = 0; ax12_speed = 0; ax12_torque = 0 }; + ax12_back_high_left = { ax12_position = 0; ax12_speed = 0; ax12_torque = 0 }; + ax12_back_high_right = { ax12_position = 0; ax12_speed = 0; ax12_torque = 0 }; } in (* Handle krobot message. *) hooks/post-receive -- krobot |