From: Xavier L. <Ba...@us...> - 2013-10-21 18:17:38
|
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 233667799df4892865de6877584ef3c9ac89dc6c (commit) from ce758846dbc2dfaf0e1d50ae203a0e955dc33aaf (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 233667799df4892865de6877584ef3c9ac89dc6c Author: Xavier Lagorce <Xav...@cr...> Date: Mon Oct 21 20:15:27 2013 +0200 [info/examples] Added a simple top level example to use AX12s ----------------------------------------------------------------------- Changes: diff --git a/info/control2011/examples/krobot_ax12.ml b/info/control2011/examples/krobot_ax12.ml new file mode 100644 index 0000000..e5aa940 --- /dev/null +++ b/info/control2011/examples/krobot_ax12.ml @@ -0,0 +1,73 @@ +#use "topfind";; +#camlp4o;; +#require "lwt.syntax";; +#require "krobot";; +open Krobot_bus;; +open Krobot_message;; +open Krobot_action;; +open Krobot_geom;; + +let ax12_2_base_position = 519;; +let ax12_2_high_position = 210;; +let ax12_2_mid_position = 400;; +let ax12_1_mid_position = 600;; +let ax12_1_base_position = 518;; +let ax12_1_high_position = 823;; + +let send cmd = ignore(Lwt_unix.run (Krobot_bus.send bus (Unix.gettimeofday (), cmd))) +let send_strat strat = ignore(Lwt_unix.run (Krobot_bus.send bus (Unix.gettimeofday (), Strategy_set strat))) + +let update_team_led team = + let m1,m2 = + if team = `Red then + Switch_request(7,false), Switch_request(6,true) + else + Switch_request(7,true), Switch_request(6,false) + in + lwt () = Krobot_message.send bus (Unix.gettimeofday (),m1) in + Krobot_message.send bus (Unix.gettimeofday (), m2) + +let hit_ax12_id id = + let base, high = + if id = 1 + then ax12_1_base_position, ax12_1_high_position + else ax12_2_base_position, ax12_2_high_position + in + Node (Simple, + [Can (Krobot_message.encode (Ax12_Set_Torque_Enable (id,true))); + Wait_for 0.1; + Can (Krobot_message.encode (Ax12_Goto (id, high, 0))); + Wait_for 0.3; + Can (Krobot_message.encode (Ax12_Goto (id, base, 0))); + Wait_for 0.3]) + +let ax12_activate id status = + send_strat ([Node (Simple, [ + Can (Krobot_message.encode (Ax12_Set_Torque_Enable (id, status))) + ]) + ]) + +let ax12_goto id angle speed = + send_strat ([Node (Simple, [ + Can (Krobot_message.encode (Ax12_Goto (id, angle, speed))) + ]) + ]) + +let hit_side side = + (if side = 1 then + run_lwt (update_team_led `Red) + else + run_lwt (update_team_led `Blue)); + let strat = [ hit_ax12_id side ] in + run_lwt ( + Krobot_bus.send bus (Unix.gettimeofday (), Strategy_set strat) + ) + +let () = hit_side 1 +let () = hit_side 2 + +let () = ax12_activate 1 true +let () = ax12_goto 1 ax12_1_high_position 300 +let () = ax12_goto 1 ax12_1_mid_position 300 +let () = ax12_goto 1 ax12_1_base_position 0 +let () = ax12_activate 1 false hooks/post-receive -- krobot |