You can subscribe to this list here.
2009 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(13) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2010 |
Jan
(50) |
Feb
(137) |
Mar
(84) |
Apr
(36) |
May
(100) |
Jun
(5) |
Jul
|
Aug
(4) |
Sep
(13) |
Oct
(1) |
Nov
(4) |
Dec
(22) |
2011 |
Jan
(4) |
Feb
(9) |
Mar
(113) |
Apr
(76) |
May
(31) |
Jun
(19) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2012 |
Jan
(4) |
Feb
|
Mar
(2) |
Apr
(6) |
May
(19) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(4) |
Nov
|
Dec
|
2013 |
Jan
|
Feb
|
Mar
(2) |
Apr
(22) |
May
(6) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
2014 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: ghaessig <Ba...@us...> - 2013-04-06 21:24:13
|
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 53fc37f4d093087aa81f0d50668689421da71958 (commit) from d2263c4a65ff26f062be07d440f81591045645fb (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 53fc37f4d093087aa81f0d50668689421da71958 Author: Germain Haessig <gha...@cr...> Date: Sat Apr 6 23:23:07 2013 +0200 [Beacon_Laser] Change of communication speed ----------------------------------------------------------------------- Changes: diff --git a/elec/boards/Beacon_Laser/Firmwares/dump_times/dump_times.ino b/elec/boards/Beacon_Laser/Firmwares/dump_times/dump_times.ino index a1a6b11..a807b9f 100644 --- a/elec/boards/Beacon_Laser/Firmwares/dump_times/dump_times.ino +++ b/elec/boards/Beacon_Laser/Firmwares/dump_times/dump_times.ino @@ -37,7 +37,7 @@ void setup() { delay(2000); flag_data_ready = false ; cmd_get_data = true; - Serial.begin(115200); + Serial.begin(57600); attachInterrupt(0,interrupt1,RISING); } hooks/post-receive -- krobot |
From: ghaessig <Ba...@us...> - 2013-04-06 21:05:02
|
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 d2263c4a65ff26f062be07d440f81591045645fb (commit) from b5dd28ad72923a038b155c247d8457f2c9eb0e4a (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 d2263c4a65ff26f062be07d440f81591045645fb Author: Germain Haessig <gha...@cr...> Date: Sat Apr 6 22:58:55 2013 +0200 [Beacon_Laser] initial import of dump_times firmware New laser Beacon system. Firmware to dump the data through Xbee for later use. ----------------------------------------------------------------------- Changes: diff --git a/elec/boards/Beacon_Laser/Firmwares/dump_times/dump_times.ino b/elec/boards/Beacon_Laser/Firmwares/dump_times/dump_times.ino new file mode 100644 index 0000000..a1a6b11 --- /dev/null +++ b/elec/boards/Beacon_Laser/Firmwares/dump_times/dump_times.ino @@ -0,0 +1,116 @@ + /* + * beacon_1_dump.c + * -------------------- + * Copyright : (c) 2013, Germain Haessig <ger...@cr...> + * Licence : BSD3 + * + * This file is a part of [kro]bot. + */ + + +int pin_interrupt = 2 ; +int pin_A = 3 ; +int pin_B = 4 ; +int pin_C = 5 ; + +volatile unsigned long times[12]={0,0,0,0,0,0,0,0,0,0,0,0}; +volatile int index_times=0; + +int i; + +volatile boolean flag_data_ready,cmd_get_data; +float N ; +float l = 2 ; +float L = 3 ; +float k = 0.5*l ; +float r = 28E-3 ; + +float gamma_A,gamma_B,gamma_C; +float d_A,d_B,d_C; + +float alpha, beta,gamma; + +float x_angle,y_angle; + + +void setup() { + delay(2000); + flag_data_ready = false ; + cmd_get_data = true; + Serial.begin(115200); + attachInterrupt(0,interrupt1,RISING); +} + + + +void loop() { + static float A = 0 ; + static float B = 0 ; + static float denom = 0 ; + + if(flag_data_ready) { + flag_data_ready = false ; + N=(1E6/(times[6]-times[0])*60); // beacon RPM + + /*gamma_A = N*(times[1]-times[0])*M_PI/30; + gamma_B = N*(times[3]-times[2])*M_PI/30; + gamma_C = N*(times[5]-times[1])*M_PI/30; + + d_A = r/(sin(gamma_A/2)); + d_B = r/(sin(gamma_B/2)); + d_C = r/(sin(gamma_C/2));*/ + /* + alpha=N*(times[2]-times[0])*1E-6*M_PI/30; + beta=N*(times[4]-times[2])*1E-6*M_PI/30; + gamma=N*(times[6]-times[4])*1E-6*M_PI/30; + + A = tan(alpha); + B = tan(beta) ; + + denom = B*B*l*l+A*A*l*l*B*B+A*A*B*B*k*k+A*A*L*L+A*A*k*k+B*B*A*A*L*L-2*A*A*l*B*B*k-2*A*A*l*B*L+2*B*l*A*k-2*B*B*l*A*L; + x_angle = (l*B-B*k-L)*(A*B*L-A*k-B*k-L)*A*l/denom; + y_angle = l*(-A*k+A*B*L-B*k-L)*(-l*B-A*k+A*B*L)/denom; + */ + + for(i=1;i<=11;i++) { + Serial.print(times[i]-times[0]); + Serial.print(" "); + } + Serial.println(); + + cmd_get_data = true ; + } + +} + + +void interrupt1() { + static int last_beacon = -1 ; + static boolean measuring = false ; + unsigned long time = micros(); + int beacon = -1 ; + + if(digitalRead(pin_A)) { + beacon = 0 ; + } else if(digitalRead(pin_B)) { + beacon = 1 ; + } else if(digitalRead(pin_C)) { + beacon = 2 ; + } + + if (!measuring && cmd_get_data && last_beacon == 2 && beacon == 0) { + measuring = true ; + cmd_get_data = false ; + index_times = 0; + } + if(measuring) { + times[index_times] = time; + index_times++; + if(index_times > 11) { + measuring = false ; + flag_data_ready = true ; + } + } + last_beacon=beacon ; +} + hooks/post-receive -- krobot |
From: Pierre C. <Ba...@us...> - 2013-04-06 20:56:03
|
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 b5dd28ad72923a038b155c247d8457f2c9eb0e4a (commit) from 367d701262d78c6d664a24f4eee9a27c79b5329e (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 b5dd28ad72923a038b155c247d8457f2c9eb0e4a Author: Pierre Chambart <pie...@oc...> Date: Sat Apr 6 22:53:27 2013 +0200 add ocaml-urg to receive data from the urg. Add the krobot_urg tool to send the data on the bus ----------------------------------------------------------------------- Changes: diff --git a/info/control2011/_oasis b/info/control2011/_oasis index 797df32..91019c0 100644 --- a/info/control2011/_oasis +++ b/info/control2011/_oasis @@ -26,6 +26,10 @@ Flag cv Description: enable opencv Default: true +Flag urg + Description: enable lib urg + Default: true + Flag sdl Description: enable sdl Default: true @@ -300,6 +304,14 @@ Executable "krobot-pet" MainIs: krobot_pet.ml BuildDepends: krobot, lwt.syntax +Executable "krobot-urg" + Path: src/tools + Build$: flag(urg) + Install$: flag(urg) + CompiledObject: best + MainIs: krobot_urg.ml + BuildDepends: krobot, urg, lwt.syntax, lwt.preemptive, threads + # +-------------------------------------------------------------------+ # | Examples | # +-------------------------------------------------------------------+ diff --git a/info/control2011/_tags b/info/control2011/_tags index 1bdb883..5ca553f 100644 --- a/info/control2011/_tags +++ b/info/control2011/_tags @@ -2,4 +2,279 @@ <src/interfaces/*.ml>: -syntax_camlp4o # OASIS_START +# DO NOT EDIT (digest: 9d24891399e4580abf4972e7db50e404) +# Ignore VCS directories, you can use the same kind of rule outside +# OASIS_START/STOP if you want to exclude directories that contains +# useless stuff for the build process +<**/.svn>: -traverse +<**/.svn>: not_hygienic +".bzr": -traverse +".bzr": not_hygienic +".hg": -traverse +".hg": not_hygienic +".git": -traverse +".git": not_hygienic +"_darcs": -traverse +"_darcs": not_hygienic +# Library krobot +"src/lib/krobot.cmxs": use_krobot +<src/lib/krobot.{cma,cmxa}>: use_libkrobot_stubs +<src/lib/*.ml{,i}>: pkg_lwt.syntax +<src/lib/*.ml{,i}>: pkg_lwt.unix +<src/lib/*.ml{,i}>: pkg_lwt.react +"src/lib/krobot_message_stubs.c": pkg_lwt.syntax +"src/lib/krobot_message_stubs.c": pkg_lwt.unix +"src/lib/krobot_message_stubs.c": pkg_lwt.react +# Library krobot-can +"src/can/krobot-can.cmxs": use_krobot-can +<src/can/krobot-can.{cma,cmxa}>: use_libkrobot-can_stubs +<src/can/*.ml{,i}>: use_krobot +<src/can/*.ml{,i}>: pkg_lwt.syntax +<src/can/*.ml{,i}>: pkg_sexplib +<src/can/*.ml{,i}>: pkg_sexplib.syntax +<src/can/*.ml{,i}>: pkg_lwt.unix +<src/can/*.ml{,i}>: pkg_bitstring +<src/can/*.ml{,i}>: pkg_lwt.react +"src/can/can_stubs.c": use_krobot +"src/can/can_stubs.c": pkg_lwt.syntax +"src/can/can_stubs.c": pkg_sexplib +"src/can/can_stubs.c": pkg_sexplib.syntax +"src/can/can_stubs.c": pkg_lwt.unix +"src/can/can_stubs.c": pkg_bitstring +"src/can/can_stubs.c": pkg_lwt.react +# Executable krobot-driver +<src/driver/krobot_driver.{native,byte}>: use_krobot-can +<src/driver/krobot_driver.{native,byte}>: use_krobot +<src/driver/krobot_driver.{native,byte}>: pkg_lwt.syntax +<src/driver/krobot_driver.{native,byte}>: pkg_sexplib +<src/driver/krobot_driver.{native,byte}>: pkg_sexplib.syntax +<src/driver/krobot_driver.{native,byte}>: pkg_lwt.unix +<src/driver/krobot_driver.{native,byte}>: pkg_bitstring +<src/driver/krobot_driver.{native,byte}>: pkg_lwt.react +<src/driver/*.ml{,i}>: use_krobot-can +<src/driver/*.ml{,i}>: use_krobot +<src/driver/*.ml{,i}>: pkg_lwt.syntax +<src/driver/*.ml{,i}>: pkg_sexplib +<src/driver/*.ml{,i}>: pkg_sexplib.syntax +<src/driver/*.ml{,i}>: pkg_lwt.unix +<src/driver/*.ml{,i}>: pkg_bitstring +<src/driver/*.ml{,i}>: pkg_lwt.react +# Executable krobot-hub +<src/tools/krobot_hub.{native,byte}>: pkg_lwt.syntax +<src/tools/krobot_hub.{native,byte}>: pkg_lwt.unix +# Executable krobot-dump +<src/tools/krobot_dump.{native,byte}>: use_krobot +<src/tools/krobot_dump.{native,byte}>: pkg_lwt.syntax +<src/tools/krobot_dump.{native,byte}>: pkg_lwt.unix +<src/tools/krobot_dump.{native,byte}>: pkg_lwt.react +# Executable krobot-monitor +<src/tools/krobot_monitor.{native,byte}>: use_krobot +<src/tools/krobot_monitor.{native,byte}>: pkg_lwt.syntax +<src/tools/krobot_monitor.{native,byte}>: pkg_lwt.unix +<src/tools/krobot_monitor.{native,byte}>: pkg_lwt.react +# Executable krobot-dump-encoders +<src/tools/krobot_dump_encoders.{native,byte}>: use_krobot +<src/tools/krobot_dump_encoders.{native,byte}>: pkg_lwt.syntax +<src/tools/krobot_dump_encoders.{native,byte}>: pkg_lwt.unix +<src/tools/krobot_dump_encoders.{native,byte}>: pkg_lwt.react +# Executable krobot-record +<src/tools/krobot_record.{native,byte}>: use_krobot +<src/tools/krobot_record.{native,byte}>: pkg_lwt.syntax +<src/tools/krobot_record.{native,byte}>: pkg_threads +<src/tools/krobot_record.{native,byte}>: pkg_lwt.unix +<src/tools/krobot_record.{native,byte}>: pkg_lwt.react +# Executable krobot-replay +<src/tools/krobot_replay.{native,byte}>: use_krobot +<src/tools/krobot_replay.{native,byte}>: pkg_lwt.syntax +<src/tools/krobot_replay.{native,byte}>: pkg_lwt.unix +<src/tools/krobot_replay.{native,byte}>: pkg_lwt.react +# Executable krobot-read +<src/tools/krobot_read.{native,byte}>: use_krobot +<src/tools/krobot_read.{native,byte}>: pkg_lwt.syntax +<src/tools/krobot_read.{native,byte}>: pkg_lwt.unix +<src/tools/krobot_read.{native,byte}>: pkg_lwt.react +# Executable krobot-plot +<src/tools/krobot_plot.{native,byte}>: use_krobot +<src/tools/krobot_plot.{native,byte}>: pkg_lwt.syntax +<src/tools/krobot_plot.{native,byte}>: pkg_cairo.lablgtk2 +<src/tools/krobot_plot.{native,byte}>: pkg_lwt.glib +<src/tools/krobot_plot.{native,byte}>: pkg_lwt.unix +<src/tools/krobot_plot.{native,byte}>: pkg_lwt.react +# Executable krobot-plot-battery +<src/tools/krobot_plot_battery.{native,byte}>: use_krobot +<src/tools/krobot_plot_battery.{native,byte}>: pkg_lwt.syntax +<src/tools/krobot_plot_battery.{native,byte}>: pkg_cairo.lablgtk2 +<src/tools/krobot_plot_battery.{native,byte}>: pkg_lwt.glib +<src/tools/krobot_plot_battery.{native,byte}>: pkg_lwt.unix +<src/tools/krobot_plot_battery.{native,byte}>: pkg_lwt.react +# Executable krobot-viewer +<src/tools/krobot_viewer.{native,byte}>: use_krobot +<src/tools/krobot_viewer.{native,byte}>: pkg_lwt.syntax +<src/tools/krobot_viewer.{native,byte}>: pkg_cairo.lablgtk2 +<src/tools/krobot_viewer.{native,byte}>: pkg_lwt.glib +<src/tools/krobot_viewer.{native,byte}>: pkg_lablgtk2.glade +<src/tools/krobot_viewer.{native,byte}>: pkg_lwt.unix +<src/tools/krobot_viewer.{native,byte}>: pkg_lwt.react +<src/tools/*.ml{,i}>: pkg_lablgtk2.glade +# Executable krobot-simulator +<src/tools/krobot_simulator.{native,byte}>: use_krobot +<src/tools/krobot_simulator.{native,byte}>: pkg_lwt.syntax +<src/tools/krobot_simulator.{native,byte}>: pkg_lwt.unix +<src/tools/krobot_simulator.{native,byte}>: pkg_lwt.react +# Executable krobot-hil-simulator +<src/tools/krobot_hil_simulator.{native,byte}>: use_krobot +<src/tools/krobot_hil_simulator.{native,byte}>: pkg_lwt.syntax +<src/tools/krobot_hil_simulator.{native,byte}>: pkg_lwt.unix +<src/tools/krobot_hil_simulator.{native,byte}>: pkg_lwt.react +# Executable krobot-planner +<src/tools/krobot_planner.{native,byte}>: use_krobot +<src/tools/krobot_planner.{native,byte}>: pkg_lwt.syntax +<src/tools/krobot_planner.{native,byte}>: pkg_lwt.unix +<src/tools/krobot_planner.{native,byte}>: pkg_lwt.react +# Executable krobot-fake-beacons +<src/tools/krobot_fake_beacons.{native,byte}>: use_krobot +<src/tools/krobot_fake_beacons.{native,byte}>: pkg_lwt.syntax +<src/tools/krobot_fake_beacons.{native,byte}>: pkg_lwt.unix +<src/tools/krobot_fake_beacons.{native,byte}>: pkg_lwt.react +# Executable krobot-objects +<src/tools/krobot_objects.{native,byte}>: use_krobot +<src/tools/krobot_objects.{native,byte}>: pkg_lwt.syntax +<src/tools/krobot_objects.{native,byte}>: pkg_lwt.unix +<src/tools/krobot_objects.{native,byte}>: pkg_lwt.react +# Executable krobot-webcam +<src/tools/krobot_webcam.{native,byte}>: use_krobot +<src/tools/krobot_webcam.{native,byte}>: pkg_lwt.syntax +<src/tools/krobot_webcam.{native,byte}>: pkg_lwt.unix +<src/tools/krobot_webcam.{native,byte}>: pkg_lwt.react +# Executable krobot-kill +<src/tools/krobot_kill.{native,byte}>: use_krobot +<src/tools/krobot_kill.{native,byte}>: pkg_lwt.syntax +<src/tools/krobot_kill.{native,byte}>: pkg_lwt.unix +<src/tools/krobot_kill.{native,byte}>: pkg_lwt.react +# Executable krobot-calibrate-sharps +<src/tools/krobot_calibrate_sharps.{native,byte}>: use_krobot +<src/tools/krobot_calibrate_sharps.{native,byte}>: pkg_lwt.syntax +<src/tools/krobot_calibrate_sharps.{native,byte}>: pkg_lwt.unix +<src/tools/krobot_calibrate_sharps.{native,byte}>: pkg_lwt.react +# Executable krobot-sharps +<src/tools/krobot_sharps.{native,byte}>: use_krobot +<src/tools/krobot_sharps.{native,byte}>: pkg_lwt.syntax +<src/tools/krobot_sharps.{native,byte}>: pkg_lwt.unix +<src/tools/krobot_sharps.{native,byte}>: pkg_lwt.react +# Executable krobot-vm +<src/tools/krobot_vm.{native,byte}>: use_krobot +<src/tools/krobot_vm.{native,byte}>: pkg_lwt.syntax +<src/tools/krobot_vm.{native,byte}>: pkg_lwt.unix +<src/tools/krobot_vm.{native,byte}>: pkg_lwt.react +# Executable krobot-ia +<src/tools/krobot_ia.{native,byte}>: use_krobot +<src/tools/krobot_ia.{native,byte}>: pkg_lwt.syntax +<src/tools/krobot_ia.{native,byte}>: pkg_lwt.unix +<src/tools/krobot_ia.{native,byte}>: pkg_lwt.react +# Executable krobot-homologation +<src/tools/krobot_homologation.{native,byte}>: use_krobot +<src/tools/krobot_homologation.{native,byte}>: pkg_lwt.syntax +<src/tools/krobot_homologation.{native,byte}>: pkg_lwt.unix +<src/tools/krobot_homologation.{native,byte}>: pkg_lwt.react +# Executable krobot-can-display +<src/tools/krobot_can_display.{native,byte}>: use_krobot-can +<src/tools/krobot_can_display.{native,byte}>: use_krobot +<src/tools/krobot_can_display.{native,byte}>: pkg_lwt.syntax +<src/tools/krobot_can_display.{native,byte}>: pkg_sexplib +<src/tools/krobot_can_display.{native,byte}>: pkg_sexplib.syntax +<src/tools/krobot_can_display.{native,byte}>: pkg_cairo.lablgtk2 +<src/tools/krobot_can_display.{native,byte}>: pkg_lwt.glib +<src/tools/krobot_can_display.{native,byte}>: pkg_lwt.unix +<src/tools/krobot_can_display.{native,byte}>: pkg_bitstring +<src/tools/krobot_can_display.{native,byte}>: pkg_lwt.react +<src/tools/*.ml{,i}>: pkg_cairo.lablgtk2 +<src/tools/*.ml{,i}>: pkg_lwt.glib +# Executable krobot-ax12-control +<src/tools/krobot_ax12_control.{native,byte}>: use_krobot-can +<src/tools/krobot_ax12_control.{native,byte}>: use_krobot +<src/tools/krobot_ax12_control.{native,byte}>: pkg_lwt.syntax +<src/tools/krobot_ax12_control.{native,byte}>: pkg_sexplib +<src/tools/krobot_ax12_control.{native,byte}>: pkg_sexplib.syntax +<src/tools/krobot_ax12_control.{native,byte}>: pkg_lwt.unix +<src/tools/krobot_ax12_control.{native,byte}>: pkg_bitstring +<src/tools/krobot_ax12_control.{native,byte}>: pkg_lwt.react +# Executable krobot-dump-ax12 +<src/tools/krobot_dump_ax12.{native,byte}>: use_krobot-can +<src/tools/krobot_dump_ax12.{native,byte}>: use_krobot +<src/tools/krobot_dump_ax12.{native,byte}>: pkg_lwt.syntax +<src/tools/krobot_dump_ax12.{native,byte}>: pkg_sexplib +<src/tools/krobot_dump_ax12.{native,byte}>: pkg_sexplib.syntax +<src/tools/krobot_dump_ax12.{native,byte}>: pkg_lwt.unix +<src/tools/krobot_dump_ax12.{native,byte}>: pkg_bitstring +<src/tools/krobot_dump_ax12.{native,byte}>: pkg_lwt.react +<src/tools/*.ml{,i}>: use_krobot-can +<src/tools/*.ml{,i}>: pkg_sexplib +<src/tools/*.ml{,i}>: pkg_sexplib.syntax +<src/tools/*.ml{,i}>: pkg_bitstring +# Executable krobot-ax12-clean +# Executable krobot-see-coin +<src/tools/krobot_see_coin.{native,byte}>: use_krobot +<src/tools/krobot_see_coin.{native,byte}>: pkg_lwt.syntax +<src/tools/krobot_see_coin.{native,byte}>: pkg_cv +<src/tools/krobot_see_coin.{native,byte}>: pkg_lwt.unix +<src/tools/krobot_see_coin.{native,byte}>: pkg_lwt.react +<src/tools/*.ml{,i}>: pkg_cv +# Executable krobot-stop-beacon +<src/tools/krobot_stop_beacon.{native,byte}>: use_krobot +<src/tools/krobot_stop_beacon.{native,byte}>: pkg_lwt.syntax +<src/tools/krobot_stop_beacon.{native,byte}>: pkg_lwt.unix +<src/tools/krobot_stop_beacon.{native,byte}>: pkg_lwt.react +# Executable krobot-joystick +<src/tools/krobot_joystick.{native,byte}>: use_krobot +<src/tools/krobot_joystick.{native,byte}>: pkg_lwt.syntax +<src/tools/krobot_joystick.{native,byte}>: pkg_sdl +<src/tools/krobot_joystick.{native,byte}>: pkg_lwt.unix +<src/tools/krobot_joystick.{native,byte}>: pkg_lwt.react +<src/tools/*.ml{,i}>: pkg_sdl +# Executable krobot-pet +<src/tools/krobot_pet.{native,byte}>: use_krobot +<src/tools/krobot_pet.{native,byte}>: pkg_lwt.syntax +<src/tools/krobot_pet.{native,byte}>: pkg_lwt.unix +<src/tools/krobot_pet.{native,byte}>: pkg_lwt.react +# Executable krobot-urg +<src/tools/krobot_urg.{native,byte}>: use_krobot +<src/tools/krobot_urg.{native,byte}>: pkg_lwt.syntax +<src/tools/krobot_urg.{native,byte}>: pkg_urg +<src/tools/krobot_urg.{native,byte}>: pkg_lwt.preemptive +<src/tools/krobot_urg.{native,byte}>: pkg_threads +<src/tools/krobot_urg.{native,byte}>: pkg_lwt.unix +<src/tools/krobot_urg.{native,byte}>: pkg_lwt.react +<src/tools/*.ml{,i}>: use_krobot +<src/tools/*.ml{,i}>: pkg_lwt.syntax +<src/tools/*.ml{,i}>: pkg_urg +<src/tools/*.ml{,i}>: pkg_lwt.preemptive +<src/tools/*.ml{,i}>: pkg_threads +<src/tools/*.ml{,i}>: pkg_lwt.unix +<src/tools/*.ml{,i}>: pkg_lwt.react +# Executable dump-can +<examples/dump_can.{native,byte}>: use_krobot-can +<examples/dump_can.{native,byte}>: use_krobot +<examples/dump_can.{native,byte}>: pkg_lwt.syntax +<examples/dump_can.{native,byte}>: pkg_sexplib +<examples/dump_can.{native,byte}>: pkg_sexplib.syntax +<examples/dump_can.{native,byte}>: pkg_lwt.unix +<examples/dump_can.{native,byte}>: pkg_bitstring +<examples/dump_can.{native,byte}>: pkg_lwt.react +# Executable send-can +<examples/send_can.{native,byte}>: use_krobot-can +<examples/send_can.{native,byte}>: use_krobot +<examples/send_can.{native,byte}>: pkg_lwt.syntax +<examples/send_can.{native,byte}>: pkg_sexplib +<examples/send_can.{native,byte}>: pkg_sexplib.syntax +<examples/send_can.{native,byte}>: pkg_lwt.unix +<examples/send_can.{native,byte}>: pkg_bitstring +<examples/send_can.{native,byte}>: pkg_lwt.react +<examples/*.ml{,i}>: use_krobot-can +<examples/*.ml{,i}>: use_krobot +<examples/*.ml{,i}>: pkg_lwt.syntax +<examples/*.ml{,i}>: pkg_sexplib +<examples/*.ml{,i}>: pkg_sexplib.syntax +<examples/*.ml{,i}>: pkg_lwt.unix +<examples/*.ml{,i}>: pkg_bitstring +<examples/*.ml{,i}>: pkg_lwt.react # OASIS_STOP diff --git a/info/control2011/myocamlbuild.ml b/info/control2011/myocamlbuild.ml index 86231e0..ebd412e 100644 --- a/info/control2011/myocamlbuild.ml +++ b/info/control2011/myocamlbuild.ml @@ -1,4 +1,499 @@ (* OASIS_START *) +(* DO NOT EDIT (digest: d2ba10e1d203a414b96ccf471790ac22) *) +module OASISGettext = struct +(* # 21 "/home/chambart/.opam/base/build/oasis.0.3.0/src/oasis/OASISGettext.ml" *) + + let ns_ str = + str + + let s_ str = + str + + let f_ (str : ('a, 'b, 'c, 'd) format4) = + str + + let fn_ fmt1 fmt2 n = + if n = 1 then + fmt1^^"" + else + fmt2^^"" + + let init = + [] + +end + +module OASISExpr = struct +(* # 21 "/home/chambart/.opam/base/build/oasis.0.3.0/src/oasis/OASISExpr.ml" *) + + + + open OASISGettext + + type test = string + + type flag = string + + type t = + | EBool of bool + | ENot of t + | EAnd of t * t + | EOr of t * t + | EFlag of flag + | ETest of test * string + + + type 'a choices = (t * 'a) list + + let eval var_get t = + let rec eval' = + function + | EBool b -> + b + + | ENot e -> + not (eval' e) + + | EAnd (e1, e2) -> + (eval' e1) && (eval' e2) + + | EOr (e1, e2) -> + (eval' e1) || (eval' e2) + + | EFlag nm -> + let v = + var_get nm + in + assert(v = "true" || v = "false"); + (v = "true") + + | ETest (nm, vl) -> + let v = + var_get nm + in + (v = vl) + in + eval' t + + let choose ?printer ?name var_get lst = + let rec choose_aux = + function + | (cond, vl) :: tl -> + if eval var_get cond then + vl + else + choose_aux tl + | [] -> + let str_lst = + if lst = [] then + s_ "<empty>" + else + String.concat + (s_ ", ") + (List.map + (fun (cond, vl) -> + match printer with + | Some p -> p vl + | None -> s_ "<no printer>") + lst) + in + match name with + | Some nm -> + failwith + (Printf.sprintf + (f_ "No result for the choice list '%s': %s") + nm str_lst) + | None -> + failwith + (Printf.sprintf + (f_ "No result for a choice list: %s") + str_lst) + in + choose_aux (List.rev lst) + +end + + +# 117 "myocamlbuild.ml" +module BaseEnvLight = struct +(* # 21 "/home/chambart/.opam/base/build/oasis.0.3.0/src/base/BaseEnvLight.ml" *) + + module MapString = Map.Make(String) + + type t = string MapString.t + + let default_filename = + Filename.concat + (Sys.getcwd ()) + "setup.data" + + let load ?(allow_empty=false) ?(filename=default_filename) () = + if Sys.file_exists filename then + begin + let chn = + open_in_bin filename + in + let st = + Stream.of_channel chn + in + let line = + ref 1 + in + let st_line = + Stream.from + (fun _ -> + try + match Stream.next st with + | '\n' -> incr line; Some '\n' + | c -> Some c + with Stream.Failure -> None) + in + let lexer = + Genlex.make_lexer ["="] st_line + in + let rec read_file mp = + match Stream.npeek 3 lexer with + | [Genlex.Ident nm; Genlex.Kwd "="; Genlex.String value] -> + Stream.junk lexer; + Stream.junk lexer; + Stream.junk lexer; + read_file (MapString.add nm value mp) + | [] -> + mp + | _ -> + failwith + (Printf.sprintf + "Malformed data file '%s' line %d" + filename !line) + in + let mp = + read_file MapString.empty + in + close_in chn; + mp + end + else if allow_empty then + begin + MapString.empty + end + else + begin + failwith + (Printf.sprintf + "Unable to load environment, the file '%s' doesn't exist." + filename) + end + + let var_get name env = + let rec var_expand str = + let buff = + Buffer.create ((String.length str) * 2) + in + Buffer.add_substitute + buff + (fun var -> + try + var_expand (MapString.find var env) + with Not_found -> + failwith + (Printf.sprintf + "No variable %s defined when trying to expand %S." + var + str)) + str; + Buffer.contents buff + in + var_expand (MapString.find name env) + + let var_choose lst env = + OASISExpr.choose + (fun nm -> var_get nm env) + lst +end + + +# 215 "myocamlbuild.ml" +module MyOCamlbuildFindlib = struct +(* # 21 "/home/chambart/.opam/base/build/oasis.0.3.0/src/plugins/ocamlbuild/MyOCamlbuildFindlib.ml" *) + + (** OCamlbuild extension, copied from + * http://brion.inria.fr/gallium/index.php/Using_ocamlfind_with_ocamlbuild + * by N. Pouillard and others + * + * Updated on 2009/02/28 + * + * Modified by Sylvain Le Gall + *) + open Ocamlbuild_plugin + + (* these functions are not really officially exported *) + let run_and_read = + Ocamlbuild_pack.My_unix.run_and_read + + let blank_sep_strings = + Ocamlbuild_pack.Lexers.blank_sep_strings + + let split s ch = + let x = + ref [] + in + let rec go s = + let pos = + String.index s ch + in + x := (String.before s pos)::!x; + go (String.after s (pos + 1)) + in + try + go s + with Not_found -> !x + + let split_nl s = split s '\n' + + let before_space s = + try + String.before s (String.index s ' ') + with Not_found -> s + + (* this lists all supported packages *) + let find_packages () = + List.map before_space (split_nl & run_and_read "ocamlfind list") + + (* this is supposed to list available syntaxes, but I don't know how to do it. *) + let find_syntaxes () = ["camlp4o"; "camlp4r"] + + (* ocamlfind command *) + let ocamlfind x = S[A"ocamlfind"; x] + + let dispatch = + function + | Before_options -> + (* by using Before_options one let command line options have an higher priority *) + (* on the contrary using After_options will guarantee to have the higher priority *) + (* override default commands by ocamlfind ones *) + Options.ocamlc := ocamlfind & A"ocamlc"; + Options.ocamlopt := ocamlfind & A"ocamlopt"; + Options.ocamldep := ocamlfind & A"ocamldep"; + Options.ocamldoc := ocamlfind & A"ocamldoc"; + Options.ocamlmktop := ocamlfind & A"ocamlmktop" + + | After_rules -> + + (* When one link an OCaml library/binary/package, one should use -linkpkg *) + flag ["ocaml"; "link"; "program"] & A"-linkpkg"; + + (* For each ocamlfind package one inject the -package option when + * compiling, computing dependencies, generating documentation and + * linking. *) + List.iter + begin fun pkg -> + flag ["ocaml"; "compile"; "pkg_"^pkg] & S[A"-package"; A pkg]; + flag ["ocaml"; "ocamldep"; "pkg_"^pkg] & S[A"-package"; A pkg]; + flag ["ocaml"; "doc"; "pkg_"^pkg] & S[A"-package"; A pkg]; + flag ["ocaml"; "link"; "pkg_"^pkg] & S[A"-package"; A pkg]; + flag ["ocaml"; "infer_interface"; "pkg_"^pkg] & S[A"-package"; A pkg]; + end + (find_packages ()); + + (* Like -package but for extensions syntax. Morover -syntax is useless + * when linking. *) + List.iter begin fun syntax -> + flag ["ocaml"; "compile"; "syntax_"^syntax] & S[A"-syntax"; A syntax]; + flag ["ocaml"; "ocamldep"; "syntax_"^syntax] & S[A"-syntax"; A syntax]; + flag ["ocaml"; "doc"; "syntax_"^syntax] & S[A"-syntax"; A syntax]; + flag ["ocaml"; "infer_interface"; "syntax_"^syntax] & S[A"-syntax"; A syntax]; + end (find_syntaxes ()); + + (* The default "thread" tag is not compatible with ocamlfind. + * Indeed, the default rules add the "threads.cma" or "threads.cmxa" + * options when using this tag. When using the "-linkpkg" option with + * ocamlfind, this module will then be added twice on the command line. + * + * To solve this, one approach is to add the "-thread" option when using + * the "threads" package using the previous plugin. + *) + flag ["ocaml"; "pkg_threads"; "compile"] (S[A "-thread"]); + flag ["ocaml"; "pkg_threads"; "doc"] (S[A "-I"; A "+threads"]); + flag ["ocaml"; "pkg_threads"; "link"] (S[A "-thread"]); + flag ["ocaml"; "pkg_threads"; "infer_interface"] (S[A "-thread"]) + + | _ -> + () + +end + +module MyOCamlbuildBase = struct +(* # 21 "/home/chambart/.opam/base/build/oasis.0.3.0/src/plugins/ocamlbuild/MyOCamlbuildBase.ml" *) + + (** Base functions for writing myocamlbuild.ml + @author Sylvain Le Gall + *) + + + + open Ocamlbuild_plugin + module OC = Ocamlbuild_pack.Ocaml_compiler + + type dir = string + type file = string + type name = string + type tag = string + +(* # 56 "/home/chambart/.opam/base/build/oasis.0.3.0/src/plugins/ocamlbuild/MyOCamlbuildBase.ml" *) + + type t = + { + lib_ocaml: (name * dir list) list; + lib_c: (name * dir * file list) list; + flags: (tag list * (spec OASISExpr.choices)) list; + (* Replace the 'dir: include' from _tags by a precise interdepends in + * directory. + *) + includes: (dir * dir list) list; + } + + let env_filename = + Pathname.basename + BaseEnvLight.default_filename + + let dispatch_combine lst = + fun e -> + List.iter + (fun dispatch -> dispatch e) + lst + + let tag_libstubs nm = + "use_lib"^nm^"_stubs" + + let nm_libstubs nm = + nm^"_stubs" + + let dispatch t e = + let env = + BaseEnvLight.load + ~filename:env_filename + ~allow_empty:true + () + in + match e with + | Before_options -> + let no_trailing_dot s = + if String.length s >= 1 && s.[0] = '.' then + String.sub s 1 ((String.length s) - 1) + else + s + in + List.iter + (fun (opt, var) -> + try + opt := no_trailing_dot (BaseEnvLight.var_get var env) + with Not_found -> + Printf.eprintf "W: Cannot get variable %s" var) + [ + Options.ext_obj, "ext_obj"; + Options.ext_lib, "ext_lib"; + Options.ext_dll, "ext_dll"; + ] + + | After_rules -> + (* Declare OCaml libraries *) + List.iter + (function + | nm, [] -> + ocaml_lib nm + | nm, dir :: tl -> + ocaml_lib ~dir:dir (dir^"/"^nm); + List.iter + (fun dir -> + List.iter + (fun str -> + flag ["ocaml"; "use_"^nm; str] (S[A"-I"; P dir])) + ["compile"; "infer_interface"; "doc"]) + tl) + t.lib_ocaml; + + (* Declare directories dependencies, replace "include" in _tags. *) + List.iter + (fun (dir, include_dirs) -> + Pathname.define_context dir include_dirs) + t.includes; + + (* Declare C libraries *) + List.iter + (fun (lib, dir, headers) -> + (* Handle C part of library *) + flag ["link"; "library"; "ocaml"; "byte"; tag_libstubs lib] + (S[A"-dllib"; A("-l"^(nm_libstubs lib)); A"-cclib"; + A("-l"^(nm_libstubs lib))]); + + flag ["link"; "library"; "ocaml"; "native"; tag_libstubs lib] + (S[A"-cclib"; A("-l"^(nm_libstubs lib))]); + + flag ["link"; "program"; "ocaml"; "byte"; tag_libstubs lib] + (S[A"-dllib"; A("dll"^(nm_libstubs lib))]); + + (* When ocaml link something that use the C library, then one + need that file to be up to date. + *) + dep ["link"; "ocaml"; "program"; tag_libstubs lib] + [dir/"lib"^(nm_libstubs lib)^"."^(!Options.ext_lib)]; + + dep ["compile"; "ocaml"; "program"; tag_libstubs lib] + [dir/"lib"^(nm_libstubs lib)^"."^(!Options.ext_lib)]; + + (* TODO: be more specific about what depends on headers *) + (* Depends on .h files *) + dep ["compile"; "c"] + headers; + + (* Setup search path for lib *) + flag ["link"; "ocaml"; "use_"^lib] + (S[A"-I"; P(dir)]); + ) + t.lib_c; + + (* Add flags *) + List.iter + (fun (tags, cond_specs) -> + let spec = + BaseEnvLight.var_choose cond_specs env + in + flag tags & spec) + t.flags + | _ -> + () + + let dispatch_default t = + dispatch_combine + [ + dispatch t; + MyOCamlbuildFindlib.dispatch; + ] + +end + + +# 476 "myocamlbuild.ml" +open Ocamlbuild_plugin;; +let package_default = + { + MyOCamlbuildBase.lib_ocaml = + [("krobot", ["src/lib"]); ("krobot-can", ["src/can"])]; + lib_c = [("krobot", "src/lib", []); ("krobot-can", "src/can", [])]; + flags = []; + includes = + [ + ("src/tools", ["src/can"; "src/lib"]); + ("src/driver", ["src/can"; "src/lib"]); + ("src/can", ["src/lib"]); + ("examples", ["src/can"]) + ]; + } + ;; + +let dispatch_default = MyOCamlbuildBase.dispatch_default package_default;; + +# 497 "myocamlbuild.ml" (* OASIS_STOP *) open Ocamlbuild_plugin diff --git a/info/control2011/setup.ml b/info/control2011/setup.ml index f41d9b8..0e2f232 100644 --- a/info/control2011/setup.ml +++ b/info/control2011/setup.ml @@ -8,10 +8,6857 @@ *) (* OASIS_START *) -(* DO NOT EDIT (digest: 7f47a529f70709161149c201ccd90f0b) *) -#use "topfind";; -#require "oasis.dynrun";; -open OASISDynRun;; +(* DO NOT EDIT (digest: 93e97b5dfbc11c54162cfd7f571db7a3) *) +(* + Regenerated by OASIS v0.3.0 + Visit http://oasis.forge.ocamlcore.org for more information and + documentation about functions used in this file. +*) +module OASISGettext = struct +(* # 21 "/home/chambart/.opam/base/build/oasis.0.3.0/src/oasis/OASISGettext.ml" *) + + let ns_ str = + str + + let s_ str = + str + + let f_ (str : ('a, 'b, 'c, 'd) format4) = + str + + let fn_ fmt1 fmt2 n = + if n = 1 then + fmt1^^"" + else + fmt2^^"" + + let init = + [] + +end + +module OASISContext = struct +(* # 21 "/home/chambart/.opam/base/build/oasis.0.3.0/src/oasis/OASISContext.ml" *) + + open OASISGettext + + type level = + [ `Debug + | `Info + | `Warning + | `Error] + + type t = + { + quiet: bool; + info: bool; + debug: bool; + ignore_plugins: bool; + ignore_unknown_fields: bool; + printf: level -> string -> unit; + } + + let printf lvl str = + let beg = + match lvl with + | `Error -> s_ "E: " + | `Warning -> s_ "W: " + | `Info -> s_ "I: " + | `Debug -> s_ "D: " + in + prerr_endline (beg^str) + + let default = + ref + { + quiet = false; + info = false; + debug = false; + ignore_plugins = false; + ignore_unknown_fields = false; + printf = printf; + } + + let quiet = + {!default with quiet = true} + + + let args () = + ["-quiet", + Arg.Unit (fun () -> default := {!default with quiet = true}), + (s_ " Run quietly"); + + "-info", + Arg.Unit (fun () -> default := {!default with info = true}), + (s_ " Display information message"); + + + "-debug", + Arg.Unit (fun () -> default := {!default with debug = true}), + (s_ " Output debug message")] +end + +module OASISString = struct +(* # 1 "/home/chambart/.opam/base/build/oasis.0.3.0/src/oasis/OASISString.ml" *) + + + + (** Various string utilities. + + Mostly inspired by extlib and batteries ExtString and BatString libraries. + + @author Sylvain Le Gall + *) + + let nsplitf str f = + if str = "" then + [] + else + let buf = Buffer.create 13 in + let lst = ref [] in + let push () = + lst := Buffer.contents buf :: !lst; + Buffer.clear buf + in + let str_len = String.length str in + for i = 0 to str_len - 1 do + if f str.[i] then + push () + else + Buffer.add_char buf str.[i] + done; + push (); + List.rev !lst + + (** [nsplit c s] Split the string [s] at char [c]. It doesn't include the + separator. + *) + let nsplit str c = + nsplitf str ((=) c) + + let find ~what ?(offset=0) str = + let what_idx = ref 0 in + let str_idx = ref offset in + while !str_idx < String.length str && + !what_idx < String.length what do + if str.[!str_idx] = what.[!what_idx] then + incr what_idx + else + what_idx := 0; + incr str_idx + done; + if !what_idx <> String.length what then + raise Not_found + else + !str_idx - !what_idx + + let sub_start str len = + let str_len = String.length str in + if len >= str_len then + "" + else + String.sub str len (str_len - len) + + let sub_end ?(offset=0) str len = + let str_len = String.length str in + if len >= str_len then + "" + else + String.sub str 0 (str_len - len) + + let starts_with ~what ?(offset=0) str = + let what_idx = ref 0 in + let str_idx = ref offset in + let ok = ref true in + while !ok && + !str_idx < String.length str && + !what_idx < String.length what do + if str.[!str_idx] = what.[!what_idx] then + incr what_idx + else + ok := false; + incr str_idx + done; + if !what_idx = String.length what then + true + else + false + + let strip_starts_with ~what str = + if starts_with ~what str then + sub_start str (String.length what) + else + raise Not_found + + let ends_with ~what ?(offset=0) str = + let what_idx = ref ((String.length what) - 1) in + let str_idx = ref ((String.length str) - 1) in + let ok = ref true in + while !ok && + offset <= !str_idx && + 0 <= !what_idx do + if str.[!str_idx] = what.[!what_idx] then + decr what_idx + else + ok := false; + decr str_idx + done; + if !what_idx = -1 then + true + else + false + + let strip_ends_with ~what str = + if ends_with ~what str then + sub_end str (String.length what) + else + raise Not_found + + let replace_chars f s = + let buf = String.make (String.length s) 'X' in + for i = 0 to String.length s - 1 do + buf.[i] <- f s.[i] + done; + buf + +end + +module OASISUtils = struct +(* # 21 "/home/chambart/.opam/base/build/oasis.0.3.0/src/oasis/OASISUtils.ml" *) + + open OASISGettext + + module MapString = Map.Make(String) + + let map_string_of_assoc assoc = + List.fold_left + (fun acc (k, v) -> MapString.add k v acc) + MapString.empty + assoc + + module SetString = Set.Make(String) + + let set_string_add_list st lst = + List.fold_left + (fun acc e -> SetString.add e acc) + st + lst + + let set_string_of_list = + set_string_add_list + SetString.empty + + + let compare_csl s1 s2 = + String.compare (String.lowercase s1) (String.lowercase s2) + + module HashStringCsl = + Hashtbl.Make + (struct + type t = string + + let equal s1 s2 = + (String.lowercase s1) = (String.lowercase s2) + + let hash s = + Hashtbl.hash (String.lowercase s) + end) + + let varname_of_string ?(hyphen='_') s = + if String.length s = 0 then + begin + invalid_arg "varname_of_string" + end + else + begin + let buf = + OASISString.replace_chars + (fun c -> + if ('a' <= c && c <= 'z') + || + ('A' <= c && c <= 'Z') + || + ('0' <= c && c <= '9') then + c + else + hyphen) + s; + in + let buf = + (* Start with a _ if digit *) + if '0' <= s.[0] && s.[0] <= '9' then + "_"^buf + else + buf + in + String.lowercase buf + end + + let varname_concat ?(hyphen='_') p s = + let what = String.make 1 hyphen in + let p = + try + OASISString.strip_ends_with ~what p + with Not_found -> + p + in + let s = + try + OASISString.strip_starts_with ~what s + with Not_found -> + s + in + p^what^s + + + let is_varname str = + str = varname_of_string str + + let failwithf fmt = Printf.ksprintf failwith fmt + +end + +module PropList = struct +(* # 21 "/home/chambart/.opam/base/build/oasis.0.3.0/src/oasis/PropList.ml" *) + + open OASISGettext + + type name = string + + exception Not_set of name * string option + exception No_printer of name + exception Unknown_field of name * name + + let () = + Printexc.register_printer + (function + | Not_set (nm, Some rsn) -> + Some + (Printf.sprintf (f_ "Field '%s' is not set: %s") nm rsn) + | Not_set (nm, None) -> + Some + (Printf.sprintf (f_ "Field '%s' is not set") nm) + | No_printer nm -> + Some + (Printf.sprintf (f_ "No default printer for value %s") nm) + | Unknown_field (nm, schm) -> + Some + (Printf.sprintf (f_ "Field %s is not defined in schema %s") nm schm) + | _ -> + None) + + module Data = + struct + + type t = + (name, unit -> unit) Hashtbl.t + + let create () = + Hashtbl.create 13 + + let clear t = + Hashtbl.clear t + +(* # 71 "/home/chambart/.opam/base/build/oasis.0.3.0/src/oasis/PropList.ml" *) + end + + module Schema = + struct + + type ('ctxt, 'extra) value = + { + get: Data.t -> string; + set: Data.t -> ?context:'ctxt -> string -> unit; + help: (unit -> string) option; + extra: 'extra; + } + + type ('ctxt, 'extra) t = + { + name: name; + fields: (name, ('ctxt, 'extra) value) Hashtbl.t; + order: name Queue.t; + name_norm: string -> string; + } + + let create ?(case_insensitive=false) nm = + { + name = nm; + fields = Hashtbl.create 13; + order = Queue.create (); + name_norm = + (if case_insensitive then + String.lowercase + else + fun s -> s); + } + + let add t nm set get extra help = + let key = + t.name_norm nm + in + + if Hashtbl.mem t.fields key then + failwith + (Printf.sprintf + (f_ "Field '%s' is already defined in schema '%s'") + nm t.name); + Hashtbl.add + t.fields + key + { + set = set; + get = get; + help = help; + extra = extra; + }; + Queue.add nm t.order + + let mem t nm = + Hashtbl.mem t.fields nm + + let find t nm = + try + Hashtbl.find t.fields (t.name_norm nm) + with Not_found -> + raise (Unknown_field (nm, t.name)) + + let get t data nm = + (find t nm).get data + + let set t data nm ?context x = + (find t nm).set + data + ?context + x + + let fold f acc t = + Queue.fold + (fun acc k -> + let v = + find t k + in + f acc k v.extra v.help) + acc + t.order + + let iter f t = + fold + (fun () -> f) + () + t + + let name t = + t.name + end + + module Field = + struct + + type ('ctxt, 'value, 'extra) t = + { + set: Data.t -> ?context:'ctxt -> 'value -> unit; + get: Data.t -> 'value; + sets: Data.t -> ?context:'ctxt -> string -> unit; + gets: Data.t -> string; + help: (unit -> string) option; + extra: 'extra; + } + + let new_id = + let last_id = + ref 0 + in + fun () -> incr last_id; !last_id + + let create ?schema ?name ?parse ?print ?default ?update ?help extra = + (* Default value container *) + let v = + ref None + in + + (* If name is not given, create unique one *) + let nm = + match name with + | Some s -> s + | None -> Printf.sprintf "_anon_%d" (new_id ()) + in + + (* Last chance to get a value: the default *) + let default () = + match default with + | Some d -> d + | None -> raise (Not_set (nm, Some (s_ "no default value"))) + in + + (* Get data *) + let get data = + (* Get value *) + try + (Hashtbl.find data nm) (); + match !v with + | Some x -> x + | None -> default () + with Not_found -> + default () + in + + (* Set data *) + let set data ?context x = + let x = + match update with + | Some f -> + begin + try + f ?context (get data) x + with Not_set _ -> + x + end + | None -> + x + in + Hashtbl.replace + data + nm + (fun () -> v := Some x) + in + + (* Parse string value, if possible *) + let parse = + match parse with + | Some f -> + f + | None -> + fun ?context s -> + failwith + (Printf.sprintf + (f_ "Cannot parse field '%s' when setting value %S") + nm + s) + in + + (* Set data, from string *) + let sets data ?context s = + set ?context data (parse ?context s) + in + + (* Output value as string, if possible *) + let print = + match print with + | Some f -> + f + | None -> + fun _ -> raise (No_printer nm) + in + + (* Get data, as a string *) + let gets data = + print (get data) + in + + begin + match schema with + | Some t -> + Schema.add t nm sets gets extra help + | None -> + () + end; + + { + set = set; + get = get; + sets = sets; + gets = gets; + help = help; + extra = extra; + } + + let fset data t ?context x = + t.set data ?context x + + let fget data t = + t.get data + + let fsets data t ?context s = + t.sets data ?context s + + let fgets data t = + t.gets data + + end + + module FieldRO = + struct + + let create ?schema ?name ?parse ?print ?default ?update ?help extra = + let fld = + Field.create ?schema ?name ?parse ?print ?default ?update ?help extra + in + fun data -> Field.fget data fld + + end +end + +module OASISMessage = struct +(* # 21 "/home/chambart/.opam/base/build/oasis.0.3.0/src/oasis/OASISMessage.ml" *) + + + open OASISGettext + open OASISContext + + let generic_message ~ctxt lvl fmt = + let cond = + if ctxt.quiet then + false + else + match lvl with + | `Debug -> ctxt.debug + | `Info -> ctxt.info + | _ -> true + in + Printf.ksprintf + (fun str -> + if cond then + begin + ctxt.printf lvl str + end) + fmt + + let debug ~ctxt fmt = + generic_message ~ctxt `Debug fmt + + let info ~ctxt fmt = + generic_message ~ctxt `Info fmt + + let warning ~ctxt fmt = + generic_message ~ctxt `Warning fmt + + let error ~ctxt fmt = + generic_message ~ctxt `Error fmt + +end + +module OASISVersion = struct +(* # 21 "/home/chambart/.opam/base/build/oasis.0.3.0/src/oasis/OASISVersion.ml" *) + + open OASISGettext + + + + type s = string + + type t = string + + type comparator = + | VGreater of t + | VGreaterEqual of t + | VEqual of t + | VLesser of t + | VLesserEqual of t + | VOr of comparator * comparator + | VAnd of comparator * comparator + + + (* Range of allowed characters *) + let is_digit c = + '0' <= c && c <= '9' + + let is_alpha c = + ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') + + let is_special = + function + | '.' | '+' | '-' | '~' -> true + | _ -> false + + let rec version_compare v1 v2 = + if v1 <> "" || v2 <> "" then + begin + (* Compare ascii string, using special meaning for version + * related char + *) + let val_ascii c = + if c = '~' then -1 + else if is_digit c then 0 + else if c = '\000' then 0 + else if is_alpha c then Char.code c + else (Char.code c) + 256 + in + + let len1 = String.length v1 in + let len2 = String.length v2 in + + let p = ref 0 in + + (** Compare ascii part *) + let compare_vascii () = + let cmp = ref 0 in + while !cmp = 0 && + !p < len1 && !p < len2 && + not (is_digit v1.[!p] && is_digit v2.[!p]) do + cmp := (val_ascii v1.[!p]) - (val_ascii v2.[!p]); + incr p + done; + if !cmp = 0 && !p < len1 && !p = len2 then + val_ascii v1.[!p] + else if !cmp = 0 && !p = len1 && !p < len2 then + - (val_ascii v2.[!p]) + else + !cmp + in + + (** Compare digit part *) + let compare_digit () = + let extract_int v p = + let start_p = !p in + while !p < String.length v && is_digit v.[!p] do + incr p + done; + let substr = + String.sub v !p ((String.length v) - !p) + in + let res = + match String.sub v start_p (!p - start_p) with + | "" -> 0 + | s -> int_of_string s + in + res, substr + in + let i1, tl1 = extract_int v1 (ref !p) in + let i2, tl2 = extract_int v2 (ref !p) in + i1 - i2, tl1, tl2 + in + + match compare_vascii () with + | 0 -> + begin + match compare_digit () with + | 0, tl1, tl2 -> + if tl1 <> "" && is_digit tl1.[0] then + 1 + else if tl2 <> "" && is_digit tl2.[0] then + -1 + else + version_compare tl1 tl2 + | n, _, _ -> + n + end + | n -> + n + end + else + begin + 0 + end + + + let version_of_string str = str + + let string_of_version t = t + + let chop t = + try + let pos = + String.rindex t '.' + in + String.sub t 0 pos + with Not_found -> + t + + let rec comparator_apply v op = + match op with + | VGreater cv -> + (version_compare v cv) > 0 + | VGreaterEqual cv -> + (version_compare v cv) >= 0 + | VLesser cv -> + (version_compare v cv) < 0 + | VLesserEqual cv -> + (version_compare v cv) <= 0 + | VEqual cv -> + (version_compare v cv) = 0 + | VOr (op1, op2) -> + (comparator_apply v op1) || (comparator_apply v op2) + | VAnd (op1, op2) -> + (comparator_apply v op1) && (comparator_apply v op2) + + let rec string_of_comparator = + function + | VGreater v -> "> "^(string_of_version v) + | VEqual v -> "= "^(string_of_version v) + | VLesser v -> "< "^(string_of_version v) + | VGreaterEqual v -> ">= "^(string_of_version v) + | VLesserEqual v -> "<= "^(string_of_version v) + | VOr (c1, c2) -> + (string_of_comparator c1)^" || "^(string_of_comparator c2) + | VAnd (c1, c2) -> + (string_of_comparator c1)^" && "^(string_of_comparator c2) + + let rec varname_of_comparator = + let concat p v = + OASISUtils.varname_concat + p + (OASISUtils.varname_of_string + (string_of_version v)) + in + function + | VGreater v -> concat "gt" v + | VLesser v -> concat "lt" v + | VEqual v -> concat "eq" v + | VGreaterEqual v -> concat "ge" v + | VLesserEqual v -> concat "le" v + | VOr (c1, c2) -> + (varname_of_comparator c1)^"_or_"^(varname_of_comparator c2) + | VAnd (c1, c2) -> + (varname_of_comparator c1)^"_and_"^(varname_of_comparator c2) + + let version_0_3_or_after t = + comparator_apply t (VGreaterEqual (string_of_version "0.3")) + +end + +module OASISLicense = struct +(* # 21 "/home/chambart/.opam/base/build/oasis.0.3.0/src/oasis/OASISLicense.ml" *) + + (** License for _oasis fields + @author Sylvain Le Gall + *) + + + + type license = string + + type license_exception = string + + type license_version = + | Version of OASISVersion.t + | VersionOrLater of OASISVersion.t + | NoVersion + + + type license_dep_5_unit = + { + license: license; + excption: license_exception option; + version: license_version; + } + + + type license_dep_5 = + | DEP5Unit of license_dep_5_unit + | DEP5Or of license_dep_5 list + | DEP5And of license_dep_5 list + + + type t = + | DEP5License of license_dep_5 + | OtherLicense of string (* URL *) + + +end + +module OASISExpr = struct +(* # 21 "/home/chambart/.opam/base/build/oasis.0.3.0/src/oasis/OASISExpr.ml" *) + + + + open OASISGettext + + type test = string + + type flag = string + + type t = + | EBool of bool + | ENot of t + | EAnd of t * t + | EOr of t * t + | EFlag of flag + | ETest of test * string + + + type 'a choices = (t * 'a) list + + let eval var_get t = + let rec eval' = + function + | EBool b -> + b + + | ENot e -> + not (eval' e) + + | EAnd (e1, e2) -> + (eval' e1) && (eval' e2) + + | EOr (e1, e2) -> + (eval' e1) || (eval' e2) + + | EFlag nm -> + let v = + var_get nm + in + assert(v = "true" || v = "false"); + (v = "true") + + | ETest (nm, vl) -> + let v = + var_get nm + in + (v = vl) + in + eval' t + + let choose ?printer ?name var_get lst = + let rec choose_aux = + function + | (cond, vl) :: tl -> + if eval var_get cond then + vl + else + choose_aux tl + | [] -> + let str_lst = + if lst = [] then + s_ "<empty>" + else + String.concat + (s_ ", ") + (List.map + (fun (cond, vl) -> + match printer with + | Some p -> p vl + | None -> s_ "<no printer>") + lst) + in + match name with + | Some nm -> + failwith + (Printf.sprintf + (f_ "No result for the choice list '%s': %s") + nm str_lst) + | None -> + failwith + (Printf.sprintf + (f_ "No result for a choice list: %s") + str_lst) + in + choose_aux (List.rev lst) + +end + +module OASISTypes = struct +(* # 21 "/home/chambart/.opam/base/build/oasis.0.3.0/src/oasis/OASISTypes.ml" *) + + + + + type name = string + type package_name = string + type url = string + type unix_dirname = string + type unix_filename = string + type host_dirname = string + type host_filename = string + type prog = string + type arg = string + type args = string list + type command_line = (prog * arg list) + + type findlib_name = string + type findlib_full = string + + type compiled_object = + | Byte + | Native + | Best + + + type dependency = + | FindlibPackage of findlib_full * OASISVersion.comparator option + | InternalLibrary of name + + + type tool = + | ExternalTool of name + | InternalExecutable of name + + + type vcs = + | Darcs + | Git + | Svn + | Cvs + | Hg + | Bzr + | Arch + | Monotone + | OtherVCS of url + + + type plugin_kind = + [ `Configure + | `Build + | `Doc + | `Test + | `Install + | `Extra + ] + + type plugin_data_purpose = + [ `Configure + | `Build + | `Install + | `Clean + | `Distclean + | `Install + | `Uninstall + | `Test + | `Doc + | `Extra + | `Other of string + ] + + type 'a plugin = 'a * name * OASISVersion.t option + + type all_plugin = plugin_kind plugin + + type plugin_data = (all_plugin * plugin_data_purpose * (unit -> unit)) list + +(* # 102 "/home/chambart/.opam/base/build/oasis.0.3.0/src/oasis/OASISTypes.ml" *) + + type 'a conditional = 'a OASISExpr.choices + + type custom = + { + pre_command: (command_line option) conditional; + post_command: (command_line option) conditional; + } + + + type common_section = + { + cs_name: name; + cs_data: PropList.Data.t; + cs_plugin_data: plugin_data; + } + + + type build_section = + { + bs_build: bool conditional; + bs_install: bool conditional; + bs_path: unix_dirname; + bs_compiled_object: compiled_object; + bs_build_depends: dependency list; + bs_build_tools: tool list; + bs_c_sources: unix_filename list; + bs_data_files: (unix_filename * unix_filename option) list; + bs_ccopt: args conditional; + bs_cclib: args conditional; + bs_dlllib: args conditional; + bs_dllpath: args conditional; + bs_byteopt: args conditional; + bs_nativeopt: args conditional; + } + + + type library = + { + lib_modules: string list; + lib_pack: bool; + lib_internal_modules: string list; + lib_findlib_parent: findlib_name option; + lib_findlib_name: findlib_name option; + lib_findlib_containers: findlib_name list; + } + + type executable = + { + exec_custom: bool; + exec_main_is: unix_filename; + } + + type flag = + { + flag_description: string option; + flag_default: bool conditional; + } + + type source_repository = + { + src_repo_type: vcs; + src_repo_location: url; + src_repo_browser: url option; + src_repo_module: string option; + src_repo_branch: string option; + src_repo_tag: string option; + src_repo_subdir: unix_filename option; + } + + type test = + { + test_type: [`Test] plugin; + test_command: command_line conditional; + test_custom: custom; + test_working_directory: unix_filename option; + test_run: bool conditional; + test_tools: tool list; + } + + type doc_format = + | HTML of unix_filename + | DocText + | PDF + | PostScript + | Info of unix_filename + | DVI + | OtherDoc + + + type doc = + { + doc_type: [`Doc] plugin; + doc_custom: custom; + doc_build: bool conditional; + doc_install: bool conditional; + doc_install_dir: unix_filename; + doc_title: string; + doc_authors: string list; + doc_abstract: string option; + doc_format: doc_format; + doc_data_files: (unix_filename * unix_filename option) list; + doc_build_tools: tool list; + } + + type section = + | Library of common_section * build_section * library + | Executable of common_section * build_section * executable + | Flag of common_section * flag + | SrcRepo of common_section * source_repository + | Test of common_section * test + | Doc of common_section * doc + + + type section_kind = + [ `Library | `Executable | `Flag | `SrcRepo | `Test | `Doc ] + + type package = + { + oasis_version: OASISVersion.t; + ocaml_version: OASISVersion.comparator option; + findlib_version: OASISVersion.comparator option; + name: package_name; + version: OASISVersion.t; + license: OASISLicense.t; + license_file: unix_filename option; + copyrights: string list; + maintainers: string list; + authors: string list; + homepage: url option; + synopsis: string; + description: string option; + categories: url list; + + conf_type: [`Configure] plugin; + conf_custom: custom; + + build_type: [`Build] plugin; + build_custom: custom; + + install_type: [`Install] plugin; + install_custom: custom; + uninstall_custom: custom; + + clean_custom: custom; + distclean_custom: custom; + + files_ab: unix_filename list; + sections: section list; + plugins: [`Extra] plugin list; + schema_data: PropList.Data.t; + plugin_data: plugin_data; + } + +end + +module OASISUnixPath = struct +(* # 21 "/home/chambart/.opam/base/build/oasis.0.3.0/src/oasis/OASISUnixPath.ml" *) + + type unix_filename = string + type unix_dirname = string + + type host_filename = string + type host_dirname = string + + let current_dir_name = "." + + let parent_dir_name = ".." + + let is_current_dir fn = + fn = current_dir_name || fn = "" + + let concat f1 f2 = + if is_current_dir f1 then + f2 + else + let f1' = + try OASISString.strip_ends_with ~what:"/" f1 with Not_found -> f1 + in + f1'^"/"^f2 + + let make = + function + | hd :: tl -> + List.fold_left + (fun f p -> concat f p) + hd + tl + | [] -> + invalid_arg "OASISUnixPath.make" + + let dirname f = + try + String.sub f 0 (String.rindex f '/') + with Not_found -> + current_dir_name + + let basename f = + try + let pos_start = + (String.rindex f '/') + 1 + in + String.sub f pos_start ((String.length f) - pos_start) + with Not_found -> + f + + let chop_extension f = + try + let last_dot = + String.rindex f '.' + in + let su... [truncated message content] |
From: Xavier L. <Ba...@us...> - 2013-04-04 19:04:18
|
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 367d701262d78c6d664a24f4eee9a27c79b5329e (commit) from 04a94c1d43ea27ee28a782ab2d7a160d3beb64f4 (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 367d701262d78c6d664a24f4eee9a27c79b5329e Author: Xavier Lagorce <Xav...@cr...> Date: Thu Apr 4 21:09:27 2013 +0200 [info/Krobot_config] This cake is not a lie ----------------------------------------------------------------------- Changes: diff --git a/info/control2011/src/lib/krobot_config.ml b/info/control2011/src/lib/krobot_config.ml index 2c103bf..434f125 100644 --- a/info/control2011/src/lib/krobot_config.ml +++ b/info/control2011/src/lib/krobot_config.ml @@ -68,7 +68,7 @@ let left_obstacles = size = sqrt (2. *. 0.125 *. 0.125) +. 0.12; };*) (* entry position *) - { pos = + (*{ pos = { x = 0.; y = 1.5 }; size = 0.02; }; @@ -87,7 +87,7 @@ let left_obstacles = { pos = { x = 0.4; y = 1.5 }; - size = 0.02; }; + size = 0.02; };*) (* coins at the bottom *) (* @@ -97,14 +97,16 @@ let left_obstacles = size = 0.15 }; *) - ] @ (line_obs { x = 0.325; y = 0. } { x = 0.325 +. (0.075 /. 2.); y = 0.75 } ) + (*] @ (line_obs { x = 0.325; y = 0. } { x = 0.325 +. (0.075 /. 2.); y = 0.75 } )*) + ] let fixed_obstacles = [ - (*{ pos = + (* Cake *) + { pos = { x = 1.5; - y = 1. }; - size = 0.1; };*) + y = 2. }; + size = 0.5; }; ] @ (List.map symetrical left_obstacles) @ left_obstacles hooks/post-receive -- krobot |
From: Xavier L. <Ba...@us...> - 2013-04-04 18:52:41
|
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 04a94c1d43ea27ee28a782ab2d7a160d3beb64f4 (commit) from ff6cb2aa4ad32d94b2e4713ebe2032fc5589a455 (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 04a94c1d43ea27ee28a782ab2d7a160d3beb64f4 Author: Xavier Lagorce <Xav...@cr...> Date: Thu Apr 4 20:57:32 2013 +0200 [info/Krobot_vm] Lower rotational speed for prototype of new beacon system ----------------------------------------------------------------------- Changes: diff --git a/info/control2011/src/tools/krobot_vm.ml b/info/control2011/src/tools/krobot_vm.ml index 7df6b4c..c88eca8 100644 --- a/info/control2011/src/tools/krobot_vm.ml +++ b/info/control2011/src/tools/krobot_vm.ml @@ -845,7 +845,7 @@ lwt () = ignore ( lwt () = Lwt_unix.sleep 2. in - Krobot_message.send bus (Unix.gettimeofday (),Motor_command (2,1000))); + Krobot_message.send bus (Unix.gettimeofday (),Motor_command (2,500))); ignore(blink bus false); hooks/post-receive -- krobot |
From: Xavier L. <Ba...@us...> - 2013-03-27 22:43:00
|
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 ff6cb2aa4ad32d94b2e4713ebe2032fc5589a455 (commit) from aa100442b8a79fa3dc718c80e03594675cf67ab1 (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 ff6cb2aa4ad32d94b2e4713ebe2032fc5589a455 Author: Xavier Lagorce <Xav...@cr...> Date: Wed Mar 27 23:47:49 2013 +0100 [info/control2011] Removed central obstacles from the table ----------------------------------------------------------------------- Changes: diff --git a/info/control2011/src/lib/krobot_config.ml b/info/control2011/src/lib/krobot_config.ml index 04a3fcd..2c103bf 100644 --- a/info/control2011/src/lib/krobot_config.ml +++ b/info/control2011/src/lib/krobot_config.ml @@ -62,10 +62,10 @@ let line_obs p1 p2 = let left_obstacles = [ (* the trees *) - { pos = + (*{ pos = { x = 0.64 +. 0.477; y = 1. }; - size = sqrt (2. *. 0.125 *. 0.125) +. 0.12; }; + size = sqrt (2. *. 0.125 *. 0.125) +. 0.12; };*) (* entry position *) { pos = @@ -101,10 +101,10 @@ let left_obstacles = let fixed_obstacles = [ - { pos = + (*{ pos = { x = 1.5; y = 1. }; - size = 0.1; }; + size = 0.1; };*) ] @ (List.map symetrical left_obstacles) @ left_obstacles hooks/post-receive -- krobot |
From: Xavier L. <Ba...@us...> - 2013-03-27 22:29:43
|
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 aa100442b8a79fa3dc718c80e03594675cf67ab1 (commit) from 626a08aeb7e638f96d01ae519611fd42d3f4506b (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 aa100442b8a79fa3dc718c80e03594675cf67ab1 Author: Xavier Lagorce <Xav...@cr...> Date: Wed Mar 27 23:33:27 2013 +0100 [Controller_motor_STM32] Wheels can have different radii (and new structural values for the robot) ----------------------------------------------------------------------- Changes: diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/main.c b/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/main.c index e4b87bf..66e9f8c 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/main.c +++ b/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/main.c @@ -17,8 +17,11 @@ #include "command_generator.h" #include "differential_drive.h" -#define PROP_WHEEL_RADIUS 0.049245 -#define PROP_SHAFT_WIDTH 0.22264 +//#define PROP_WHEEL_RADIUS 0.049245 +#define PROP_WHEEL_RADIUS_LEFT 0.049207 +#define PROP_WHEEL_RADIUS_RIGHT 0.049283 +#define PROP_WHEEL_RADIUS ((PROP_WHEEL_RADIUS_RIGHT+PROP_WHEEL_RADIUS_LEFT)/2) +#define PROP_SHAFT_WIDTH 0.22587 #define INDEP_WHEEL_RADIUS 0.0359 #define INDEP_SHAFT_WIDTH 0.266 @@ -53,7 +56,7 @@ static void init(void) // Start control of drive motors tc_init(); dd_start(CONTROL_ODOMETRY, // Use odometry CONTROL_ODOMETRY for control - PROP_WHEEL_RADIUS, PROP_SHAFT_WIDTH, // Structural parameters + PROP_WHEEL_RADIUS_LEFT, PROP_WHEEL_RADIUS_RIGHT, PROP_SHAFT_WIDTH, // Structural parameters 8*2*M_PI, // Absolute wheel speed limitation 0.5, // Linear velocity limitation 1.0, // Linear acceleration limitation @@ -82,11 +85,13 @@ static void init(void) // Start odometrys odometryInit(0, 1e-3, - PROP_WHEEL_RADIUS, PROP_SHAFT_WIDTH, + PROP_WHEEL_RADIUS_LEFT, PROP_WHEEL_RADIUS_RIGHT, + PROP_SHAFT_WIDTH, ENCODER3, ENCODER4, 2.0*M_PI/2000.0/15, -2.0*M_PI/2000.0/15); odometryInit(1, 1e-3, - INDEP_WHEEL_RADIUS, INDEP_SHAFT_WIDTH, + INDEP_WHEEL_RADIUS, INDEP_WHEEL_RADIUS, + INDEP_SHAFT_WIDTH, ENCODER1, ENCODER2, 2.0*M_PI/1024.0, -2.0*M_PI/1024.0); diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/lib/differential_drive.c b/elec/boards/Controller_Motor_STM32/Firmwares/lib/differential_drive.c index ab84dce..f2b0444 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/lib/differential_drive.c +++ b/elec/boards/Controller_Motor_STM32/Firmwares/lib/differential_drive.c @@ -26,7 +26,7 @@ typedef struct { typedef struct { uint8_t initialized, enabled, running, working; uint8_t odometry_process; - float wheel_radius, shaft_width; + float left_wheel_radius, right_wheel_radius, shaft_width; float last_lin_acceleration, last_rot_acceleration; float u, v_max, at_max, ar_max; command_generator_t left_wheel_speed, right_wheel_speed; @@ -163,11 +163,13 @@ static void NORETURN traj_following_process(void) { } void dd_start(uint8_t odometry_process, - float wheel_radius, float shaft_width, float max_wheel_speed, + float left_wheel_radius, float right_wheel_radius, + float shaft_width, float max_wheel_speed, float v_max, float at_max, float ar_max, float k1, float k2, float k3, float Ts) { params.odometry_process = odometry_process; - params.wheel_radius = wheel_radius; + params.left_wheel_radius = left_wheel_radius; + params.right_wheel_radius = right_wheel_radius; params.shaft_width = shaft_width; params.last_lin_acceleration = 0.0; params.last_rot_acceleration = 0.0; @@ -199,14 +201,14 @@ void dd_start(uint8_t odometry_process, tc_get_speed_generator(DD_LINEAR_SPEED_TC), tc_get_position_generator(DD_ROTATIONAL_SPEED_TC), tc_get_speed_generator(DD_ROTATIONAL_SPEED_TC), - wheel_radius, shaft_width, max_wheel_speed, + left_wheel_radius, shaft_width, max_wheel_speed, -1); new_dd_generator(¶ms.right_wheel_speed, tc_get_position_generator(DD_LINEAR_SPEED_TC), tc_get_speed_generator(DD_LINEAR_SPEED_TC), tc_get_position_generator(DD_ROTATIONAL_SPEED_TC), tc_get_speed_generator(DD_ROTATIONAL_SPEED_TC), - wheel_radius, shaft_width, max_wheel_speed, + right_wheel_radius, shaft_width, max_wheel_speed, 1); new_ramp2_generator(¶ms.left_wheel, 0.0, ¶ms.left_wheel_speed); new_ramp2_generator(¶ms.right_wheel, 0.0, ¶ms.right_wheel_speed); diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/lib/differential_drive.h b/elec/boards/Controller_Motor_STM32/Firmwares/lib/differential_drive.h index 2c0a7e4..35d2388 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/lib/differential_drive.h +++ b/elec/boards/Controller_Motor_STM32/Firmwares/lib/differential_drive.h @@ -33,7 +33,8 @@ /* Initializes the differential drive * - odometry_process : ID of the odometry process to base the control on - * - wheel_radius : radius of the wheels (in meters) + * - left_wheel_radius : radius of the left wheel (in meters) + * - right_wheel_radius : radius of the right wheel (in meters) * - shaft_width : propulsion shaft width (in meters) * - max_wheel_speed : maximum wheel speed (in rad/s) * - v_max : maximum linear speed (in m/s) @@ -46,7 +47,8 @@ * DD_LINEAR_SPEED_TC and DD_ROTATIONAL_SPEED_TC */ void dd_start(uint8_t odometry_process, - float wheel_radius, float shaft_width, float max_wheel_speed, + float left_wheel_radius, float right_wheel_radius, + float shaft_width, float max_wheel_speed, float v_max, float at_max, float ar_max, float k1, float k2, float k3, float Ts); diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/lib/odometry.c b/elec/boards/Controller_Motor_STM32/Firmwares/lib/odometry.c index 33a597d..902a00d 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/lib/odometry.c +++ b/elec/boards/Controller_Motor_STM32/Firmwares/lib/odometry.c @@ -14,7 +14,8 @@ static cpu_stack_t stack_odometry[MAX_ODOMETRY_PROCESSES][(ODOMETRY_STACK_SIZE + typedef struct { robot_state_t robot_state; - float wheel_radius, shaft_width, left_encoder_gain, right_encoder_gain; + float left_wheel_radius, right_wheel_radius, shaft_width; + float left_encoder_gain, right_encoder_gain; uint8_t left_encoder, right_encoder; float Ts; uint8_t enable; @@ -26,7 +27,8 @@ odometry_state_t state[MAX_ODOMETRY_PROCESSES]; static void NORETURN odometry_process(void); void odometryInit(uint8_t process_num, float Ts, - float wheel_radius, float shaft_width, + float left_wheel_radius, float right_wheel_radius, + float shaft_width, uint8_t left_encoder, uint8_t right_encoder, float left_encoder_gain, float right_encoder_gain) { @@ -36,7 +38,8 @@ void odometryInit(uint8_t process_num, float Ts, state[process_num].robot_state.theta = 0; // Initialize robot parameters - state[process_num].wheel_radius = wheel_radius; + state[process_num].left_wheel_radius = left_wheel_radius; + state[process_num].right_wheel_radius = right_wheel_radius; state[process_num].shaft_width = shaft_width; state[process_num].left_encoder = left_encoder; state[process_num].right_encoder = right_encoder; @@ -108,10 +111,9 @@ static void NORETURN odometry_process(void) { last_pos_r = pos_r; // New state computation - state->robot_state.x += state->wheel_radius * (delta_r + delta_l) / 2.0 * cos(state->robot_state.theta); - state->robot_state.y += state->wheel_radius * (delta_r + delta_l) / 2.0 * sin(state->robot_state.theta); - state->robot_state.theta += state->wheel_radius / state->shaft_width * (delta_r - delta_l); - + state->robot_state.x += (state->right_wheel_radius * delta_r + state->left_wheel_radius * delta_l) / 2.0 * cos(state->robot_state.theta); + state->robot_state.y += (state->right_wheel_radius * delta_r + state->left_wheel_radius * delta_l) / 2.0 * sin(state->robot_state.theta); + state->robot_state.theta += (state->right_wheel_radius * delta_r - state->left_wheel_radius * delta_l) / state->shaft_width; // Normalization of theta if (state->robot_state.theta > M_PI) { state->robot_state.theta -= 2*M_PI; diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/lib/odometry.h b/elec/boards/Controller_Motor_STM32/Firmwares/lib/odometry.h index dcafed4..588bf8b 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/lib/odometry.h +++ b/elec/boards/Controller_Motor_STM32/Firmwares/lib/odometry.h @@ -23,7 +23,8 @@ typedef struct { } robot_state_t; void odometryInit(uint8_t process_num, float Ts, - float wheel_radius, float shaft_width, + float left_wheel_radius, float right_wheel_radius, + float shaft_width, uint8_t left_encoder, uint8_t right_encoder, float left_encoder_gain, float right_encoder_gain); void odo_disable(uint8_t process_num); hooks/post-receive -- krobot |
From: Xavier L. <Ba...@us...> - 2012-10-26 22:34:51
|
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 626a08aeb7e638f96d01ae519611fd42d3f4506b (commit) from cf9f9165a120527867e0bc0815a5a609f5a2e645 (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 626a08aeb7e638f96d01ae519611fd42d3f4506b Author: Xavier Lagorce <Xav...@cr...> Date: Sat Oct 27 00:34:20 2012 +0200 [Control2011/example] Missing requirements in krobot_rolling ----------------------------------------------------------------------- Changes: diff --git a/info/control2011/examples/krobot_rolling.ml b/info/control2011/examples/krobot_rolling.ml index c502593..4c85a66 100644 --- a/info/control2011/examples/krobot_rolling.ml +++ b/info/control2011/examples/krobot_rolling.ml @@ -1,4 +1,6 @@ -#use "topfind" +#use "topfind";; +#camlp4o;; +#require "lwt.syntax";; #require "krobot";; open Krobot_bus;; open Krobot_message;; hooks/post-receive -- krobot |
From: Pierre C. <Ba...@us...> - 2012-10-26 22:27:30
|
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 cf9f9165a120527867e0bc0815a5a609f5a2e645 (commit) via c315ed882e3d90289684f4bef4b76ff92244451b (commit) from 29443c43d4f4f00011fa3e0b3c8e07dbae034732 (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 cf9f9165a120527867e0bc0815a5a609f5a2e645 Author: Pierre Chambart <pie...@oc...> Date: Sat Oct 27 00:26:41 2012 +0200 Fix small bug in odometry reinitialisation commit c315ed882e3d90289684f4bef4b76ff92244451b Author: Pierre Chambart <pie...@oc...> Date: Sat Oct 27 00:25:10 2012 +0200 Adds a small example to run in the toplevel ----------------------------------------------------------------------- Changes: diff --git a/info/control2011/examples/krobot_rolling.ml b/info/control2011/examples/krobot_rolling.ml new file mode 100644 index 0000000..c502593 --- /dev/null +++ b/info/control2011/examples/krobot_rolling.ml @@ -0,0 +1,112 @@ +#use "topfind" +#require "krobot";; +open Krobot_bus;; +open Krobot_message;; + +let moving = ref false +let roting = ref false + +(* le hub et driver doivent être lancés *) +let bus = Lwt_unix.run (Krobot_bus.get ()) +let send m = Lwt_unix.run (Krobot_message.send bus (Unix.gettimeofday (), m)) + +let handle_message (timestamp, message) = + match message with + | CAN(_, frame) -> begin + match decode frame with + + | Motor_status(m,t,_,_) -> + moving := m; + roting := t + + | _ -> + () + end + | _ -> + () + +(* a n'executer qu'une fois *) +let () = Lwt_react.E.keep (Lwt_react.E.map handle_message (Krobot_bus.recv bus)) + +let move distance speed acceleration = + send (Motor_move(distance,speed,acceleration)) +(** [Motor_move(distance, speed, acceleration)] command to make + the robot to move. + - [distance] is in m + - [speed] is in m/s + - [acceleration] is in m/s^2 +*) +let turn angle speed acceleration = + send (Motor_turn(angle,speed,acceleration)) + (** [Motor_turn(angle, speed, acceleration)] command to make the + robot to turn. + - [angle] is in rad + - [speed] is in rad/s + - [acceleration] is in rad/s^2 + *) + +let motor_stop lin_acc rot_acc = send (Motor_stop(lin_acc, rot_acc)) + (** [Motor_stop(lin_acc, rot_acc)] command to stop following the + current Bezier Spline and the queued ones. + - [lin_acc] in m/s^2 + - [rot_acc] in rad/s^2 + *) + +let wait t = Lwt_unix.run (lwt () = Lwt_unix.sleep 0. in Lwt_unix.sleep t) +(* en secondes *) + +let wait_ref_false r = + while !r do + wait 0.01; + done + +let beacon_speed s = send (Motor_command (2,s)) + + +let pi = 4. *. atan 1. + +let fait_un_truc () = + wait 2.; + Printf.printf "go\n%!"; + move 0.5 0.2 0.5; + wait_ref_false moving; + turn pi (pi/.2.) (pi/.2.); + wait_ref_false roting; + move 0.2 0.2 0.5 + +let () = move 2. 0.2 0.5 +let () = turn (pi/.2.) (pi/.2. /. 4.) (pi/.2. /. 4. /. 1.) +let () = send (Set_odometry( 0.1, 0.2, pi)) + +let () = send (Drive_activation false) +let () = send (Drive_activation true) +let () = send (Drive_torque_limit 100) +let () = send (Drive_torque_limit 3600) +let () = send (Torque_limit(4,5)) +let () = send (Torque_limit(8,5)) + +let () = move 1. 0.2 0.5 + +let () = move (-.1.) 0.2 0.5 + +let () = turn (20.*.pi) pi 0.5 + +let () = turn (-. 20.*.pi) pi 0.5 + +let () = motor_stop 0.5 0.5 + +(*lancer: + let () = fait_un_truc () +*) + +(* commande de la vm / planner *) +open Krobot_geom + +let send_bus m = Lwt_unix.run (Krobot_bus.send bus (Unix.gettimeofday (), m)) +let stop () = send_bus Strategy_stop +let clear () = send_bus (Trajectory_set_vertices []) +(* nettoie la trajectoire enregistree *) +let set_vertice x y = send_bus (Trajectory_set_vertices [{x;y}]) +(* enregistre la trajectoire *) +let go () = send_bus Trajectory_go + diff --git a/info/control2011/src/tools/krobot_vm.ml b/info/control2011/src/tools/krobot_vm.ml index a2b7534..7df6b4c 100644 --- a/info/control2011/src/tools/krobot_vm.ml +++ b/info/control2011/src/tools/krobot_vm.ml @@ -603,7 +603,7 @@ let rec exec robot actions = | `Blue, _ | `Auto, `Blue -> let { Krobot_geom.x; y }, angle = Krobot_config.blue_initial_position in [Krobot_message.Set_odometry( x, y, pi); - Krobot_message.Set_odometry( x, y, pi )])) + Set_odometry_indep( x, y, pi )])) | Load face :: rest -> exec robot (Node (None,[ Lift_down face; hooks/post-receive -- krobot |
From: Xavier L. <Xav...@cr...> - 2012-10-26 20:47:51
|
On 26/10/2012 22:40, Pierre Chambart wrote: > [...] Le code de la coupe :D -- Xavier. |
From: Pierre C. <Ba...@us...> - 2012-10-26 20:40:37
|
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 29443c43d4f4f00011fa3e0b3c8e07dbae034732 (commit) via 035f9d52b1b2e95562b0af441e542e2fa91ff38c (commit) via d3646d8988b275d635808e856f27a8169fcbe5b1 (commit) via 645a18abb1e663350086d537520888245e5644c2 (commit) via e700577fe24962963fb1943e57d404269ab76fa9 (commit) via 78af501cf61256d87e4fa09b6a5205b8397082fb (commit) via 666e0dc488f66ed5318fd5e841be1a537ee45560 (commit) via 82f57164333960d5b04bbc124c86a6daf344355b (commit) via 46c0ef8dfeb43e00ed50d72edad767ee4cf54cab (commit) via 53bf72d4ef903e5d87c698b52be0f39860f89d06 (commit) via 3d59652b59b7621cb9f011073ce7e1f923b8410e (commit) via bdeff879b8ed42276763573967dc7ed28dd50ce9 (commit) via 96d08ed82366e7c0b2599bd7035675e0cec7ed4e (commit) via bf9296f621e8ab25375fe4bdfa8a23197ddb9cb4 (commit) via 7a344e7ce89be0492587d0cba6bc32509456ed4f (commit) via ae0e0bc5d8cce9c4fe7b38773f5d99ee45ed2e7d (commit) via d2e02e09948f8e2f38183d4aea5441fb42092115 (commit) via 864db7bdf520c38dcf04dfb809e53b7a474e4cea (commit) via 2147180a73cd3e00b5eb7e35a9b2decb614bb0ff (commit) via 88d667e7e67cd64256ef567631bf788a32a2db1a (commit) via 2ee981deaba2c5a24d2b9d64f52f7554440d5832 (commit) via cce7084f6572f1a73bc8f9c1e2815f063525041a (commit) via 4ee8b067e5a5f92c38c96a8f069a9f02dc088ee3 (commit) via 000b1c651d916fbe7fe4de92c47f9d535f294a0e (commit) via 05a4ea204296802b2d8235f2519ebc7020d9372c (commit) via 650368da1ad2db0410ddcc397c2c31a06ca33674 (commit) via 0ad19a68def0b2fabafeb0e5e15ee1e6177590bc (commit) via 3ae218d6a175f384974252c5dd2eaa928fa13f6c (commit) via 7b0cf7382c5779a9a3048bbc185785181a8aa151 (commit) via 4bbe513d86ee6fd90bd17203354ad4f773955a44 (commit) via b302c56062cbf220bba5ed93b8289976ada3926e (commit) via 658408babb5310adde2136f174db84e380b51772 (commit) via dc78cd457b1b62d932798cd8274bf57f770daea2 (commit) via 0b246ee805ed4f163fb9579213451fce33aa51f4 (commit) via ed691e2747ff70813a0282e24ae45bc528a4e6de (commit) via 1f2f8c16bfb4dae9311823a60b86495466c59bab (commit) via 97bb881fbf21d84c503a1614299dd9a0a86b7e26 (commit) via c3258de737a58cc28457ba3dfdff35d6d269a203 (commit) via a66b5b7a6574372066c3bda8ae352262192cd19c (commit) via 6a43241bc8a4cfb99751ff0200319d03b0acfaf6 (commit) via 4efddb34ffcc7c46f83c34fde0ba3d02b7f3c6cd (commit) via f021f7d3fc24b091b5707b5ebf6c8268ee2f41d7 (commit) via 6c07178363e06313500119b9f5544e1c88567baa (commit) via 928d72ced8991fb8738d19e159eec18edf867fdd (commit) via a00e289b2347abcce9a6513603322e341ae9e785 (commit) via 0a079cd8bf2574072c85ff858e5974a202cd38b3 (commit) via af11ff63690880602b4351c6a630d1f0d3260433 (commit) via 2aea2c681aeb19aca037ee85a6f97a1b30070d64 (commit) via e99b9813d3aed62947cb5a371b6e8c96527e9368 (commit) via 89f78177ab4494c17be6d21c8c8ed4d6ce365ada (commit) via 69133de534b5a299380fd905600970fd3c82a365 (commit) via c1c21ceb36150b0970fdc2323679fcfe8dbc494e (commit) via 41ef32f16fb0f5bd7afe33b46dc9620b1fe48de9 (commit) from 39d27a4038f8f91b6469513e63ba3ccb4da8d3e8 (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 29443c43d4f4f00011fa3e0b3c8e07dbae034732 Author: chicco <cha...@cr...> Date: Sat May 19 23:26:21 2012 +0200 [calibration] add a calibration action to the vm commit 035f9d52b1b2e95562b0af441e542e2fa91ff38c Author: Jérémie Dimino <je...@di...> Date: Sat May 19 12:06:37 2012 +0200 Add krobot_collision commit d3646d8988b275d635808e856f27a8169fcbe5b1 Author: Jérémie Dimino <je...@di...> Date: Sat May 19 11:57:49 2012 +0200 add robot.motors_moving in krobot-vm commit 645a18abb1e663350086d537520888245e5644c2 Author: Jérémie Dimino <je...@di...> Date: Sat May 19 05:20:29 2012 +0200 Try to do random stuff commit e700577fe24962963fb1943e57d404269ab76fa9 Author: Jérémie Dimino <je...@di...> Date: Fri May 18 20:53:10 2012 +0200 Display collisions commit 78af501cf61256d87e4fa09b6a5205b8397082fb Author: Jérémie Dimino <je...@di...> Date: Fri May 18 19:24:38 2012 +0200 Better collision detection commit 666e0dc488f66ed5318fd5e841be1a537ee45560 Author: chicco <cha...@cr...> Date: Fri May 18 23:40:10 2012 +0200 [krobot_pet] that all folks commit 82f57164333960d5b04bbc124c86a6daf344355b Author: Jérémie Dimino <je...@di...> Date: Fri May 18 22:39:08 2012 +0200 Send logs in background in joystick control commit 46c0ef8dfeb43e00ed50d72edad767ee4cf54cab Author: [Kro]bot <kr...@wa...> Date: Fri May 18 22:31:06 2012 +0200 Enable motors in joystick control commit 53bf72d4ef903e5d87c698b52be0f39860f89d06 Author: Jérémie Dimino <je...@di...> Date: Fri May 18 21:52:43 2012 +0200 Add joystick control commit 3d59652b59b7621cb9f011073ce7e1f923b8410e Author: chicco <cha...@cr...> Date: Fri May 18 18:02:26 2012 +0200 [homo] push bottle commit bdeff879b8ed42276763573967dc7ed28dd50ce9 Author: chicco <cha...@cr...> Date: Fri May 18 17:48:18 2012 +0200 plop commit 96d08ed82366e7c0b2599bd7035675e0cec7ed4e Author: chicco <cha...@cr...> Date: Fri May 18 13:43:40 2012 +0200 go commit bf9296f621e8ab25375fe4bdfa8a23197ddb9cb4 Author: Jérémie Dimino <je...@di...> Date: Fri May 18 13:09:30 2012 +0200 Fix logging in daemons commit 7a344e7ce89be0492587d0cba6bc32509456ed4f Author: chicco <cha...@cr...> Date: Fri May 18 12:36:10 2012 +0200 [pathfinding] correct bezier curve correction commit ae0e0bc5d8cce9c4fe7b38773f5d99ee45ed2e7d Author: Jérémie Dimino <je...@di...> Date: Fri May 18 12:14:10 2012 +0200 Optimize krobot-record Send all messages to log to the writer thread in one batch commit d2e02e09948f8e2f38183d4aea5441fb42092115 Author: Jérémie Dimino <je...@di...> Date: Fri May 18 11:57:54 2012 +0200 Add a flag for opencv commit 864db7bdf520c38dcf04dfb809e53b7a474e4cea Author: Jérémie Dimino <je...@di...> Date: Fri May 18 11:53:50 2012 +0200 Remove generated stuff from the repository commit 2147180a73cd3e00b5eb7e35a9b2decb614bb0ff Author: Jérémie Dimino <je...@di...> Date: Fri May 18 11:34:36 2012 +0200 Modify the message logging system * krobot-record records everything to stdout (so it can be piped to gzip) * krobot-replay filter-out non-can messages and Info can frames * add krobot-read to pretty-print the contents of record files commit 88d667e7e67cd64256ef567631bf788a32a2db1a Author: chicco <cha...@cr...> Date: Fri May 18 11:00:09 2012 +0200 [vm] correct typo commit 2ee981deaba2c5a24d2b9d64f52f7554440d5832 Author: chicco <cha...@cr...> Date: Fri May 18 10:36:07 2012 +0200 [info] modify bezier coefs such that it avoid colliding commit cce7084f6572f1a73bc8f9c1e2815f063525041a Author: chicco <cha...@cr...> Date: Fri May 18 02:47:59 2012 +0200 [info] add coins positions commit 4ee8b067e5a5f92c38c96a8f069a9f02dc088ee3 Author: chicco <cha...@cr...> Date: Fri May 18 01:48:21 2012 +0200 [krobot_vm] restart after some time when no trajectory is found commit 000b1c651d916fbe7fe4de92c47f9d535f294a0e Author: chicco <cha...@cr...> Date: Fri May 18 01:40:29 2012 +0200 [info] fix pathfinder commit 05a4ea204296802b2d8235f2519ebc7020d9372c Author: chicco <cha...@cr...> Date: Thu May 17 21:21:27 2012 +0200 [control] fix things with ennemy avoiding commit 650368da1ad2db0410ddcc397c2c31a06ca33674 Author: chicco <cha...@cr...> Date: Thu May 17 17:39:03 2012 +0200 [control] add krobot_stop_beacon to stop the annoying sound... commit 0ad19a68def0b2fabafeb0e5e15ee1e6177590bc Author: Xavier Lagorce <Xav...@cr...> Date: Fri May 18 02:09:22 2012 +0200 [control2011] Added CAN packets descriptions for new features commit 3ae218d6a175f384974252c5dd2eaa928fa13f6c Author: Xavier Lagorce <Xav...@cr...> Date: Fri May 18 02:08:35 2012 +0200 [Controller_Motor_STM32] New commands and forgotten mail commit 7b0cf7382c5779a9a3048bbc185785181a8aa151 Author: Xavier Lagorce <Xav...@cr...> Date: Fri May 18 00:31:03 2012 +0200 [Controller_Motor_STM32] Suspend motor controllers when the fault button is pressed. commit 4bbe513d86ee6fd90bd17203354ad4f773955a44 Author: Xavier Lagorce <Xav...@cr...> Date: Fri May 18 00:29:39 2012 +0200 [Controller_Motor_STM32] Added functions to suspend and re-enable a controller, taking into account the possible movement of the motor between the two operations commit b302c56062cbf220bba5ed93b8289976ada3926e Author: Olivier BICHLER <oli...@gm...> Date: Thu May 17 21:52:42 2012 +0200 [Sensor_Actuator] Multiple beacons handling commit 658408babb5310adde2136f174db84e380b51772 Author: Olivier BICHLER <oli...@gm...> Date: Thu May 17 19:11:45 2012 +0200 [Sensor_Actuator] Comment blinky leds commit dc78cd457b1b62d932798cd8274bf57f770daea2 Author: Olivier BICHLER <oli...@gm...> Date: Thu May 17 18:07:43 2012 +0200 [Sensor_Actuator] Bug correction on smooth commit 0b246ee805ed4f163fb9579213451fce33aa51f4 Author: Jérémie Dimino <je...@di...> Date: Thu May 17 16:18:16 2012 +0200 Allow to put fake beacons commit ed691e2747ff70813a0282e24ae45bc528a4e6de Author: chicco <cha...@cr...> Date: Thu May 17 15:02:20 2012 +0200 [homologation] homologation startegy restart when changing team commit 1f2f8c16bfb4dae9311823a60b86495466c59bab Author: chicco <cha...@cr...> Date: Thu May 17 11:39:24 2012 +0200 [control] last minute fix for homologation commit 97bb881fbf21d84c503a1614299dd9a0a86b7e26 Author: chicco <cha...@cr...> Date: Thu May 17 09:59:58 2012 +0200 [homologation] wait after pluging the jack commit c3258de737a58cc28457ba3dfdff35d6d269a203 Author: chicco <cha...@cr...> Date: Thu May 17 09:33:31 2012 +0200 [control] code from the whooole long night commit a66b5b7a6574372066c3bda8ae352262192cd19c Author: Xavier Lagorce <Xav...@cr...> Date: Thu May 17 10:21:09 2012 +0200 [control2011] Take into account the double beacon detection commit 6a43241bc8a4cfb99751ff0200319d03b0acfaf6 Author: Xavier Lagorce <Xav...@cr...> Date: Thu May 17 10:16:23 2012 +0200 [Controller_Motor_STM32] Correct independant encoder parameters commit 4efddb34ffcc7c46f83c34fde0ba3d02b7f3c6cd Author: Xavier Lagorce <Xav...@cr...> Date: Thu May 17 10:15:49 2012 +0200 [Controller_Motor_STM32] Corrected Makefile commit f021f7d3fc24b091b5707b5ebf6c8268ee2f41d7 Author: Xavier Lagorce <Xav...@cr...> Date: Wed May 16 22:56:46 2012 +0200 [Controller_Motor_STM32] Always respond to a Bezier command with a CAN packet commit 6c07178363e06313500119b9f5544e1c88567baa Author: Olivier BICHLER <oli...@gm...> Date: Thu May 17 09:30:15 2012 +0200 [Sensor_Actuator] Changed CAN message to send two beacon positions commit 928d72ced8991fb8738d19e159eec18edf867fdd Author: Olivier BICHLER <oli...@gm...> Date: Thu May 17 00:13:12 2012 +0200 [Sensor_Actuator] Correction of bugs in some limit cases commit a00e289b2347abcce9a6513603322e341ae9e785 Author: Olivier BICHLER <oli...@gm...> Date: Thu May 17 00:20:08 2012 +0200 [Sensor_Actuator] Nouvelle calibration OK commit 0a079cd8bf2574072c85ff858e5974a202cd38b3 Author: chicco <cha...@cr...> Date: Wed May 16 21:03:17 2012 +0200 [viewer] draw the robot using independent encoder informations commit af11ff63690880602b4351c6a630d1f0d3260433 Author: chicco <cha...@cr...> Date: Wed May 16 20:51:13 2012 +0200 [viewer/vm] handler Odometry_indep/Set_odometry_indep commit 2aea2c681aeb19aca037ee85a6f97a1b30070d64 Author: Xavier Lagorce <Xav...@cr...> Date: Wed May 16 20:09:36 2012 +0200 [Controller_Motor_STM32] Allow user choice of encoders for odometry commit e99b9813d3aed62947cb5a371b6e8c96527e9368 Author: Xavier Lagorce <Xav...@cr...> Date: Wed May 16 19:11:27 2012 +0200 [Krobot_message] Added CAN messages for independant odometry commit 89f78177ab4494c17be6d21c8c8ed4d6ce365ada Author: Xavier Lagorce <Xav...@cr...> Date: Wed May 16 19:01:29 2012 +0200 [Controller_Motor_STM32] Added messages to set independant odometry commit 69133de534b5a299380fd905600970fd3c82a365 Author: Xavier Lagorce <Xav...@cr...> Date: Wed May 16 18:23:56 2012 +0200 [Controller_Motor_STM32] Verify bezier spline validity commit c1c21ceb36150b0970fdc2323679fcfe8dbc494e Author: Xavier Lagorce <Xav...@cr...> Date: Wed May 16 18:22:20 2012 +0200 [Controller_Motor_STM32] Compute and broadcast second odometry commit 41ef32f16fb0f5bd7afe33b46dc9620b1fe48de9 Author: Olivier BICHLER <oli...@gm...> Date: Wed May 16 20:09:27 2012 +0200 [Sensor_Actuator] Updated beacon system to use an index switch and handle multiple beacons ----------------------------------------------------------------------- Changes: diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/can_messages.h b/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/can_messages.h index 94ebea0..156bf47 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/can_messages.h +++ b/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/can_messages.h @@ -24,6 +24,7 @@ #define CAN_MSG_ODOMETRY 104 // odometry_can_msg_t #define CAN_MSG_GHOST 105 // ghost_can_msg_t #define CAN_MSG_CONTROL_ERROR 106 // error_can_msg_t +#define CAN_MSG_ODOMETRY_INDEP 107 // odometry_can_msg_t // Received commands #define CAN_MSG_MOVE 201 // move_can_msg_t @@ -34,6 +35,11 @@ #define CAN_MSG_BEZIER_ADD 206 // bezier_can_msg_t #define CAN_MSG_BEZIER_LIMITS 207 // bezier_limits_can_msg_t #define CAN_MSG_MOTOR_COMMAND 208 // motor_command_can_msg_t +#define CAN_MSG_ODOMETRY_INDEP_SET 209 // odometry_can_msg_t +#define CAN_MSG_CONTROLLER_ACTIVATION 210 // controller_activation_can_msg_t +#define CAN_MSG_DRIVE_ACTIVATION 211 // controller_activation_can_msg_t +#define CAN_MSG_TORQUE_LIMIT 212 // torque_limit_can_msg_t +#define CAN_MSG_DRIVE_TORQUE_LIMIT 213 // drive_torque_limit_can_msg_t /* +-----------------------------------------------------------------+ | CAN messages data structures | @@ -81,6 +87,17 @@ typedef struct { uint8_t state; // 1 if trajectory in progress, 0 else } ghost_msg_t; +// Torque limitation on some motors +typedef struct { + uint8_t motor __attribute__((__packed__)); // Logic OR of bits corresponding to motors + uint16_t limit __attribute__((__packed__)); // Torque limit (between 0 and 3600) +} torque_limit_msg_t; + +// Torque limitation on propulsion drive +typedef struct { + uint16_t limit __attribute__((__packed__)); // Torque limit (between 0 and 3600) +} drive_torque_limit_msg_t; + // Move command typedef struct { int32_t distance __attribute__((__packed__)); // Distance in mm (fixed point representation...) @@ -95,6 +112,19 @@ typedef struct { uint16_t acceleration __attribute__((__packed__)); // Acceleration in 1/1000 radians/s^2 } turn_msg_t; +// Controller activation command +typedef struct { + uint8_t motor __attribute__((__packed__)); // Motor ID of the motor to act on + uint8_t activate __attribute__((__packed__)); // Activate the controller if non zero + // else release the control. +} controller_activation_msg_t; + +// Propulsion Drive activation command +typedef struct { + uint8_t activate __attribute__((__packed__)); // Activate the propulsion drive if non zero + // else release the control. +} drive_activation_msg_t; + // Add a new Bezier Spline to the wait queue typedef struct { uint16_t x_end:12 __attribute__((__packed__)); // end point x coordinate in mm @@ -125,8 +155,8 @@ typedef struct { // Command the speed of a particular motor typedef struct { - uint8_t motor_id; - int32_t speed; + uint8_t motor_id __attribute__((__packed__)); + int32_t speed __attribute__((__packed__)); } motor_command_msg_t; /* +-----------------------------------------------------------------+ @@ -164,6 +194,16 @@ typedef union { } ghost_can_msg_t; typedef union { + torque_limit_msg_t data; + uint32_t data32[2]; +} torque_limit_can_msg_t; + +typedef union { + drive_torque_limit_msg_t data; + uint32_t data32[2]; +} drive_torque_limit_can_msg_t; + +typedef union { move_msg_t data; uint32_t data32[2]; } move_can_msg_t; @@ -174,6 +214,16 @@ typedef union { } turn_can_msg_t; typedef union { + controller_activation_msg_t data; + uint32_t data32[2]; +} controller_activation_can_msg_t; + +typedef union { + drive_activation_msg_t data; + uint32_t data32[2]; +} drive_activation_can_msg_t; + +typedef union { bezier_msg_t data; uint32_t data32[2]; } bezier_can_msg_t; diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/can_messages_sensors.h b/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/can_messages_sensors.h new file mode 100644 index 0000000..48c3b90 --- /dev/null +++ b/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/can_messages_sensors.h @@ -0,0 +1,223 @@ +/** + * Sensor-Actuator board messages + * + * Header file for the Sensor and Actuator CAN messages + * + * Copyright © 2011 Nicolas Dandrimont <ol...@cr...> + * Authors: Nicolas Dandrimont <ol...@cr...> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#ifndef CAN_MESSAGES_H__ +#define CAN_MESSAGES_H__ + +/** + * Message IDs + */ + +// Beacon + +#define CAN_BEACON_POSITION 301 // beacon_position +#define CAN_BEACON_LOWLEVEL_POSITION 302 // beacon_lowlevel_position +#define CAN_BEACON_CALIBRATION 303 // beacon_calibration + +// Switches + +#define CAN_SWITCH_STATUS_1 311 // switch_status +#define CAN_SWITCH_STATUS_2 312 // switch_status +#define CAN_SWITCH_SET 313 // switch_request + + +// ADC + +#define CAN_ADC_VALUES_1 321 // adc_values +#define CAN_ADC_VALUES_2 322 // adc_values + +// Battery monitoring + +#define CAN_BATTERY_STATUS_1 331 // battery_status +#define CAN_BATTERY_STATUS_2 332 // battery_status + +// AX12 + +#define CAN_AX12_STATE 341 // ax12_state +#define CAN_AX12_REQUEST_STATE 342 // ax12_request_state +#define CAN_AX12_GOTO 343 // ax12_goto +//#define CAN_AX12_RESET 344 // Not used anymore +#define CAN_AX12_SET_TORQUE_ENABLE 345 // ax12_set_torque_enable + +/****************************************************************************/ + +/** + * Message Packets + */ + +/** + * Beacon messages + */ + +// Position of the opponent +struct beacon_position_pkt { + uint16_t angle[2]; // in 1/10000th of radians [0; 2*Pi[ + uint16_t distance[2]; // in mm [0; 65536[ +} __attribute__((packed)); + + + +// Beacon low-level position +struct beacon_lowlevel_position_pkt { + uint16_t angle; // in 1/10000th of radians [0; 2*Pi[ + uint16_t width; // in 1/100000th of radians [0; Pi/5[ + uint32_t period; // in timer ticks +} __attribute__((packed)); + + + +// Beacon calibration +struct beacon_calibration_pkt { + uint16_t width; // in 1/100000th of radians [0; Pi/5[ + uint16_t distance; // in mm [0; 65536[ +} __attribute__((packed)); + + +/** + * Switch messages + */ + +// Switch status +struct switch_status_pkt { + uint8_t sw1; + uint8_t sw2; + uint8_t sw3; + uint8_t sw4; + uint8_t sw5; + uint8_t sw6; + uint8_t sw7; + uint8_t sw8; +}; + +// Switch request +struct switch_request_pkt { + uint8_t num; + uint8_t state; +}; + +/** + * ADC messages + */ +// ADC Values +struct adc_values_pkt { + uint16_t val1; + uint16_t val2; + uint16_t val3; + uint16_t val4; +} __attribute__((packed)); + +/** + * Battery monitoring + */ +struct battery_status_pkt { + uint16_t elem[4]; // in 1/10000th volts [0; 6.5536[ +} __attribute__((packed)); + + +/** + * AX-12 + */ +struct ax12_state_pkt { + uint8_t address; + uint16_t position; + uint16_t speed; + uint16_t torque; +} __attribute__((packed)); + +struct ax12_request_state_pkt { + uint8_t address; +} __attribute__((packed)); + +struct ax12_goto_pkt { + uint8_t address; + uint16_t position; + uint16_t speed; +} __attribute__((packed)); + +struct ax12_set_torque_enable_pkt { + uint8_t address; + uint8_t enable; +}; + +/****************************************************************************/ + +/** + * Typedefs + */ + +typedef union { + struct beacon_position_pkt p; + uint32_t d[2]; +} beacon_position; + +typedef union { + struct beacon_lowlevel_position_pkt p; + uint32_t d[2]; +} beacon_lowlevel_position; + +typedef union { + struct beacon_calibration_pkt p; + uint32_t d[2]; +} beacon_calibration; + +typedef union { + struct switch_status_pkt p; + uint32_t d[2]; +} switch_status; + +typedef union { + struct switch_request_pkt p; + uint32_t d[2]; +} switch_request; + +typedef union { + struct adc_values_pkt p; + uint32_t d[2]; +} adc_values; + +typedef union { + struct battery_status_pkt p; + uint32_t d[2]; +} battery_status; + +typedef union { + struct ax12_state_pkt p; + uint32_t d[2]; +} ax12_state; + +typedef union { + struct ax12_request_state_pkt p; + uint32_t d[2]; +} ax12_request_state; + +typedef union { + struct ax12_goto_pkt p; + uint32_t d[2]; +} ax12_goto; + +typedef union { + struct ax12_set_torque_enable_pkt p; + uint32_t d[2]; +} ax12_set_torque_enable; + +#endif diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/can_monitor.c b/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/can_monitor.c index 5ed50a6..3d83b64 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/can_monitor.c +++ b/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/can_monitor.c @@ -12,6 +12,7 @@ #define ROBOT_MODE_NORMAL 0 #define ROBOT_MODE_HIL 1 +#define ROBOT_MODE_FAULT 2 #define CONTROL_ODOMETRY 0 @@ -19,7 +20,7 @@ PROC_DEFINE_STACK(stack_can_send, KERN_MINSTACKSIZE * 8); PROC_DEFINE_STACK(stack_can_receive, KERN_MINSTACKSIZE * 8); // globals -volatile uint8_t mode; +volatile uint8_t mode, old_mode; volatile uint8_t err1, err2, send_err; // Process for communication @@ -40,6 +41,7 @@ void canMonitorInit(void) { can_start(CAND1, &cfg); mode = ROBOT_MODE_NORMAL; + old_mode = ROBOT_MODE_NORMAL; // Start communication process proc_new(canMonitor_process, NULL, sizeof(stack_can_send), stack_can_send); @@ -88,8 +90,9 @@ static void NORETURN canMonitor_process(void) { can_transmit(CAND1, &txm, ms_to_ticks(10));*/ // Sending odometry data if not in HIL mode or motor commands if in HIL mode - if (mode != ROBOT_MODE_HIL) { - odo_getState(CONTROL_ODOMETRY, &odometry); + if (mode != ROBOT_MODE_HIL || + (mode == ROBOT_MODE_FAULT && old_mode == ROBOT_MODE_HIL)) { + odo_getState(0, &odometry); msg_odo.data.x = (int16_t)(odometry.x * 1000.0); msg_odo.data.y = (int16_t)(odometry.y * 1000.0); odometry.theta = fmodf(odometry.theta, 2*M_PI); @@ -103,6 +106,21 @@ static void NORETURN canMonitor_process(void) { txm.data32[1] = msg_odo.data32[1]; txm.eid = CAN_MSG_ODOMETRY; can_transmit(CAND1, &txm, ms_to_ticks(10)); + + odo_getState(1, &odometry); + msg_odo.data.x = (int16_t)(odometry.x * 1000.0); + msg_odo.data.y = (int16_t)(odometry.y * 1000.0); + odometry.theta = fmodf(odometry.theta, 2*M_PI); + if (odometry.theta > M_PI) + odometry.theta -= 2*M_PI; + if (odometry.theta < -M_PI) + odometry.theta += 2*M_PI; + msg_odo.data.theta = (int16_t)(odometry.theta * 10000.0); + + txm.data32[0] = msg_odo.data32[0]; + txm.data32[1] = msg_odo.data32[1]; + txm.eid = CAN_MSG_ODOMETRY_INDEP; + can_transmit(CAND1, &txm, ms_to_ticks(10)); } else { // Sending MOTOR3 data msg_mot.data.position = mc_getPosition(MOTOR3); @@ -166,6 +184,7 @@ static void NORETURN canMonitorListen_process(void) { bool received = false; can_tx_frame txm; robot_state_t odometry; + uint8_t res; move_can_msg_t move_msg; turn_can_msg_t turn_msg; @@ -175,6 +194,11 @@ static void NORETURN canMonitorListen_process(void) { bezier_can_msg_t bezier_msg; bezier_limits_can_msg_t bezier_limits_msg; motor_command_can_msg_t motor_command_msg; + switch_status switches; + torque_limit_can_msg_t torque_limit_msg; + drive_torque_limit_can_msg_t drive_torque_limit_msg; + controller_activation_can_msg_t cont_act_msg; + drive_activation_can_msg_t drive_activation_msg; // Initialize constant parameters of TX frame txm.dlc = 8; @@ -194,6 +218,16 @@ static void NORETURN canMonitorListen_process(void) { } else { // Handle commands and other informations switch (frame.eid) { + case CAN_MSG_TORQUE_LIMIT: + torque_limit_msg.data32[0] = frame.data32[0]; + torque_limit_msg.data32[1] = frame.data32[0]; + motorSetMaxPWM(torque_limit_msg.data.motor, torque_limit_msg.data.limit); + break; + case CAN_MSG_DRIVE_TORQUE_LIMIT: + drive_torque_limit_msg.data32[0] = frame.data32[0]; + drive_torque_limit_msg.data32[1] = frame.data32[1]; + motorSetMaxPWM(MOTOR3|MOTOR4, torque_limit_msg.data.limit);; + break; case CAN_MSG_MOVE: move_msg.data32[0] = frame.data32[0]; move_msg.data32[1] = frame.data32[1]; @@ -206,12 +240,36 @@ static void NORETURN canMonitorListen_process(void) { if (!tc_is_working(TC_MASK(DD_LINEAR_SPEED_TC) | TC_MASK(DD_ROTATIONAL_SPEED_TC))) dd_turn(turn_msg.data.angle / 10000.0, turn_msg.data.speed / 1000.0, turn_msg.data.acceleration / 1000.0); break; + case CAN_MSG_CONTROLLER_ACTIVATION: + cont_act_msg.data32[0] = frame.data32[0]; + cont_act_msg.data32[1] = frame.data32[1]; + if (!cont_act_msg.data.activate) + mc_suspend_controller(1 << (cont_act_msg.data.motor-1)); + else + mc_reactivate_controller(1 << (cont_act_msg.data.motor-1)); + break; + case CAN_MSG_DRIVE_ACTIVATION: + drive_activation_msg.data32[0] = frame.data32[0]; + drive_activation_msg.data32[1] = frame.data32[1]; + if (!drive_activation_msg.data.activate) { + mc_suspend_controller(MOTOR3); + mc_suspend_controller(MOTOR4); + dd_interrupt_trajectory(0., 0.); + } else { + mc_reactivate_controller(MOTOR3); + mc_reactivate_controller(MOTOR4); + } + break; case CAN_MSG_BEZIER_ADD: bezier_msg.data32[0] = frame.data32[0]; bezier_msg.data32[1] = frame.data32[1]; - dd_add_bezier(bezier_msg.data.x_end/1000.0, bezier_msg.data.y_end/1000.0, - bezier_msg.data.d1/100.0, bezier_msg.data.d2/100.0, - bezier_msg.data.theta_end/100.0, bezier_msg.data.v_end/1000.0); + res = dd_add_bezier(bezier_msg.data.x_end/1000.0, + bezier_msg.data.y_end/1000.0, + bezier_msg.data.d1/100.0, + bezier_msg.data.d2/100.0, + bezier_msg.data.theta_end/100.0, + bezier_msg.data.v_end/1000.0); + can_send_error(res,0); break; case CAN_MSG_BEZIER_LIMITS: bezier_limits_msg.data32[0] = frame.data32[0]; @@ -231,7 +289,15 @@ static void NORETURN canMonitorListen_process(void) { odometry.x = ((float)odometry_msg.data.x) / 1000.0; odometry.y = ((float)odometry_msg.data.y) / 1000.0; odometry.theta = ((float)odometry_msg.data.theta) / 10000.0; - odo_setState(CONTROL_ODOMETRY, &odometry); + odo_setState(0, &odometry); + break; + case CAN_MSG_ODOMETRY_INDEP_SET: + odometry_msg.data32[0] = frame.data32[0]; + odometry_msg.data32[1] = frame.data32[1]; + odometry.x = ((float)odometry_msg.data.x) / 1000.0; + odometry.y = ((float)odometry_msg.data.y) / 1000.0; + odometry.theta = ((float)odometry_msg.data.theta) / 10000.0; + odo_setState(1, &odometry); break; case CAN_MSG_ODOMETRY: // We should only receive such message in HIL mode @@ -265,6 +331,20 @@ static void NORETURN canMonitorListen_process(void) { motorSetSpeed(motor_command_msg.data.motor_id, motor_command_msg.data.speed); break; + case CAN_SWITCH_STATUS_1: + switches.d[0] = frame.data32[0]; + switches.d[1] = frame.data32[1]; + if (mode != ROBOT_MODE_FAULT && !switches.p.sw3) { + dd_interrupt_trajectory(0., 0.); + old_mode = mode; + mode = ROBOT_MODE_FAULT; + mc_suspend_controller(MOTOR3); + mc_suspend_controller(MOTOR4); + } else if (mode == ROBOT_MODE_FAULT && switches.p.sw3) { + mode = old_mode; + mc_reactivate_controller(MOTOR3); + mc_reactivate_controller(MOTOR4); + } } } } diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/can_monitor.h b/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/can_monitor.h index c157f58..c829c10 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/can_monitor.h +++ b/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/can_monitor.h @@ -19,6 +19,7 @@ #include "odometry.h" #include "differential_drive.h" #include "can_messages.h" +#include "can_messages_sensors.h" void canMonitorInit(void); void can_send_error(uint8_t err1, uint8_t err2); diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/controller_motor_stm32.mk b/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/controller_motor_stm32.mk index ac9aa9a..37d3ed0 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/controller_motor_stm32.mk +++ b/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/controller_motor_stm32.mk @@ -9,7 +9,7 @@ Firmware_DEBUG = 1 # Our target application TRG += controller_motor_stm32 -controller_motor_stm32_PREFIX = "/media/data/krobot/arm-i386/bin/arm-none-eabi-" +controller_motor_stm32_PREFIX = "$$HOME/opt/arm/bin/arm-none-eabi-" controller_motor_stm32_SUFFIX = "" diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/main.c b/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/main.c index 48846a3..e4b87bf 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/main.c +++ b/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/main.c @@ -17,8 +17,11 @@ #include "command_generator.h" #include "differential_drive.h" -#define WHEEL_RADIUS 0.049245 -#define SHAFT_WIDTH 0.224 +#define PROP_WHEEL_RADIUS 0.049245 +#define PROP_SHAFT_WIDTH 0.22264 + +#define INDEP_WHEEL_RADIUS 0.0359 +#define INDEP_SHAFT_WIDTH 0.266 #define CONTROL_ODOMETRY 0 @@ -50,7 +53,7 @@ static void init(void) // Start control of drive motors tc_init(); dd_start(CONTROL_ODOMETRY, // Use odometry CONTROL_ODOMETRY for control - WHEEL_RADIUS, SHAFT_WIDTH, // Structural parameters + PROP_WHEEL_RADIUS, PROP_SHAFT_WIDTH, // Structural parameters 8*2*M_PI, // Absolute wheel speed limitation 0.5, // Linear velocity limitation 1.0, // Linear acceleration limitation @@ -77,8 +80,15 @@ static void init(void) params.encoder_gain = -2.0*M_PI/2000.0/15; // Left motor is reversed mc_new_controller(¶ms, dd_get_right_wheel_generator(), CONTROLLER_MODE_NORMAL); - // Start odometry - odometryInit(CONTROL_ODOMETRY, 1e-3, WHEEL_RADIUS, SHAFT_WIDTH, 2.0*M_PI/2000.0/15, -2.0*M_PI/2000.0/15); + // Start odometrys + odometryInit(0, 1e-3, + PROP_WHEEL_RADIUS, PROP_SHAFT_WIDTH, + ENCODER3, ENCODER4, + 2.0*M_PI/2000.0/15, -2.0*M_PI/2000.0/15); + odometryInit(1, 1e-3, + INDEP_WHEEL_RADIUS, INDEP_SHAFT_WIDTH, + ENCODER1, ENCODER2, + 2.0*M_PI/1024.0, -2.0*M_PI/1024.0); // Init beacon motor enableMotor(MOTOR2); @@ -96,6 +106,7 @@ static void init(void) LED4_OFF(); timer_delay(100); } + } static void NORETURN ind_process(void) diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/lib/differential_drive.c b/elec/boards/Controller_Motor_STM32/Firmwares/lib/differential_drive.c index 487ae75..ab84dce 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/lib/differential_drive.c +++ b/elec/boards/Controller_Motor_STM32/Firmwares/lib/differential_drive.c @@ -304,6 +304,10 @@ uint8_t dd_add_bezier(float x_end, float y_end, float d1, float d2, float end_an if (params.trajs[t_ind].initialized == 1) { return DD_TRAJECTORY_ALREADY_USED; } else { + // Test the validity of the spline + if (fabsf(d1) < 0.01 || fabsf(d2) < 0.01) { + return DD_BAD_TRAJECTORY; + } traj = ¶ms.trajs[t_ind]; // New trajectory is not enabled traj->enabled = 0; diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/lib/differential_drive.h b/elec/boards/Controller_Motor_STM32/Firmwares/lib/differential_drive.h index df33321..2c0a7e4 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/lib/differential_drive.h +++ b/elec/boards/Controller_Motor_STM32/Firmwares/lib/differential_drive.h @@ -26,6 +26,7 @@ #define DD_NO_ERROR 0 #define DD_TRAJECTORY_ALREADY_USED 1 +#define DD_BAD_TRAJECTORY 2 #define DD_GHOST_STOPPED 0 #define DD_GHOST_MOVING 1 diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/lib/motor_controller.c b/elec/boards/Controller_Motor_STM32/Firmwares/lib/motor_controller.c index 2c2ae81..c106343 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/lib/motor_controller.c +++ b/elec/boards/Controller_Motor_STM32/Firmwares/lib/motor_controller.c @@ -21,6 +21,7 @@ typedef struct { uint8_t enable; // Is this controller enabled ? uint8_t running; // Is this controller running ? + uint8_t suspended; // Is this controller suspended ? uint8_t mode; // Is this a real controller or an HIL controller uint8_t motor; // Motor ID to control uint8_t encoder; // Encoder ID to measure motor position from @@ -178,13 +179,6 @@ static void NORETURN motorController_process(void) { // Measure motor rotation encoder_pos = (float)getEncoderPosition(params->encoder); delta = encoder_pos - params->last_encoder_pos; - /*if (getEncoderDirection(params->encoder) == ENCODER_DIR_UP) { - if (delta < 0) - delta = delta + 65535; - } else { - if (delta > 0) - delta = delta - 65535; - }*/ if (delta > 32767) { delta = delta - 65535; } else if (delta < - 32767) { @@ -208,12 +202,14 @@ static void NORETURN motorController_process(void) { params->last_estimate[1] = estimate[1]; params->last_encoder_pos = encoder_pos; - // Apply command - if (isnan(params->last_command)) { - motorSetSpeed(params->motor, 0); - motor_led_on(params->motor); - } else { - motorSetSpeed(params->motor, (int32_t)params->last_command); + // Apply command if necessary + if (!params->suspended) { + if (isnan(params->last_command)) { + motorSetSpeed(params->motor, 0); + motor_led_on(params->motor); + } else { + motorSetSpeed(params->motor, (int32_t)params->last_command); + } } } timer_waitEvent(&timer); // Wait for the remaining of the sample period @@ -416,3 +412,28 @@ void mc_change_mode(uint8_t motor, uint8_t new_mode) { } } } + +void mc_suspend_controller(uint8_t motor) { + control_params_t *params; + + params = &(controllers[get_motor_index(motor)]); + if (params->enable) + params->suspended = 1; + disableMotor(motor); +} + +void mc_reactivate_controller(uint8_t motor) { + control_params_t *params; + + params = &(controllers[get_motor_index(motor)]); + if (params->enable && params->suspended) { + params->last_command = 0; + params->last_estimate[0] = get_output_value(params->reference); + params->last_estimate[1] = 0; + params->last_output = params->last_estimate[0]; + params->last_encoder_pos = getEncoderPosition(params->encoder); + params->suspended = 0; + motorSetSpeed(motor, 0); + enableMotor(motor); + } +} diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/lib/motor_controller.h b/elec/boards/Controller_Motor_STM32/Firmwares/lib/motor_controller.h index f78cde4..0d793b2 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/lib/motor_controller.h +++ b/elec/boards/Controller_Motor_STM32/Firmwares/lib/motor_controller.h @@ -89,6 +89,13 @@ uint8_t mc_is_controller_running(uint8_t motor); * Returns 'motor' 's controller mode */ uint8_t mc_controller_mode(uint8_t motor); - +/* + * Suspends 'motor' 's controller + */ +void mc_suspend_controller(uint8_t motor); +/* + * Get back on-line a controller + */ +void mc_reactivate_controller(uint8_t motor); #endif diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/lib/odometry.c b/elec/boards/Controller_Motor_STM32/Firmwares/lib/odometry.c index 6b33924..33a597d 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/lib/odometry.c +++ b/elec/boards/Controller_Motor_STM32/Firmwares/lib/odometry.c @@ -15,6 +15,7 @@ static cpu_stack_t stack_odometry[MAX_ODOMETRY_PROCESSES][(ODOMETRY_STACK_SIZE + typedef struct { robot_state_t robot_state; float wheel_radius, shaft_width, left_encoder_gain, right_encoder_gain; + uint8_t left_encoder, right_encoder; float Ts; uint8_t enable; uint8_t running; @@ -24,7 +25,10 @@ odometry_state_t state[MAX_ODOMETRY_PROCESSES]; static void NORETURN odometry_process(void); -void odometryInit(uint8_t process_num, float Ts, float wheel_radius, float shaft_width, float left_encoder_gain, float right_encoder_gain) { +void odometryInit(uint8_t process_num, float Ts, + float wheel_radius, float shaft_width, + uint8_t left_encoder, uint8_t right_encoder, + float left_encoder_gain, float right_encoder_gain) { // Initialize initial state state[process_num].robot_state.x = 0.; @@ -34,6 +38,8 @@ void odometryInit(uint8_t process_num, float Ts, float wheel_radius, float shaft // Initialize robot parameters state[process_num].wheel_radius = wheel_radius; state[process_num].shaft_width = shaft_width; + state[process_num].left_encoder = left_encoder; + state[process_num].right_encoder = right_encoder; state[process_num].left_encoder_gain = left_encoder_gain; state[process_num].right_encoder_gain = right_encoder_gain; state[process_num].Ts = Ts; @@ -57,7 +63,6 @@ void odo_restart(uint8_t process_num) { static void NORETURN odometry_process(void) { float pos_l, pos_r, last_pos_l, last_pos_r, delta_l, delta_r; - uint8_t dir_l, dir_r; Timer timer; odometry_state_t *state; @@ -72,8 +77,8 @@ static void NORETURN odometry_process(void) { state->running = 1; // State initialization - last_pos_l = (float)getEncoderPosition(ENCODER3); - last_pos_r = (float)getEncoderPosition(ENCODER4); + last_pos_l = (float)getEncoderPosition(state->left_encoder); + last_pos_r = (float)getEncoderPosition(state->right_encoder); while (1) { if (state->enable == 0) { @@ -83,8 +88,8 @@ static void NORETURN odometry_process(void) { timer_add(&timer); // Measure motors rotation and correct wrapping - pos_l = (float)getEncoderPosition(ENCODER3); dir_l = getEncoderDirection(ENCODER3); - pos_r = (float)getEncoderPosition(ENCODER4); dir_r = getEncoderDirection(ENCODER4); + pos_l = (float)getEncoderPosition(state->left_encoder); + pos_r = (float)getEncoderPosition(state->right_encoder); delta_l = pos_l - last_pos_l; delta_r = pos_r - last_pos_r; if (delta_l > 32767) { @@ -97,20 +102,6 @@ static void NORETURN odometry_process(void) { } else if (delta_r < - 32767) { delta_r = delta_r + 65535; } - /*if (dir_l == ENCODER_DIR_UP) { - if (delta_l < 0) - delta_l = delta_l + 65535; - } else { - if (delta_l > 0) - delta_l = delta_l - 65535; - } - if (dir_r == ENCODER_DIR_UP) { - if (delta_r < 0) - delta_r = delta_r + 65535; - } else { - if (delta_r > 0) - delta_r = delta_r - 65535; - }*/ delta_l *= state->left_encoder_gain; delta_r *= state->right_encoder_gain; last_pos_l = pos_l; diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/lib/odometry.h b/elec/boards/Controller_Motor_STM32/Firmwares/lib/odometry.h index cac8c83..dcafed4 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/lib/odometry.h +++ b/elec/boards/Controller_Motor_STM32/Firmwares/lib/odometry.h @@ -22,7 +22,10 @@ typedef struct { float theta; } robot_state_t; -void odometryInit(uint8_t process_num, float Ts, float wheel_radius, float shaft_width, float left_encoder_gain, float right_encoder_gain); +void odometryInit(uint8_t process_num, float Ts, + float wheel_radius, float shaft_width, + uint8_t left_encoder, uint8_t right_encoder, + float left_encoder_gain, float right_encoder_gain); void odo_disable(uint8_t process_num); void odo_restart(uint8_t process_num); diff --git a/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/bertos/cpu/cortex-m3/drv/clock_stm32.h b/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/bertos/cpu/cortex-m3/drv/clock_stm32.h index e91753d..5c9203b 100644 --- a/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/bertos/cpu/cortex-m3/drv/clock_stm32.h +++ b/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/bertos/cpu/cortex-m3/drv/clock_stm32.h @@ -234,12 +234,30 @@ #define RCC_APB2_GPIOC (0x00000010) #define RCC_APB2_GPIOD (0x00000020) #define RCC_APB2_GPIOE (0x00000040) +#define RCC_APB2_GPIOF (0x00000080) +#define RCC_APB2_GPIOG (0x00000100) #define RCC_APB2_ADC1 (0x00000200) #define RCC_APB2_ADC2 (0x00000400) #define RCC_APB2_TIM1 (0x00000800) #define RCC_APB2_SPI1 (0x00001000) +#define RCC_APB2_TIM8 (0x00002000) #define RCC_APB2_USART1 (0x00004000) -#define RCC_APB2_ALL (0x00005E7D) +#define RCC_APB2_ADC3 (0x00008000) +#define RCC_APB2_ALL (RCC_APB2_AFIO \ + | RCC_APB2_GPIOA \ + | RCC_APB2_GPIOB \ + | RCC_APB2_GPIOC \ + | RCC_APB2_GPIOD \ + | RCC_APB2_GPIOE \ + | RCC_APB2_GPIOF \ + | RCC_APB2_GPIOG \ + | RCC_APB2_ADC1 \ + | RCC_APB2_ADC2 \ + | RCC_APB2_TIM1 \ + | RCC_APB2_SPI1 \ + | RCC_APB2_TIM8 \ + | RCC_APB2_USART1 \ + | RCC_APB2_ADC3) /** * RCC register: BCDR diff --git a/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/bertos/cpu/cortex-m3/drv/irq_cm3.c b/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/bertos/cpu/cortex-m3/drv/irq_cm3.c index 14311d9..bb8ac66 100644 --- a/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/bertos/cpu/cortex-m3/drv/irq_cm3.c +++ b/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/bertos/cpu/cortex-m3/drv/irq_cm3.c @@ -95,8 +95,10 @@ static void sysirq_enable(sysirq_t irq) /* Enable the IRQ line (only for generic IRQs) */ if (irq >= 16 && irq < 48) NVIC_EN0_R = 1 << (irq - 16); - else if (irq >= 48) + else if (irq >= 48 && irq < 80) NVIC_EN1_R = 1 << (irq - 48); + else if (irq >= 80) + NVIC_EN2_R = 1 << (irq - 80); } void sysirq_setHandler(sysirq_t irq, sysirq_handler_t handler) diff --git a/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/bertos/cpu/cortex-m3/io/stm32_ints.h b/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/bertos/cpu/cortex-m3/io/stm32_ints.h index 7fde933..c425b59 100644 --- a/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/bertos/cpu/cortex-m3/io/stm32_ints.h +++ b/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/bertos/cpu/cortex-m3/io/stm32_ints.h @@ -83,8 +83,25 @@ #define EXTI15_10_IRQHANDLER 56 /* External Line[15:10] Interrupts */ #define RTCALARM_IRQHANDLER 57 /* RTC Alarm through EXTI Line Interrupt */ #define USBWAKEUP_IRQHANDLER 58 /* USB WakeUp from suspend through EXTI Line Interrupt */ +#define TIM8_BRK_IRQHANDLER 59 /*TIM8 Break Interrupt */ +#define TIM8_UP_IRQHANDLER 60 /*TIM8 Update Interrupt */ +#define TIM8_TRG_COM_IRQHANDLER 61 /*TIM8 Trigger and Commutation Interrupt */ +#define TIM8_CC_IRQHANDLER 62 /*TIM8 Capture Compare Interrupt */ +#define ADC3_IRQHANDLER 63 /*ADC3 global Interrupt */ +#define FSMC_IRQHANDLER 64 /*FSMC global Interrupt */ +#define SDIO_IRQHANDLER 65 /*SDIO global Interrupt */ +#define TIM5_IRQHANDLER 66 /*TIM5 global Interrupt */ +#define SPI3_IRQHANDLER 67 /*SPI3 global Interrupt */ +#define UART4_IRQHANDLER 68 /*UART4 global Interrupt */ +#define UART5_IRQHANDLER 69 /*UART5 global Interrupt */ +#define TIM6_IRQHANDLER 70 /*TIM6 global Interrupt */ +#define TIM7_IRQHANDLER 71 /*TIM7 global Interrupt */ +#define DMA2_Channel1_IRQHANDLER 72 /*DMA2 Channel 1 global Interrupt */ +#define DMA2_Channel2_IRQHANDLER 73 /*DMA2 Channel 2 global Interrupt */ +#define DMA2_Channel3_IRQHANDLER 74 /*DMA2 Channel 3 global Interrupt */ +#define DMA2_Channel4_5_IRQHANDLER 75 /* DMA2 Channel 4 and Channel 5 global Interrupt */ /*\}*/ -#define NUM_INTERRUPTS 66 +#define NUM_INTERRUPTS 76 #endif /* STM32_INTS_H */ diff --git a/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/bertos/cpu/cortex-m3/io/stm32_nvic.h b/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/bertos/cpu/cortex-m3/io/stm32_nvic.h index 9a209f3..6b35d10 100644 --- a/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/bertos/cpu/cortex-m3/io/stm32_nvic.h +++ b/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/bertos/cpu/cortex-m3/io/stm32_nvic.h @@ -63,6 +63,7 @@ #define NVIC_ST_CAL_R (*((reg32_t *)0xE000E01C)) #define NVIC_EN0_R (*((reg32_t *)0xE000E100)) #define NVIC_EN1_R (*((reg32_t *)0xE000E104)) +#define NVIC_EN2_R (*((reg32_t *)0xE000E108)) #define NVIC_DIS0_R (*((reg32_t *)0xE000E180)) #define NVIC_DIS1_R (*((reg32_t *)0xE000E184)) #define NVIC_PEND0_R (*((reg32_t *)0xE000E200)) diff --git a/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/sensor_actuator.cbp b/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/sensor_actuator.cbp new file mode 100644 index 0000000..ae3b3e2 --- /dev/null +++ b/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/sensor_actuator.cbp @@ -0,0 +1,202 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> +<CodeBlocks_project_file> + <FileVersion major="1" minor="6" /> + <Project> + <Option title="sensor_actuator" /> + <Option makefile_is_custom="1" /> + <Option pch_mode="2" /> + <Option compiler="gcc" /> + <MakeCommands> + <Build command="make" /> + <CompileFile command="make" /> + <Clean command="make clean" /> + <DistClean command="$make -f $makefile distclean$target" /> + <AskRebuildNeeded command="$make -q -f $makefile $target" /> + <SilentBuild command="$make -s -f $makefile $target" /> + </MakeCommands> + <Build> + <Target title=" "> + <Option output="bin/Release/sensor_actuator" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Release/" /> + <Option type="1" /> + <Option compiler="gcc" /> + <Compiler> + <Add option="-O2" /> + </Compiler> + <Linker> + <Add option="-s" /> + </Linker> + <MakeCommands> + <Build command="make" /> + <CompileFile command="make" /> + <Clean command="make clean" /> + <DistClean command="$make -f $makefile distclean$target" /> + <AskRebuildNeeded command="$make -q -f $makefile $target" /> + <SilentBuild command="$make -s -f $makefile $target" /> + </MakeCommands> + </Target> + </Build> + <Compiler> + <Add option="-Wall" /> + </Compiler> + <Unit filename="sensor_actuator/adc/adc.c"> + <Option compilerVar="CC" /> + </Unit> + <Unit filename="sensor_actuator/adc/adc.h" /> + <Unit filename="sensor_actuator/ax12/ax12.c"> + <Option compilerVar="CC" /> + </Unit> + <Unit filename="sensor_actuator/ax12/ax12.h" /> + <Unit filename="sensor_actuator/ax12/ax12_highlevel.c"> + <Option compilerVar="CC" /> + </Unit> + <Unit filename="sensor_actuator/ax12/ax12_highlevel.h" /> + <Unit filename="sensor_actuator/ax12/serial.c"> + <Option compilerVar="CC" /> + </Unit> + <Unit filename="sensor_actuator/ax12/serial.h" /> + <Unit filename="sensor_actuator/battery_monitoring/ads7828.c"> + <Option compilerVar="CC" /> + </Unit> + <Unit filename="sensor_actuator/battery_monitoring/ads7828.h" /> + <Unit filename="sensor_actuator/battery_monitoring/battery_monitoring.c"> + <Option compilerVar="CC" /> + </Unit> + <Unit filename="sensor_actuator/battery_monitoring/battery_monitoring.h" /> + <Unit filename="sensor_actuator/beacon/beacon.c"> + <Option compilerVar="CC" /> + </Unit> + <Unit filename="sensor_actuator/beacon/beacon.h" /> + <Unit filename="sensor_actuator/beacon/stm32lib/core_cm3.h" /> + <Unit filename="sensor_actuator/beacon/stm32lib/stm32f10x.h" /> + <Unit filename="sensor_actuator/beacon/stm32lib/stm32f10x_rcc.c"> + <Option compilerVar="CC" /> + </Unit> + <Unit filename="sensor_actuator/beacon/stm32lib/stm32f10x_rcc.h" /> + <Unit filename="sensor_actuator/beacon/stm32lib/stm32f10x_tim.c"> + <Option compilerVar="CC" /> + </Unit> + <Unit filename="sensor_actuator/beacon/stm32lib/stm32f10x_tim.h" /> + <Unit filename="sensor_actuator/can/can_messages.h" /> + <Unit filename="sensor_actuator/can/can_monitor.c"> + <Option compilerVar="CC" /> + </Unit> + <Unit filename="sensor_actuator/can/can_monitor.h" /> + <Unit filename="sensor_actuator/cfg/cfg_adc.h" /> + <Unit filename="sensor_actuator/cfg/cfg_afsk.h" /> + <Unit filename="sensor_actuator/cfg/cfg_ax25.h" /> + <Unit filename="sensor_actuator/cfg/cfg_battfs.h" /> + <Unit filename="sensor_actuator/cfg/cfg_can.h" /> + <Unit filename="sensor_actuator/cfg/cfg_context_switch.h" /> + <Unit filename="sensor_actuator/cfg/cfg_dac.h" /> + <Unit filename="sensor_actuator/cfg/cfg_dataflash.h" /> + <Unit filename="sensor_actuator/cfg/cfg_dc_motor.h" /> + <Unit filename="sensor_actuator/cfg/cfg_debug.h" /> + <Unit filename="sensor_actuator/cfg/cfg_eeprom.h" /> + <Unit filename="sensor_actuator/cfg/cfg_emb_flash.h" /> + <Unit filename="sensor_actuator/cfg/cfg_eth.h" /> + <Unit filename="sensor_actuator/cfg/cfg_fat.h" /> + <Unit filename="sensor_actuator/cfg/cfg_flash25.h" /> + <Unit filename="sensor_actuator/cfg/cfg_formatwr.h" /> + <Unit filename="sensor_actuator/cfg/cfg_gfx.h" /> + <Unit filename="sensor_actuator/cfg/cfg_hashtable.h" /> + <Unit filename="sensor_actuator/cfg/cfg_heap.h" /> + <Unit filename="sensor_actuator/cfg/cfg_i2c.h" /> + <Unit filename="sensor_actuator/cfg/cfg_i2s.h" /> + <Unit filename="sensor_actuator/cfg/cfg_ini_reader.h" /> + <Unit filename="sensor_actuator/cfg/cfg_kbd.h" /> + <Unit filename="sensor_actuator/cfg/cfg_keytag.h" /> + <Unit filename="sensor_actuator/cfg/cfg_kfile.h" /> + <Unit filename="sensor_actuator/cfg/cfg_lcd_32122a.h" /> + <Unit filename="sensor_actuator/cfg/cfg_lcd_hd44.h" /> + <Unit filename="sensor_actuator/cfg/cfg_led_7seg.h" /> + <Unit filename="sensor_actuator/cfg/cfg_lm75.h" /> + <Unit filename="sensor_actuator/cfg/cfg_lwip.h" /> + <Unit filename="sensor_actuator/cfg/cfg_md2.h" /> + <Unit filename="sensor_actuator/cfg/cfg_monitor.h" /> + <Unit filename="sensor_actuator/cfg/cfg_nand.h" /> + <Unit filename="sensor_actuator/cfg/cfg_nmea.h" /> + <Unit filename="sensor_actuator/cfg/cfg_parser.h" /> + <Unit filename="sensor_actuator/cfg/cfg_phase.h" /> + <Unit filename="sensor_actuator/cfg/cfg_pocketbus.h" /> + <Unit filename="sensor_actuator/cfg/cfg_proc.h" /> + <Unit filename="sensor_actuator/cfg/cfg_pwm.h" /> + <Unit filename="sensor_actuator/cfg/cfg_ramp.h" /> + <Unit filename="sensor_actuator/cfg/cfg_random.h" /> + <Unit filename="sensor_actuator/cfg/cfg_randpool.h" /> + <Unit filename="sensor_actuator/cfg/cfg_sd.h" /> + <Unit filename="sensor_actuator/cfg/cfg_sem.h" /> + <Unit filename="sensor_actuator/cfg/cfg_ser.h" /> + <Unit filename="sensor_actuator/cfg/cfg_signal.h" /> + <Unit filename="sensor_actuator/cfg/cfg_spi_bitbang.h" /> + <Unit filename="sensor_actuator/cfg/cfg_stepper.h" /> + <Unit filename="sensor_actuator/cfg/cfg_tas5706a.h" /> + <Unit filename="sensor_actuator/cfg/cfg_tftp.h" /> + <Unit filename="sensor_actuator/cfg/cfg_thermo.h" /> + <Unit filename="sensor_actuator/cfg/cfg_timer.h" /> + <Unit filename="sensor_actuator/cfg/cfg_usb.h" /> + <Unit filename="sensor_actuator/cfg/cfg_usbkbd.h" /> + <Unit filename="sensor_actuator/cfg/cfg_usbmouse.h" /> + <Unit filename="sensor_actuator/cfg/cfg_usbser.h" /> + <Unit filename="sensor_actuator/cfg/cfg_wdt.h" /> + <Unit filename="sensor_actuator/cfg/cfg_xmodem.h" /> + <Unit filename="sensor_actuator/hw/hw_afsk.h" /> + <Unit filename="sensor_actuator/hw/hw_buzzer.h" /> + <Unit filename="sensor_actuator/hw/hw_dataflash.c"> + <Option compilerVar="CC" /> + </Unit> + <Unit filename="sensor_actuator/hw/hw_dataflash.h" /> + <Unit filename="sensor_actuator/hw/hw_dc_motor.h" /> + <Unit filename="sensor_actuator/hw/hw_ft245rl.h" /> + <Unit filename="sensor_actuator/hw/hw_hx8347.h" /> + <Unit filename="sensor_actuator/hw/hw_i2c_bitbang.h" /> + <Unit filename="sensor_actuator/hw/hw_ili9225.h" /> + <Unit filename="sensor_actuator/hw/hw_kbd.h" /> + <Unit filename="sensor_actuator/hw/hw_lcd_32122a.h" /> + <Unit filename="sensor_actuator/hw/hw_lcd_hd44.h" /> + <Unit filename="sensor_actuator/hw/hw_led.h" /> + <Unit filename="sensor_actuator/hw/hw_led_7seg.h" /> + <Unit filename="sensor_actuator/hw/hw_lm75.h" /> + <Unit filename="sensor_actuator/hw/hw_mcp41.c"> + <Option compilerVar="CC" /> + </Unit> + <Unit filename="sensor_actuator/hw/hw_mcp41.h" /> + <Unit filename="sensor_actuator/hw/hw_ntc.c"> + <Option compilerVar="CC" /> + </Unit> + <Unit filename="sensor_actuator/hw/hw_ntc.h" /> + <Unit filename="sensor_actuator/hw/hw_phase.c"> + <Option compilerVar="CC" /> + </Unit> + <Unit filename="sensor_actuator/hw/hw_phase.h" /> + <Unit filename="sensor_actuator/hw/hw_rit128x96.h" /> + <Unit filename="sensor_actuator/hw/hw_sd.h" /> + <Unit filename="sensor_actuator/hw/hw_ser.h" /> + <Unit filename="sensor_actuator/hw/hw_sipo.h" /> + <Unit filename="sensor_actuator/hw/hw_spi.h" /> + <Unit filename="sensor_actuator/hw/hw_stepper.h" /> + <Unit filename="sensor_actuator/hw/hw_tas5706a.h" /> + <Unit filename="sensor_actuator/hw/hw_thermo.h" /> + <Unit filename="sensor_actuator/hw/hw_tlv5618.h" /> + <Unit filename="sensor_actuator/hw/hw_tmp123.h" /> + <Unit filename="sensor_actuator/hw/kbd_map.h" /> + <Unit filename="sensor_actuator/hw/mcp41_map.h" /> + <Unit filename="sensor_actuator/hw/ntc_map.h" /> + <Unit filename="sensor_actuator/hw/phase_map.h" /> + <Unit filename="sensor_actuator/hw/pwm_map.h" /> + <Unit filename="sensor_actuator/hw/thermo_map.h" /> + <Unit filename="sensor_actuator/main.c"> + <Option compilerVar="CC" /> + </Unit> + <Unit filename="sensor_actuator/switch/switch.c"> + <Option compilerVar="CC" /> + </Unit> + <Unit filename="sensor_actuator/switch/switch.h" /> + <Extensions> + <envvars /> + <code_completion /> + <debugger /> + <lib_finder disable_auto="1" /> + </Extensions> + </Project> +</CodeBlocks_project_file> diff --git a/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/sensor_actuator/beacon/beacon.c b/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/sensor_actuator/beacon/beacon.c index 6d180ea..be33ec7 100644 --- a/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/sensor_actuator/beacon/beacon.c +++ b/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/sensor_actuator/beacon/beacon.c @@ -26,149 +26,158 @@ static struct Event got_capture; static struct Event updated_beacon; -static uint16_t cur_period = 0; -static uint16_t cur_width = 0; - +static uint16_t beacon_idx = 0; +static uint16_t beacon_measured = 0; +static uint32_t beacon_start[MAX_BEACONS] = {0}; +static uint32_t beacon_stop[MAX_BEACONS] = {0}; static uint32_t period = 0; -static uint16... [truncated message content] |
From: Pierre C. <Ba...@us...> - 2012-05-15 23:13:18
|
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 39d27a4038f8f91b6469513e63ba3ccb4da8d3e8 (commit) from ea5d9b40eb2d99f440301de0de5be3f232ef1e74 (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 39d27a4038f8f91b6469513e63ba3ccb4da8d3e8 Author: chicco <cha...@cr...> Date: Wed May 16 01:12:29 2012 +0200 [control] ready for homologation ----------------------------------------------------------------------- Changes: diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/controller_motor_stm32.mk b/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/controller_motor_stm32.mk index cbfc980..ac9aa9a 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/controller_motor_stm32.mk +++ b/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/controller_motor_stm32.mk @@ -9,7 +9,7 @@ Firmware_DEBUG = 1 # Our target application TRG += controller_motor_stm32 -controller_motor_stm32_PREFIX = "/home/lxir/opt/arm/bin/arm-none-eabi-" +controller_motor_stm32_PREFIX = "/media/data/krobot/arm-i386/bin/arm-none-eabi-" controller_motor_stm32_SUFFIX = "" diff --git a/info/control2011/_tags b/info/control2011/_tags index c2c77dd..1deda0d 100644 --- a/info/control2011/_tags +++ b/info/control2011/_tags @@ -2,7 +2,7 @@ <src/interfaces/*.ml>: -syntax_camlp4o # OASIS_START -# DO NOT EDIT (digest: 8b68a015ff8be0607836f173f33170fd) +# DO NOT EDIT (digest: 791dda707015630876eec58d1f5251cd) # Ignore VCS directories, you can use the same kind of rule outside # OASIS_START/STOP if you want to exclude directories that contains # useless stuff for the build process @@ -77,6 +77,11 @@ <src/tools/krobot_record.{native,byte}>: pkg_lwt.unix <src/tools/krobot_record.{native,byte}>: pkg_lwt.syntax <src/tools/krobot_record.{native,byte}>: pkg_lwt.react +# Executable krobot-homologation +<src/tools/krobot_homologation.{native,byte}>: use_krobot +<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-simulator <src/tools/krobot_simulator.{native,byte}>: use_krobot <src/tools/krobot_simulator.{native,byte}>: pkg_lwt.unix diff --git a/info/control2011/setup.ml b/info/control2011/setup.ml index e0ea140..ac9febe 100644 --- a/info/control2011/setup.ml +++ b/info/control2011/setup.ml @@ -1,7 +1,7 @@ (* setup.ml generated for the first time by OASIS v0.2.0~alpha1 *) (* OASIS_START *) -(* DO NOT EDIT (digest: 6276a9db280e9f6fd9a16f0e5e4359c8) *) +(* DO NOT EDIT (digest: b99935b89748cc3e2881684ab7d70ce0) *) (* Regenerated by OASIS v0.3.0~rc3 Visit http://oasis.forge.ocamlcore.org for more information and @@ -5540,6 +5540,36 @@ let setup_t = {exec_custom = false; exec_main_is = "krobot_record.ml"; }); Executable ({ + cs_name = "krobot-homologation"; + 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_homologation.ml"; + }); + Executable + ({ cs_name = "krobot-simulator"; cs_data = PropList.Data.create (); cs_plugin_data = []; @@ -6220,13 +6250,13 @@ let setup_t = }; oasis_fn = Some "_oasis"; oasis_version = "0.3.0~rc3"; - oasis_digest = Some "\189Q=v\151\180\162\208\188\238+\208>;\014V"; + oasis_digest = Some "^\025\t\b\239\141[v`R\255\200\143\017g\177"; oasis_exec = None; oasis_setup_args = []; };; let setup () = BaseSetup.setup setup_t;; -# 6231 "setup.ml" +# 6261 "setup.ml" (* OASIS_STOP *) let () = setup ();; diff --git a/info/control2011/src/lib/krobot_config.ml b/info/control2011/src/lib/krobot_config.ml index 4c5ef37..a88c48b 100644 --- a/info/control2011/src/lib/krobot_config.ml +++ b/info/control2011/src/lib/krobot_config.ml @@ -22,3 +22,65 @@ let object_safety_distance = object_radius +. robot_size /. 2. let beacon_safety_distance = 0.7 let coin_radius = 0.12 + +open Krobot_geom + +let pi = 4. *. atan 1. + +let red_initial_position = + { x = 0.25; + y = world_height -. 0.25; }, + 0. + +let blue_initial_position = + { x = world_width -. 0.25; + y = world_height -. 0.25; }, + pi + + +let fixed_obstacles = + [ + (* the trees *) + { pos = + { x = 0.64 +. 0.477; + y = 1. }; + size = sqrt (2. *. 0.125 *. 0.125); }; + { pos = + { x = world_width -. (0.64 +. 0.477); + y = 1. }; + size = sqrt (2. *. 0.125 *. 0.125); }; + + { pos = + { x = 1.5; + y = 1. }; + size = 0.1; }; + + (* entry position *) + { pos = + { x = 0.; + y = 1.5 }; + size = 0.1; }; + { pos = + { x = 0.2; + y = 1.5 }; + size = 0.1; }; + { pos = + { x = 0.4; + y = 1.5 }; + size = 0.1; }; + + { pos = + { x = world_width; + y = 1.5 }; + size = 0.1; }; + { pos = + { x = world_width -. 0.2; + y = 1.5 }; + size = 0.1; }; + { pos = + { x = world_width -. 0.4; + y = 1.5 }; + size = 0.1; }; + + + ] diff --git a/info/control2011/src/lib/krobot_config.mli b/info/control2011/src/lib/krobot_config.mli index def3497..3ca4531 100644 --- a/info/control2011/src/lib/krobot_config.mli +++ b/info/control2011/src/lib/krobot_config.mli @@ -46,3 +46,12 @@ val beacon_safety_distance : float val coin_radius : float (** Radius of coins. *) + +val red_initial_position : Krobot_geom.vertice * float + (** position and angle of the robot as red *) + +val blue_initial_position : Krobot_geom.vertice * float + (** position and angle of the robot as blue *) + + +val fixed_obstacles : Krobot_geom.obj list diff --git a/info/control2011/src/lib/krobot_geom.ml b/info/control2011/src/lib/krobot_geom.ml index 2f87a84..2d8c61a 100644 --- a/info/control2011/src/lib/krobot_geom.ml +++ b/info/control2011/src/lib/krobot_geom.ml @@ -101,6 +101,8 @@ let mult m v = (fun k -> Array.fold_left (+.) 0. (Array.mapi (fun i n -> v.(i) *. n) m.(k))) +type obj = { pos : vertice; size : float } + (* +-----------------------------------------------------------------+ | Cubic bezier curves | +-----------------------------------------------------------------+ *) diff --git a/info/control2011/src/lib/krobot_geom.mli b/info/control2011/src/lib/krobot_geom.mli index 71ec7e9..fbbb624 100644 --- a/info/control2011/src/lib/krobot_geom.mli +++ b/info/control2011/src/lib/krobot_geom.mli @@ -20,6 +20,8 @@ val math_mod_float : float -> float -> float type vector = { vx : float; vy : float } type vertice = { x : float; y : float } +type obj = { pos : vertice; size : float } + val null : vector val origin : vertice diff --git a/info/control2011/src/lib/krobot_pathfinding.ml b/info/control2011/src/lib/krobot_pathfinding.ml index b3c5262..63bd27f 100644 --- a/info/control2011/src/lib/krobot_pathfinding.ml +++ b/info/control2011/src/lib/krobot_pathfinding.ml @@ -23,14 +23,14 @@ module Vect = struct type circle = { c : point; r : float } type segment = { p1 : point; p2 : point } type line = { p : point; v : vect } - + let epsilon = 0.0000000001 - + let vect p1 p2 = { vx = p2.px -. p1.px; vy = p2.py -. p1.py } - + let ( +! ) p v = { px = v.vx +. p.px; py = v.vy +. p.py } let ( -! ) p v = { px = p.px -. v.vx; py = p.py -. v.vy } - + let ( +| ) v1 v2 = { vx = v1.vx +. v2.vx; vy = v1.vy +. v2.vy } let ( -| ) v1 v2 = { vx = v1.vx -. v2.vx; vy = v1.vy -. v2.vy } let ( *@ ) n v = { vx = n *. v.vx; vy = n *. v.vy } @@ -42,7 +42,7 @@ module Vect = struct let line s = { p = s.p1; v = vect s.p1 s.p2 } let scal v1 v2 = v1.vx *. v2.vx +. v1.vy *. v2.vy let colineaire v1 v2 = abs_float (v1.vx *. v2.vy -. v1.vy *. v2.vx) < epsilon - + let distance s p = let middle = ( scal diff --git a/info/control2011/src/tools/krobot_dump.ml b/info/control2011/src/tools/krobot_dump.ml index a734159..5b7f7ca 100644 --- a/info/control2011/src/tools/krobot_dump.ml +++ b/info/control2011/src/tools/krobot_dump.ml @@ -79,9 +79,7 @@ lwt () = Lwt_io.printl "" | Trajectory_go -> Lwt_io.printf "trajectory_go" - | _ -> - Lwt_io.printf "truc" - (*return ()*)) + | _ -> return ()) (Krobot_bus.recv bus)); fst (wait ()) diff --git a/info/control2011/src/tools/krobot_homologation.ml b/info/control2011/src/tools/krobot_homologation.ml index e06a26a..c69761b 100644 --- a/info/control2011/src/tools/krobot_homologation.ml +++ b/info/control2011/src/tools/krobot_homologation.ml @@ -11,6 +11,7 @@ open Krobot_bus open Krobot_action +open Krobot_geom let init_pos, init_angle = Krobot_config.red_initial_position @@ -21,14 +22,14 @@ let path = { x = 0.7; y = 1.15 }; { x = 0.5; y = 1.15 }; { x = 0.4; y = 1.15 }; - ]; + ] lwt () = lwt bus = Krobot_bus.get () in Krobot_bus.send bus (Unix.gettimeofday (), Strategy_set [ + Reset_odometry `Red; Wait_for_jack false; - Reset_odometry `Auto; Follow_path path; ]) diff --git a/info/control2011/src/tools/krobot_viewer.ml b/info/control2011/src/tools/krobot_viewer.ml index c7453b7..81adc86 100644 --- a/info/control2011/src/tools/krobot_viewer.ml +++ b/info/control2011/src/tools/krobot_viewer.ml @@ -283,6 +283,17 @@ let draw viewer = Cairo.stroke ctx) viewer.coins; + (* Draw obstacles *) + Cairo.set_source_rgba ctx 255. 255. 255. 0.5; + let () = + let open Krobot_geom in + List.iter + (fun { pos = { x; y }; size } -> + Cairo.arc ctx x y size 0. (2. *. pi); + Cairo.fill ctx) + Krobot_config.fixed_obstacles + in + (* Draw the robot and the ghost *) List.iter (fun (state, alpha) -> @@ -497,7 +508,7 @@ let handle_message viewer (timestamp, message) = (fun v -> let v = [|v.x;v.y;1.|] in let v = mult (rot_mat viewer.state.theta) v in - { x = v.(0); y = v.(1) }) l; + Krobot_geom.translate viewer.state.pos { vx = v.(0); vy = v.(1) }) l; queue_draw viewer | _ -> diff --git a/info/control2011/src/tools/krobot_vm.ml b/info/control2011/src/tools/krobot_vm.ml index 5bd2d11..1b38347 100644 --- a/info/control2011/src/tools/krobot_vm.ml +++ b/info/control2011/src/tools/krobot_vm.ml @@ -57,6 +57,9 @@ type robot = { mutable objects : vertice list; (* Position of objects on the table. *) + mutable coins : vertice list; + (* Position of coins on the table *) + mutable moving : bool; (* Is the robot moving ? *) @@ -171,6 +174,14 @@ let handle_message robot (timestamp, message) = | Objects l -> robot.objects <- l + | Coins l -> + robot.coins <- + List.map + (fun v -> + let v = [|v.x;v.y;1.|] in + let v = mult (rot_mat robot.orientation) v in + Krobot_geom.translate robot.position { vx = v.(0); vy = v.(1) }) l + | Strategy_append l -> begin match robot.append_strategy with | Some l' -> @@ -343,7 +354,7 @@ let rec exec robot actions = ignore (Lwt_log.info "Bezier"); (* Compute parameters. *) let d1 = sign *. distance p q and d2 = distance r s in - if d1 = 0. || d2 = 0. + if abs_float d1 <= 0.01 || abs_float d2 = 0.01 then (* in that case: there is an error somewhere else: search and destroy it ! *) @@ -361,10 +372,13 @@ let rec exec robot actions = Send (match which, robot.team with | `Red, _ | `Auto, `Red -> - Set_odometry(0.215 -. robot_size /. 2. +. wheels_position, - world_height -. robot_size -. 0.1 , 0.) + let { Krobot_geom.x; y }, angle = Krobot_config.red_initial_position in + Set_odometry( x, + y, 0. ) | `Blue, _ | `Auto, `Blue -> - Set_odometry(2.77, world_height -. 0.1 , pi))) + let { Krobot_geom.x; y }, angle = Krobot_config.blue_initial_position in + Set_odometry( x, + y, pi))) | Load face :: rest -> exec robot (Node [ Lift_down face; @@ -501,6 +515,7 @@ lwt () = ghost_position = { x = 0.; y = 0. }; orientation = 0.; objects = []; + coins = []; moving = false; path = None; curve = None; hooks/post-receive -- krobot |
From: Pierre C. <Ba...@us...> - 2012-05-15 22:13:29
|
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 ea5d9b40eb2d99f440301de0de5be3f232ef1e74 (commit) via 8405c1cc560b0db86389ae2f7e169ba460463f09 (commit) from ff93134afe82b8e1bc1ea72a8d8af8a2b6c756e6 (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 ea5d9b40eb2d99f440301de0de5be3f232ef1e74 Author: chicco <cha...@cr...> Date: Wed May 16 00:12:18 2012 +0200 [control] add a small homologation program commit 8405c1cc560b0db86389ae2f7e169ba460463f09 Author: chicco <cha...@cr...> Date: Tue May 15 18:12:19 2012 +0200 [control] vm: protect against invalid bezier curve ----------------------------------------------------------------------- Changes: diff --git a/info/control2011/_oasis b/info/control2011/_oasis index 3227ab2..c9dcb61 100644 --- a/info/control2011/_oasis +++ b/info/control2011/_oasis @@ -212,6 +212,13 @@ Executable "krobot-ia" MainIs: krobot_ia.ml BuildDepends: krobot, lwt.syntax +Executable "krobot-homologation" + Path: src/tools + Install: true + CompiledObject: best + MainIs: krobot_homologation.ml + BuildDepends: krobot, lwt.syntax + Executable "krobot-can-display" Path: src/tools Build$: flag(gtk) diff --git a/info/control2011/src/tools/krobot_homologation.ml b/info/control2011/src/tools/krobot_homologation.ml new file mode 100644 index 0000000..e06a26a --- /dev/null +++ b/info/control2011/src/tools/krobot_homologation.ml @@ -0,0 +1,34 @@ +(* + * krobot_homologation.ml + * ------------ + * Copyright : (c) 2012, Pierre Chambart <cha...@cr...> + * Licence : BSD3 + * + * This file is a part of [kro]bot. + *) + +(* The simple ai for homologation. *) + +open Krobot_bus +open Krobot_action + +let init_pos, init_angle = Krobot_config.red_initial_position + +let path = + [ + { x = 0.7; y = init_pos.y }; + { x = 0.8; y = 1.5 }; + { x = 0.7; y = 1.15 }; + { x = 0.5; y = 1.15 }; + { x = 0.4; y = 1.15 }; + ]; + +lwt () = + lwt bus = Krobot_bus.get () in + Krobot_bus.send bus + (Unix.gettimeofday (), + Strategy_set [ + Wait_for_jack false; + Reset_odometry `Auto; + Follow_path path; + ]) diff --git a/info/control2011/src/tools/krobot_vm.ml b/info/control2011/src/tools/krobot_vm.ml index 32d541a..5bd2d11 100644 --- a/info/control2011/src/tools/krobot_vm.ml +++ b/info/control2011/src/tools/krobot_vm.ml @@ -343,9 +343,16 @@ let rec exec robot actions = ignore (Lwt_log.info "Bezier"); (* Compute parameters. *) let d1 = sign *. distance p q and d2 = distance r s in - let v = vector r s in - let theta_end = atan2 v.vy v.vx in - (rest, Send(Motor_bezier(s.x, s.y, d1, d2, theta_end, v_end))) + if d1 = 0. || d2 = 0. + then + (* in that case: there is an error somewhere else: + search and destroy it ! *) + (ignore (Lwt_log.error_f "Error: Bezier with d1 = %f, d2 = %f" d1 d2); + ([], Wait)) + else + let v = vector r s in + let theta_end = atan2 v.vy v.vx in + (rest, Send(Motor_bezier(s.x, s.y, d1, d2, theta_end, v_end))) | Stop :: rest -> reset robot; (rest, Send(Motor_stop(1.0, 0.0))) @@ -354,9 +361,10 @@ let rec exec robot actions = Send (match which, robot.team with | `Red, _ | `Auto, `Red -> - Set_odometry(0.215 -. robot_size /. 2. +. wheels_position, 1.885, 0.) + Set_odometry(0.215 -. robot_size /. 2. +. wheels_position, + world_height -. robot_size -. 0.1 , 0.) | `Blue, _ | `Auto, `Blue -> - Set_odometry(2.77, 1.915, pi))) + Set_odometry(2.77, world_height -. 0.1 , pi))) | Load face :: rest -> exec robot (Node [ Lift_down face; hooks/post-receive -- krobot |
From: Xavier L. <Ba...@us...> - 2012-05-15 20:14:03
|
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 ff93134afe82b8e1bc1ea72a8d8af8a2b6c756e6 (commit) via 7f4506759a33ee70857837cccfc047a1ef6f03f5 (commit) from a66675c38188c8ce812898d3d4865d53294c7be6 (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 ff93134afe82b8e1bc1ea72a8d8af8a2b6c756e6 Author: Xavier Lagorce <Xav...@cr...> Date: Tue May 15 22:13:33 2012 +0200 [control2011] More CAN packets (bugged ?...) commit 7f4506759a33ee70857837cccfc047a1ef6f03f5 Author: Xavier Lagorce <Xav...@cr...> Date: Tue May 15 18:39:56 2012 +0200 [Controller_Motor_STM32] Added a mechanism to send CAN frames indicating software errors ----------------------------------------------------------------------- Changes: diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/can_messages.h b/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/can_messages.h index aa5c8b1..94ebea0 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/can_messages.h +++ b/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/can_messages.h @@ -23,6 +23,7 @@ #define CAN_MSG_STATUS 103 // status_can_msg_t #define CAN_MSG_ODOMETRY 104 // odometry_can_msg_t #define CAN_MSG_GHOST 105 // ghost_can_msg_t +#define CAN_MSG_CONTROL_ERROR 106 // error_can_msg_t // Received commands #define CAN_MSG_MOVE 201 // move_can_msg_t @@ -58,6 +59,12 @@ typedef struct { uint8_t is_moving; } status_msg_t; +// Error packet +typedef struct { + uint8_t err1; + uint8_t err2; +} error_msg_t; + // Robot state typedef struct { int16_t x __attribute__((__packed__)); // X position in mm (fixed point representation...) @@ -142,6 +149,11 @@ typedef union { } status_can_msg_t; typedef union { + error_msg_t data; + uint32_t data32[2]; +} error_can_msg_t; + +typedef union { odometry_msg_t data; uint32_t data32[2]; } odometry_can_msg_t; diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/can_monitor.c b/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/can_monitor.c index bae2706..5ed50a6 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/can_monitor.c +++ b/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/can_monitor.c @@ -20,6 +20,7 @@ PROC_DEFINE_STACK(stack_can_send, KERN_MINSTACKSIZE * 8); PROC_DEFINE_STACK(stack_can_receive, KERN_MINSTACKSIZE * 8); // globals volatile uint8_t mode; +volatile uint8_t err1, err2, send_err; // Process for communication static void NORETURN canMonitor_process(void); @@ -45,12 +46,19 @@ void canMonitorInit(void) { proc_new(canMonitorListen_process, NULL, sizeof(stack_can_receive), stack_can_receive); } +void can_send_error(uint8_t e1, uint8_t e2) { + err1 |= e1; + err2 |= e2; + send_err = 1; +} + static void NORETURN canMonitor_process(void) { //encoder_can_msg_t msg_enc; motor_can_msg_t msg_mot; odometry_can_msg_t msg_odo; ghost_can_msg_t msg_ghost; status_can_msg_t status_msg; + error_can_msg_t error_msg; can_tx_frame txm; robot_state_t odometry; float u; @@ -136,6 +144,17 @@ static void NORETURN canMonitor_process(void) { txm.eid = CAN_MSG_STATUS; can_transmit(CAND1, &txm, ms_to_ticks(10)); + // Send error packet if requested + if (send_err) { + error_msg.data.err1 = err1; err1 = 0; + error_msg.data.err2 = err2; err2 = 0; + send_err = 0; + txm.data32[0] = error_msg.data32[0]; + txm.data32[1] = error_msg.data32[1]; + txm.eid = CAN_MSG_CONTROL_ERROR; + can_transmit(CAND1, &txm, ms_to_ticks(10)); + } + // Wait for the next transmission timer timer_waitEvent(&timer_can); } diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/can_monitor.h b/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/can_monitor.h index da6ad7f..c157f58 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/can_monitor.h +++ b/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/can_monitor.h @@ -21,5 +21,6 @@ #include "can_messages.h" void canMonitorInit(void); +void can_send_error(uint8_t err1, uint8_t err2); #endif /* __CAN_MONITOR_H */ diff --git a/info/control2011/src/lib/krobot_message.ml b/info/control2011/src/lib/krobot_message.ml index 4addf15..285dfdc 100644 --- a/info/control2011/src/lib/krobot_message.ml +++ b/info/control2011/src/lib/krobot_message.ml @@ -36,10 +36,12 @@ type t = | Encoder_position_direction_3_4 of int * direction * int * direction | Encoder_position_speed_3 of float * float | Encoder_position_speed_4 of float * float + | Control_error of int * int | Motor_status of bool * bool * bool * bool | Motor_move of float * float * float | Motor_turn of float * float * float | Motor_bezier of float * float * float * float * float * float + | Motor_command of int * int | Motor_stop of float * float | Motor_bezier_limits of float * float * float | Odometry of float * float * float @@ -144,6 +146,10 @@ let to_string = function sprintf "Motor_status(%B, %B, %B, %B)" m1 m2 m3 m4 + | Control_error(e1, e2) -> + sprintf + "Control_error(%d, %d)" + e1 e2 | Motor_move(dist, speed, acc) -> sprintf "Motor_move(%f, %f, %f)" @@ -164,6 +170,10 @@ let to_string = function sprintf "Motor_bezier_limits(%f, %f, %f)" v_max a_tan_max a_rad_max + | Motor_command(motor_id, speed) -> + sprintf + "Motor_command(%d, %d)" + motor_id speed | Odometry(x, y, theta) -> sprintf "Odometry(%f, %f, %f)" @@ -256,6 +266,16 @@ let encode = function ~remote:false ~format:F29bits ~data + | Control_error(e1, e2) -> + let data = String.create 2 in + put_uint8 data 0 e1; + put_uint8 data 1 e2; + frame + ~identifier:106 + ~kind:Data + ~remote:false + ~format:F29bits + ~data | Odometry(x, y, theta) -> let data = String.create 6 in put_sint16 data 0 (truncate (x *. 1000.)); @@ -315,6 +335,16 @@ let encode = function ~remote:false ~format:F29bits ~data:(encode_bezier (x, y, d1, d2, theta, v)) + | Motor_command(motor_id, speed) -> + let data = String.create 5 in + put_uint8 data 0 motor_id; + put_sint32 data 1 speed; + frame + ~identifier:208 + ~kind:Data + ~remote:false + ~format:F29bits + ~data | Set_odometry(x, y, theta) -> let data = String.create 6 in put_sint16 data 0 (truncate (x *. 1000.)); @@ -595,6 +625,10 @@ let decode frame = float (get_sint16 frame.data 4) /. 10000., get_uint8 frame.data 6, get_uint8 frame.data 7 <> 0) + | 106 -> + Control_error + (get_uint8 frame.data 0, + get_uint8 frame.data 1) | 201 -> Motor_move (float (get_sint32 frame.data 0) /. 1000., @@ -630,6 +664,10 @@ let decode frame = (float (get_uint16 frame.data 0) /. 1000., float (get_uint16 frame.data 2) /. 1000., float (get_uint16 frame.data 4) /. 1000.) + | 208 -> + Motor_command + (get_uint8 frame.data 0, + get_sint32 frame.data 1) | 231 -> Elevator(get_float32 frame.data 0, get_float32 frame.data 4) @@ -641,7 +679,7 @@ let decode frame = | 302 -> Beacon_lowlevel_position (float (get_uint16 frame.data 0), - float (get_uint16 frame.data 2) /. 10000., + float (get_uint16 frame.data 2) (*/. 10000*), get_uint32 frame.data 4) | 311 -> Switch1_status diff --git a/info/control2011/src/lib/krobot_message.mli b/info/control2011/src/lib/krobot_message.mli index 752e937..4d79d4d 100644 --- a/info/control2011/src/lib/krobot_message.mli +++ b/info/control2011/src/lib/krobot_message.mli @@ -55,6 +55,8 @@ type t = (** The position and speed of encoder 3. *) | Encoder_position_speed_4 of float * float (** The position and speed of encoder 4. *) + | Control_error of int * int + (** Errors generated by a motor controller card. *) | Motor_status of bool * bool * bool * bool (** Status of the 4 motors. *) | Motor_move of float * float * float @@ -73,6 +75,8 @@ type t = *) | Motor_bezier of float * float * float * float * float * float (** [Motor_bezier(x_end, y_end, d1, d2, theta_end, v_end)] *) + | Motor_command of int * int + (** [Motor_command(motor_id, PWM_value)] *) | Motor_stop of float * float (** [Motor_stop(lin_acc, rot_acc)] command to stop following the current Bezier Spline and the queued ones. hooks/post-receive -- krobot |
From: Pierre C. <Ba...@us...> - 2012-05-15 15:35:24
|
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 a66675c38188c8ce812898d3d4865d53294c7be6 (commit) via ea47bc225093a0f6c9c0534c4177d74036f11966 (commit) from 387e765be280cde4559fa39b47ae6650e728b813 (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 a66675c38188c8ce812898d3d4865d53294c7be6 Author: chicco <cha...@cr...> Date: Tue May 15 17:34:06 2012 +0200 [control] krobot_vm set the led according to the team, some packets doc commit ea47bc225093a0f6c9c0534c4177d74036f11966 Author: chicco <cha...@cr...> Date: Tue May 15 15:45:55 2012 +0200 [krobot_viewer] reduce line size ----------------------------------------------------------------------- Changes: diff --git a/info/control2011/src/lib/krobot_message.mli b/info/control2011/src/lib/krobot_message.mli index a071772..752e937 100644 --- a/info/control2011/src/lib/krobot_message.mli +++ b/info/control2011/src/lib/krobot_message.mli @@ -23,11 +23,18 @@ type t = | Beacon_lowlevel_position of float * float * int (** The position of the beacon as internally stored (for calibration) *) | Switch1_status of bool * bool * bool * bool * bool * bool * bool * bool - (** The status of the first 8 switches *) + (** The status of the first 8 switches + 1 : start + 2 : team + 3 : emergency stop *) | Switch2_status of bool * bool * bool * bool * bool * bool * bool * bool (** The status of the other 8 switches *) | Switch_request of int * bool - (** A request to switch something on/off *) + (** A request to switch something on/off + 4 : buzzer + 5 : yellow led + 6 : red led + 7 : green led *) | Adc1_values of int * int * int * int (** The values of the first 4 ADCs *) | Adc2_values of int * int * int * int diff --git a/info/control2011/src/tools/krobot_viewer.ml b/info/control2011/src/tools/krobot_viewer.ml index 92af2d6..c7453b7 100644 --- a/info/control2011/src/tools/krobot_viewer.ml +++ b/info/control2011/src/tools/krobot_viewer.ml @@ -78,11 +78,11 @@ let set_color ctx color = let r, g, b = match color with | Black -> (0., 0., 0.) | White -> (255., 255., 255.) - | Green -> (36., 145., 64.) - | Red -> (199., 23., 18.) - | Blue -> (0., 59., 128.) - | Yellow -> (252., 189., 31.) - | Purple -> (128., 0., 128.) + | Green -> (36., 200., 64.) + | Red -> (220., 23., 18.) + | Blue -> (20., 80., 170.) + | Yellow -> (232., 232., 0.) + | Purple -> (180., 0., 128.) | Brown -> (175., 89., 67.) in Cairo.set_source_rgb ctx (r /. 255.) (g /. 255.) (b /. 255.) @@ -124,21 +124,27 @@ let draw viewer = (* Draw beacon supports *) Cairo.rectangle ctx (-0.102) (-0.102) 0.08 0.08; + set_color ctx Purple; Cairo.fill ctx; Cairo.rectangle ctx (-0.102) (world_height /. 2. -. 0.04) 0.08 0.08; + set_color ctx Red; Cairo.fill ctx; Cairo.rectangle ctx (-0.102) (world_height +. 0.022) 0.08 0.08; + set_color ctx Purple; Cairo.fill ctx; Cairo.rectangle ctx (world_width +. 0.022) (-0.102) 0.08 0.08; + set_color ctx Red; Cairo.fill ctx; Cairo.rectangle ctx (world_width +. 0.022) (world_height /. 2. -. 0.04) 0.08 0.08; + set_color ctx Purple; Cairo.fill ctx; Cairo.rectangle ctx (world_width +. 0.022) (world_height +. 0.022) 0.08 0.08; + set_color ctx Red; Cairo.fill ctx; (* Draw the viewer background *) @@ -169,6 +175,7 @@ let draw viewer = set_color ctx Black; Cairo.set_line_width ctx (5. /. scale); Cairo.stroke ctx; + Cairo.set_line_width ctx (1. /. scale); (* draw the homes *) Cairo.move_to ctx 0. 0.; @@ -228,6 +235,30 @@ let draw viewer = set_color ctx Green; Cairo.fill ctx; + Cairo.rectangle ctx (0.64 +. 0.477 -. 0.125) (1. -. 0.125) 0.25 0.25; + set_color ctx Brown; + Cairo.fill ctx; + + Cairo.rectangle ctx (world_width -. (0.64 +. 0.477 +. 0.125)) (1. -. 0.125) 0.25 0.25; + set_color ctx Brown; + Cairo.fill ctx; + + Cairo.rectangle ctx 0.54 (-.0.1) 0.2 0.1; + set_color ctx Purple; + Cairo.fill ctx; + + Cairo.rectangle ctx (0.54 +. 0.47) (-.0.1) 0.2 0.1; + set_color ctx Red; + Cairo.fill ctx; + + Cairo.rectangle ctx (world_width -. 0.74) (-.0.1) 0.2 0.1; + set_color ctx Red; + Cairo.fill ctx; + + Cairo.rectangle ctx (world_width -. (0.74 +. 0.47)) (-.0.1) 0.2 0.1; + set_color ctx Purple; + Cairo.fill ctx; + (* Draw objects *) List.iter (fun { x; y } -> diff --git a/info/control2011/src/tools/krobot_vm.ml b/info/control2011/src/tools/krobot_vm.ml index 9a67034..32d541a 100644 --- a/info/control2011/src/tools/krobot_vm.ml +++ b/info/control2011/src/tools/krobot_vm.ml @@ -79,6 +79,9 @@ type robot = { mutable team : [ `Red | `Blue ]; (* The state of the team selector. *) + mutable emergency_stop : bool; + (* The state of the emergency button. *) + ax12_front_low_left : ax12; ax12_front_low_right : ax12; ax12_front_high_left : ax12; @@ -94,6 +97,20 @@ type robot = { | Message handling | +-----------------------------------------------------------------+ *) +let update_team_led robot = + let m1,m2 = + if robot.team = `Red then + Switch_request(6,true), Switch_request(7,false) + else + Switch_request(6,false), Switch_request(7,true) + in + lwt () = Krobot_message.send robot.bus (Unix.gettimeofday (),m1) in + Krobot_message.send robot.bus (Unix.gettimeofday (), m2) + +let clear_team_led robot = + lwt () = Krobot_message.send robot.bus (Unix.gettimeofday (), Switch_request(6,false)) in + Krobot_message.send robot.bus (Unix.gettimeofday (), Switch_request(7,false)) + let handle_message robot (timestamp, message) = match message with | CAN(_, frame) -> begin @@ -118,8 +135,11 @@ let handle_message robot (timestamp, message) = end else robot.beacon <- None - | Switch1_status(b, _, _, _, _, _, _, _) -> - robot.jack <- not b + | Switch1_status(jack, team, emergency, _, _, _, _, _) -> + robot.jack <- not jack; + robot.team <- if team then `Red else `Blue; + robot.emergency_stop <- emergency; + ignore (update_team_led robot) | Ax12_State(id, position, speed, torque) -> begin let set ax12 = @@ -481,6 +501,7 @@ lwt () = beacon = None; date_seen_beacon = 0.; team = `Red; + emergency_stop = false; 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 }; @@ -491,6 +512,8 @@ lwt () = ax12_back_high_right = { ax12_position = 0; ax12_speed = 0; ax12_torque = 0 }; } in + lwt () = clear_team_led robot in + (* Handle krobot message. *) E.keep (E.map (handle_message robot) (Krobot_bus.recv bus)); hooks/post-receive -- krobot |
From: Xavier L. <Ba...@us...> - 2012-05-15 14:47:24
|
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 387e765be280cde4559fa39b47ae6650e728b813 (commit) from 03e4d8dbf2a8a7216d261348799c2b9b6474ad74 (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 387e765be280cde4559fa39b47ae6650e728b813 Author: Xavier Lagorce <Xav...@cr...> Date: Tue May 15 16:45:13 2012 +0200 [Controller_Motor_STM32] Bug fixes and detection ----------------------------------------------------------------------- Changes: diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/lib/differential_drive.c b/elec/boards/Controller_Motor_STM32/Firmwares/lib/differential_drive.c index 01fa1d2..487ae75 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/lib/differential_drive.c +++ b/elec/boards/Controller_Motor_STM32/Firmwares/lib/differential_drive.c @@ -148,8 +148,10 @@ static void NORETURN traj_following_process(void) { u2=w2*powf(cosf(rs.theta-params.ghost_state.theta),2)+v_rot; // Apply command - dd_set_linear_speed(u1, 0.); - dd_set_rotational_speed(u2, 0.); + if (params.working) { + dd_set_linear_speed(u1, 0.); + dd_set_rotational_speed(u2, 0.); + } // Keep current time last_time = cur_time; diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/lib/motor_controller.c b/elec/boards/Controller_Motor_STM32/Firmwares/lib/motor_controller.c index 6caa48f..2c2ae81 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/lib/motor_controller.c +++ b/elec/boards/Controller_Motor_STM32/Firmwares/lib/motor_controller.c @@ -209,7 +209,12 @@ static void NORETURN motorController_process(void) { params->last_encoder_pos = encoder_pos; // Apply command - motorSetSpeed(params->motor, (int32_t)params->last_command); + if (isnan(params->last_command)) { + motorSetSpeed(params->motor, 0); + motor_led_on(params->motor); + } else { + motorSetSpeed(params->motor, (int32_t)params->last_command); + } } timer_waitEvent(&timer); // Wait for the remaining of the sample period } hooks/post-receive -- krobot |
From: Olivier B. <Ba...@us...> - 2012-05-15 13:42:30
|
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 03e4d8dbf2a8a7216d261348799c2b9b6474ad74 (commit) from bc94b6c746f8ff33a7d448ed453ed0619713d639 (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 03e4d8dbf2a8a7216d261348799c2b9b6474ad74 Author: Olivier BICHLER <oli...@gm...> Date: Tue May 15 15:40:41 2012 +0200 Bug in get_battery_monitoring() ----------------------------------------------------------------------- Changes: diff --git a/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/sensor_actuator/battery_monitoring/battery_monitoring.c b/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/sensor_actuator/battery_monitoring/battery_monitoring.c index f82f81f..8fc7d4c 100644 --- a/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/sensor_actuator/battery_monitoring/battery_monitoring.c +++ b/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/sensor_actuator/battery_monitoring/battery_monitoring.c @@ -39,7 +39,7 @@ int get_battery_monitoring(battery_status *pkt1, battery_status *pkt2) { // Battery 2 for (ch = 0; ch < 4; ++ch) - pkt2->p.elem[ch] = battery_state[ch]; + pkt2->p.elem[ch] = battery_state[4+ch]; measure_flag = 0; return 0; hooks/post-receive -- krobot |
From: Xavier L. <Ba...@us...> - 2012-05-15 13:27:16
|
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 bc94b6c746f8ff33a7d448ed453ed0619713d639 (commit) from 9e5759cec52e0fc9ec2c9aeaed62ef57bfdf6163 (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 bc94b6c746f8ff33a7d448ed453ed0619713d639 Author: Xavier Lagorce <Xav...@cr...> Date: Tue May 15 15:26:35 2012 +0200 [Controller_Motor_STM32] Added can message to specify speed of a motor ----------------------------------------------------------------------- Changes: diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/can_messages.h b/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/can_messages.h index 1226a2b..aa5c8b1 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/can_messages.h +++ b/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/can_messages.h @@ -32,6 +32,7 @@ #define CAN_MSG_CONTROLLER_MODE 205 // controller_mode_can_msg_t #define CAN_MSG_BEZIER_ADD 206 // bezier_can_msg_t #define CAN_MSG_BEZIER_LIMITS 207 // bezier_limits_can_msg_t +#define CAN_MSG_MOTOR_COMMAND 208 // motor_command_can_msg_t /* +-----------------------------------------------------------------+ | CAN messages data structures | @@ -115,6 +116,11 @@ typedef struct { uint8_t mode; } controller_mode_msg_t; +// Command the speed of a particular motor +typedef struct { + uint8_t motor_id; + int32_t speed; +} motor_command_msg_t; /* +-----------------------------------------------------------------+ | CAN messages unions for data representation | @@ -175,5 +181,9 @@ typedef union { uint32_t data32[2]; } controller_mode_can_msg_t; +typedef union { + motor_command_msg_t data; + uint32_t data32[2]; +} motor_command_can_msg_t; #endif /* __CAN_MESSAGES_H */ diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/can_monitor.c b/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/can_monitor.c index f41d686..bae2706 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/can_monitor.c +++ b/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/can_monitor.c @@ -155,6 +155,7 @@ static void NORETURN canMonitorListen_process(void) { controller_mode_can_msg_t controller_mode_msg; bezier_can_msg_t bezier_msg; bezier_limits_can_msg_t bezier_limits_msg; + motor_command_can_msg_t motor_command_msg; // Initialize constant parameters of TX frame txm.dlc = 8; @@ -239,6 +240,12 @@ static void NORETURN canMonitorListen_process(void) { mode = ROBOT_MODE_NORMAL; } break; + case CAN_MSG_MOTOR_COMMAND: + motor_command_msg.data32[0] = frame.data32[0]; + motor_command_msg.data32[1] = frame.data32[1]; + motorSetSpeed(motor_command_msg.data.motor_id, + motor_command_msg.data.speed); + break; } } } diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/main.c b/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/main.c index 0f69fc0..48846a3 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/main.c +++ b/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/main.c @@ -96,9 +96,6 @@ static void init(void) LED4_OFF(); timer_delay(100); } - - // Start Beacon motor - //motorSetSpeed(MOTOR2, 1100); } static void NORETURN ind_process(void) hooks/post-receive -- krobot |
From: Xavier L. <Ba...@us...> - 2012-05-15 12:22: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 9e5759cec52e0fc9ec2c9aeaed62ef57bfdf6163 (commit) via 5bde23dedda3f4fb95d49065eabc207807928e41 (commit) via 5831326246b4e1e880010f94cc920c4f13bf0b68 (commit) from 7e52949ac9a86441f90a1066ffa97cab74d46bc8 (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 9e5759cec52e0fc9ec2c9aeaed62ef57bfdf6163 Author: Xavier Lagorce <Xav...@cr...> Date: Tue May 15 14:21:10 2012 +0200 [Controller_Motor_STM32] Keep the repo up to date : * Added CAN messages to limit speed and acceleration of bezier following * Corrected a bug in encoder wrapping detection * Allow more than one odometry process * New control parameters for 2012 robot commit 5bde23dedda3f4fb95d49065eabc207807928e41 Author: Xavier Lagorce <Xav...@cr...> Date: Tue May 15 14:11:46 2012 +0200 [Controller_Motor_STM32] Update jtag flash script commit 5831326246b4e1e880010f94cc920c4f13bf0b68 Author: Xavier Lagorce <Xav...@cr...> Date: Tue May 15 14:10:58 2012 +0200 Add ocaml bytecode to .gitignore ----------------------------------------------------------------------- Changes: diff --git a/.gitignore b/.gitignore index 263aa3c..10f9f01 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ *.dmp *.hex *.o.d +*.byte setup.data setup.log _build diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/can_messages.h b/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/can_messages.h index 81a44c2..1226a2b 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/can_messages.h +++ b/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/can_messages.h @@ -31,6 +31,7 @@ #define CAN_MSG_STOP 204 // stop_can_msg_t #define CAN_MSG_CONTROLLER_MODE 205 // controller_mode_can_msg_t #define CAN_MSG_BEZIER_ADD 206 // bezier_can_msg_t +#define CAN_MSG_BEZIER_LIMITS 207 // bezier_limits_can_msg_t /* +-----------------------------------------------------------------+ | CAN messages data structures | @@ -96,6 +97,13 @@ typedef struct { uint16_t v_end:11 __attribute__((__packed__)); // final speed in mm/s } bezier_msg_t; +// Modify Bezier Spline trajectory generation limits +typedef struct { + uint16_t v_max __attribute__((__packed__)); // max linear speed in mm/s + uint16_t at_max __attribute__((__packed__)); // max linear acceleration in mm/s/s + uint16_t ar_max __attribute__((__packed__)); // max radial acceleration in mm/s/s +} bezier_limits_msg_t; + // Stop Bezier Spline following and brakes typedef struct { float lin_acc __attribute__((__packed__)); // Linear acceleration for braking @@ -153,6 +161,11 @@ typedef union { } bezier_can_msg_t; typedef union { + bezier_limits_msg_t data; + uint32_t data32[2]; +} bezier_limits_can_msg_t; + +typedef union { stop_msg_t data; uint32_t data32[2]; } stop_can_msg_t; diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/can_monitor.c b/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/can_monitor.c index 8c3793d..f41d686 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/can_monitor.c +++ b/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/can_monitor.c @@ -13,6 +13,8 @@ #define ROBOT_MODE_NORMAL 0 #define ROBOT_MODE_HIL 1 +#define CONTROL_ODOMETRY 0 + // Processes stacks PROC_DEFINE_STACK(stack_can_send, KERN_MINSTACKSIZE * 8); PROC_DEFINE_STACK(stack_can_receive, KERN_MINSTACKSIZE * 8); @@ -79,7 +81,7 @@ static void NORETURN canMonitor_process(void) { // Sending odometry data if not in HIL mode or motor commands if in HIL mode if (mode != ROBOT_MODE_HIL) { - odo_getState(&odometry); + odo_getState(CONTROL_ODOMETRY, &odometry); msg_odo.data.x = (int16_t)(odometry.x * 1000.0); msg_odo.data.y = (int16_t)(odometry.y * 1000.0); odometry.theta = fmodf(odometry.theta, 2*M_PI); @@ -152,6 +154,7 @@ static void NORETURN canMonitorListen_process(void) { stop_can_msg_t stop_msg; controller_mode_can_msg_t controller_mode_msg; bezier_can_msg_t bezier_msg; + bezier_limits_can_msg_t bezier_limits_msg; // Initialize constant parameters of TX frame txm.dlc = 8; @@ -190,6 +193,13 @@ static void NORETURN canMonitorListen_process(void) { bezier_msg.data.d1/100.0, bezier_msg.data.d2/100.0, bezier_msg.data.theta_end/100.0, bezier_msg.data.v_end/1000.0); break; + case CAN_MSG_BEZIER_LIMITS: + bezier_limits_msg.data32[0] = frame.data32[0]; + bezier_limits_msg.data32[1] = frame.data32[1]; + dd_adjust_limits(bezier_limits_msg.data.v_max/1000.0, + bezier_limits_msg.data.at_max/1000.0, + bezier_limits_msg.data.ar_max/1000.0); + break; case CAN_MSG_STOP: stop_msg.data32[0] = frame.data32[0]; stop_msg.data32[1] = frame.data32[1]; @@ -201,7 +211,7 @@ static void NORETURN canMonitorListen_process(void) { odometry.x = ((float)odometry_msg.data.x) / 1000.0; odometry.y = ((float)odometry_msg.data.y) / 1000.0; odometry.theta = ((float)odometry_msg.data.theta) / 10000.0; - odo_setState(&odometry); + odo_setState(CONTROL_ODOMETRY, &odometry); break; case CAN_MSG_ODOMETRY: // We should only receive such message in HIL mode @@ -211,7 +221,7 @@ static void NORETURN canMonitorListen_process(void) { odometry.x = ((float)odometry_msg.data.x) / 1000.0; odometry.y = ((float)odometry_msg.data.y) / 1000.0; odometry.theta = ((float)odometry_msg.data.theta) / 10000.0; - odo_setState(&odometry); + odo_setState(CONTROL_ODOMETRY, &odometry); } break; case CAN_MSG_CONTROLLER_MODE: @@ -220,12 +230,12 @@ static void NORETURN canMonitorListen_process(void) { if (controller_mode_msg.data.mode == 1) { mc_change_mode(MOTOR3, CONTROLLER_MODE_HIL); mc_change_mode(MOTOR4, CONTROLLER_MODE_HIL); - odo_disable(); + odo_disable(CONTROL_ODOMETRY); mode = ROBOT_MODE_HIL; } else { mc_change_mode(MOTOR3, CONTROLLER_MODE_NORMAL); mc_change_mode(MOTOR4, CONTROLLER_MODE_NORMAL); - odo_restart(); + odo_restart(CONTROL_ODOMETRY); mode = ROBOT_MODE_NORMAL; } break; diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/main.c b/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/main.c index b52b689..0f69fc0 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/main.c +++ b/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/main.c @@ -18,10 +18,9 @@ #include "differential_drive.h" #define WHEEL_RADIUS 0.049245 -#define SHAFT_WIDTH 0.14320 +#define SHAFT_WIDTH 0.224 -//#define WHEEL_RADIUS 0.0325 -//#define SHAFT_WIDTH 0.255 +#define CONTROL_ODOMETRY 0 PROC_DEFINE_STACK(stack_ind, KERN_MINSTACKSIZE * 2); @@ -50,7 +49,8 @@ static void init(void) // Start control of drive motors tc_init(); - dd_start(WHEEL_RADIUS, SHAFT_WIDTH, // Structural parameters + dd_start(CONTROL_ODOMETRY, // Use odometry CONTROL_ODOMETRY for control + WHEEL_RADIUS, SHAFT_WIDTH, // Structural parameters 8*2*M_PI, // Absolute wheel speed limitation 0.5, // Linear velocity limitation 1.0, // Linear acceleration limitation @@ -58,34 +58,30 @@ static void init(void) 0.4, 0.7, 1.0, // Controller gains 0.005); // Sample period // Common parameters - params.encoder_gain = -2.0*M_PI/2000.0/15; + params.encoder_gain = 2.0*M_PI/2000.0/15; params.T = 0.005; - // Initialize right motor - params.G0 = 0.0146; - params.tau = 0.120; - params.k[0] = -2139.6; - params.k[1] = -193.9178; - params.l = -params.k[0]; - params.l0[0] = 0.0408; - params.l0[1] = 0; - params.motor = MOTOR4; - params.encoder = ENCODER4; - mc_new_controller(¶ms, dd_get_right_wheel_generator(), CONTROLLER_MODE_NORMAL); // Initialize left motor - params.G0 = 0.0146; - params.tau = 0.266; - params.k[0] = -4689.1; - params.k[1] = -506.4099; + params.G0 = 0.011686; + params.tau = 0.118; + params.k[0] = -3735.7; + params.k[1] = -297.5867; params.l = -params.k[0]; - params.l0[0] = 0.0630; - params.l0[1] = 0.0994; + params.l0[0] = 0.0561; + params.l0[1] = 0.0108; params.motor = MOTOR3; params.encoder = ENCODER3; - params.encoder_gain = 2.0*M_PI/2000.0/15; // Left motor is reversed mc_new_controller(¶ms, dd_get_left_wheel_generator(), CONTROLLER_MODE_NORMAL); + // Initialize right motor + params.motor = MOTOR4; + params.encoder = ENCODER4; + params.encoder_gain = -2.0*M_PI/2000.0/15; // Left motor is reversed + mc_new_controller(¶ms, dd_get_right_wheel_generator(), CONTROLLER_MODE_NORMAL); // Start odometry - odometryInit(1e-3, WHEEL_RADIUS, SHAFT_WIDTH, 2.0*M_PI/2000.0/15, -2.0*M_PI/2000.0/15); + odometryInit(CONTROL_ODOMETRY, 1e-3, WHEEL_RADIUS, SHAFT_WIDTH, 2.0*M_PI/2000.0/15, -2.0*M_PI/2000.0/15); + + // Init beacon motor + enableMotor(MOTOR2); // Blink to say we are ready for (uint8_t i=0; i < 5; i++) { @@ -100,6 +96,9 @@ static void init(void) LED4_OFF(); timer_delay(100); } + + // Start Beacon motor + //motorSetSpeed(MOTOR2, 1100); } static void NORETURN ind_process(void) diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/jtag/flash.cfg b/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/jtag/flash.cfg index 2721d3e..b1c2352 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/jtag/flash.cfg +++ b/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/jtag/flash.cfg @@ -1,7 +1,7 @@ init reset halt -stm32x mass_erase 0 +stm32f1x mass_erase 0 flash write_bank 0 fw.bin 0 reset init reset run -shutdown \ No newline at end of file +shutdown diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/jtag/openocd.cfg b/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/jtag/openocd.cfg index d6a58e9..0e09b2b 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/jtag/openocd.cfg +++ b/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/jtag/openocd.cfg @@ -77,7 +77,7 @@ target create $_TARGETNAME cortex_m3 -endian $_ENDIAN -chain-position $_TARGETNA $_TARGETNAME configure -work-area-phys 0x20000000 -work-area-size $_WORKAREASIZE -work-area-backup 0 set _FLASHNAME $_CHIPNAME.flash -flash bank $_FLASHNAME stm32x 0 0 0 0 $_TARGETNAME +flash bank $_FLASHNAME stm32f1x 0 0 0 0 $_TARGETNAME # For more information about the configuration files, take a look at: # openocd.texi diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/lib/differential_drive.c b/elec/boards/Controller_Motor_STM32/Firmwares/lib/differential_drive.c index b566a84..01fa1d2 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/lib/differential_drive.c +++ b/elec/boards/Controller_Motor_STM32/Firmwares/lib/differential_drive.c @@ -25,6 +25,7 @@ typedef struct { typedef struct { uint8_t initialized, enabled, running, working; + uint8_t odometry_process; float wheel_radius, shaft_width; float last_lin_acceleration, last_rot_acceleration; float u, v_max, at_max, ar_max; @@ -80,7 +81,7 @@ static void NORETURN traj_following_process(void) { } timer_add(&timer); if (params.working) { - odo_getState(&rs); + odo_getState(params.odometry_process, &rs); // Stop following the trajectory if we are close enough to our goal if (params.u >= 1.0 || ((rs.x-traj->goal[0]) * (rs.x-traj->goal[0]) + (rs.y-traj->goal[1]) * (rs.y-traj->goal[1])) <= (0.01*0.01)) { @@ -123,12 +124,15 @@ static void NORETURN traj_following_process(void) { dxu = bezier_apply(traj->dparams[0], params.u); dyu = bezier_apply(traj->dparams[1], params.u); params.u += traj->v_lin/sqrtf(dxu*dxu+dyu*dyu)*dt; - params.ghost_state.x += traj->v_lin*cosf(params.ghost_state.theta)*dt; - params.ghost_state.y += traj->v_lin*sinf(params.ghost_state.theta)*dt; - params.ghost_state.theta = fmodf(params.ghost_state.theta + v_rot*dt, 2*M_PI); + //params.ghost_state.x += traj->v_lin*cosf(params.ghost_state.theta)*dt; + //params.ghost_state.y += traj->v_lin*sinf(params.ghost_state.theta)*dt; + //params.ghost_state.theta = fmodf(params.ghost_state.theta + v_rot*dt, 2*M_PI); + params.ghost_state.x = bezier_apply(traj->params[0],params.u); + params.ghost_state.y = bezier_apply(traj->params[1],params.u); + params.ghost_state.theta = atan2f(dyu,dxu); if (params.ghost_state.theta > M_PI) { params.ghost_state.theta -= 2*M_PI; - } else if (params.ghost_state.theta <= M_PI) { + } else if (params.ghost_state.theta <= -M_PI) { params.ghost_state.theta += 2*M_PI; } @@ -156,9 +160,11 @@ static void NORETURN traj_following_process(void) { } } -void dd_start(float wheel_radius, float shaft_width, float max_wheel_speed, +void dd_start(uint8_t odometry_process, + float wheel_radius, float shaft_width, float max_wheel_speed, float v_max, float at_max, float ar_max, float k1, float k2, float k3, float Ts) { + params.odometry_process = odometry_process; params.wheel_radius = wheel_radius; params.shaft_width = shaft_width; params.last_lin_acceleration = 0.0; @@ -307,7 +313,7 @@ uint8_t dd_add_bezier(float x_end, float y_end, float d1, float d2, float end_an y_ini = params.trajs[params.current_traj].goal[1]; theta_ini = params.trajs[params.current_traj].theta_end; } else { - odo_getState(&rs); + odo_getState(params.odometry_process, &rs); x_ini = rs.x; y_ini = rs.y; theta_ini = rs.theta; @@ -357,6 +363,12 @@ void dd_interrupt_trajectory(float rot_acc, float lin_acc) { dd_set_linear_speed(0., lin_acc); } +void dd_adjust_limits(float v_max, float at_max, float ar_max) { + params.v_max = v_max; + params.at_max = at_max; + params.ar_max = ar_max; +} + uint8_t dd_get_ghost_state(robot_state_t *state, float *u) { if (state != NULL) { state->x = params.ghost_state.x; diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/lib/differential_drive.h b/elec/boards/Controller_Motor_STM32/Firmwares/lib/differential_drive.h index 0a0a0f9..df33321 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/lib/differential_drive.h +++ b/elec/boards/Controller_Motor_STM32/Firmwares/lib/differential_drive.h @@ -31,6 +31,7 @@ #define DD_GHOST_MOVING 1 /* Initializes the differential drive + * - odometry_process : ID of the odometry process to base the control on * - wheel_radius : radius of the wheels (in meters) * - shaft_width : propulsion shaft width (in meters) * - max_wheel_speed : maximum wheel speed (in rad/s) @@ -43,7 +44,8 @@ * Note : the differential drive system will use Trajectory controllers * DD_LINEAR_SPEED_TC and DD_ROTATIONAL_SPEED_TC */ -void dd_start(float wheel_radius, float shaft_width, float max_wheel_speed, +void dd_start(uint8_t odometry_process, + float wheel_radius, float shaft_width, float max_wheel_speed, float v_max, float at_max, float ar_max, float k1, float k2, float k3, float Ts); @@ -104,6 +106,13 @@ uint8_t dd_add_bezier(float x_end, float y_end, float d1, float d2, float end_an */ void dd_interrupt_trajectory(float rot_acc, float lin_acc); +/* Change limitations of the trajectory follower + * - v_max : maximum linear speed (in m/s) + * - at_max : maximum tangential acceleration (in m/s/s) + * - ar_max : maximum radial acceleration (in m/s/s) + */ +void dd_adjust_limits(float v_max, float at_max, float ar_max); + /* * Return the current state of the followed ghost robot * - state : pointer to a robot_state_t structure where the ghost state will be written diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/lib/motor_controller.c b/elec/boards/Controller_Motor_STM32/Firmwares/lib/motor_controller.c index 3bc54e0..6caa48f 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/lib/motor_controller.c +++ b/elec/boards/Controller_Motor_STM32/Firmwares/lib/motor_controller.c @@ -178,12 +178,17 @@ static void NORETURN motorController_process(void) { // Measure motor rotation encoder_pos = (float)getEncoderPosition(params->encoder); delta = encoder_pos - params->last_encoder_pos; - if (getEncoderDirection(params->encoder) == ENCODER_DIR_UP) { + /*if (getEncoderDirection(params->encoder) == ENCODER_DIR_UP) { if (delta < 0) delta = delta + 65535; } else { if (delta > 0) delta = delta - 65535; + }*/ + if (delta > 32767) { + delta = delta - 65535; + } else if (delta < - 32767) { + delta = delta + 65535; } // New state vector estimation diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/lib/odometry.c b/elec/boards/Controller_Motor_STM32/Firmwares/lib/odometry.c index 3c26212..6b33924 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/lib/odometry.c +++ b/elec/boards/Controller_Motor_STM32/Firmwares/lib/odometry.c @@ -9,7 +9,8 @@ #include "odometry.h" -PROC_DEFINE_STACK(stack_odometry, KERN_MINSTACKSIZE * 8); +#define ODOMETRY_STACK_SIZE (KERN_MINSTACKSIZE * 8) +static cpu_stack_t stack_odometry[MAX_ODOMETRY_PROCESSES][(ODOMETRY_STACK_SIZE + sizeof(cpu_stack_t) - 1) / sizeof(cpu_stack_t)]; typedef struct { robot_state_t robot_state; @@ -19,38 +20,38 @@ typedef struct { uint8_t running; } odometry_state_t; -odometry_state_t state; +odometry_state_t state[MAX_ODOMETRY_PROCESSES]; static void NORETURN odometry_process(void); -void odometryInit(float Ts, float wheel_radius, float shaft_width, float left_encoder_gain, float right_encoder_gain) { +void odometryInit(uint8_t process_num, float Ts, float wheel_radius, float shaft_width, float left_encoder_gain, float right_encoder_gain) { // Initialize initial state - state.robot_state.x = 0.; - state.robot_state.y = 0; - state.robot_state.theta = 0; + state[process_num].robot_state.x = 0.; + state[process_num].robot_state.y = 0; + state[process_num].robot_state.theta = 0; // Initialize robot parameters - state.wheel_radius = wheel_radius; - state.shaft_width = shaft_width; - state.left_encoder_gain = left_encoder_gain; - state.right_encoder_gain = right_encoder_gain; - state.Ts = Ts; + state[process_num].wheel_radius = wheel_radius; + state[process_num].shaft_width = shaft_width; + state[process_num].left_encoder_gain = left_encoder_gain; + state[process_num].right_encoder_gain = right_encoder_gain; + state[process_num].Ts = Ts; // Start odometry process - state.enable = 1; - proc_new(odometry_process, NULL, sizeof(stack_odometry), stack_odometry); + state[process_num].enable = 1; + proc_new(odometry_process, (&state[process_num]), sizeof(stack_odometry[process_num]), stack_odometry[process_num]); } -void odo_disable(void) { - state.enable = 0; +void odo_disable(uint8_t process_num) { + state[process_num].enable = 0; } -void odo_restart(void) { +void odo_restart(uint8_t process_num) { // Start odometry process - if (state.enable == 0 && state.running == 0) { - state.enable = 1; - proc_new(odometry_process, NULL, sizeof(stack_odometry), stack_odometry); + if (state[process_num].enable == 0 && state[process_num].running == 0) { + state[process_num].enable = 1; + proc_new(odometry_process, (&state[process_num]), sizeof(stack_odometry[process_num]), stack_odometry[process_num]); } } @@ -58,21 +59,25 @@ static void NORETURN odometry_process(void) { float pos_l, pos_r, last_pos_l, last_pos_r, delta_l, delta_r; uint8_t dir_l, dir_r; Timer timer; + odometry_state_t *state; + + // get data + state = (odometry_state_t *) proc_currentUserData(); // configure timer - timer_setDelay(&timer, ms_to_ticks(1000 * state.Ts)); + timer_setDelay(&timer, ms_to_ticks(1000 * state->Ts)); timer_setEvent(&timer); // Indicate we are running - state.running = 1; + state->running = 1; // State initialization last_pos_l = (float)getEncoderPosition(ENCODER3); last_pos_r = (float)getEncoderPosition(ENCODER4); while (1) { - if (state.enable == 0) { - state.running = 0; + if (state->enable == 0) { + state->running = 0; proc_exit(); } else { timer_add(&timer); @@ -82,7 +87,17 @@ static void NORETURN odometry_process(void) { pos_r = (float)getEncoderPosition(ENCODER4); dir_r = getEncoderDirection(ENCODER4); delta_l = pos_l - last_pos_l; delta_r = pos_r - last_pos_r; - if (dir_l == ENCODER_DIR_UP) { + if (delta_l > 32767) { + delta_l = delta_l - 65535; + } else if (delta_l < - 32767) { + delta_l = delta_l + 65535; + } + if (delta_r > 32767) { + delta_r = delta_r - 65535; + } else if (delta_r < - 32767) { + delta_r = delta_r + 65535; + } + /*if (dir_l == ENCODER_DIR_UP) { if (delta_l < 0) delta_l = delta_l + 65535; } else { @@ -95,37 +110,37 @@ static void NORETURN odometry_process(void) { } else { if (delta_r > 0) delta_r = delta_r - 65535; - } - delta_l *= state.left_encoder_gain; - delta_r *= state.right_encoder_gain; + }*/ + delta_l *= state->left_encoder_gain; + delta_r *= state->right_encoder_gain; last_pos_l = pos_l; last_pos_r = pos_r; // New state computation - state.robot_state.x += state.wheel_radius * (delta_r + delta_l) / 2.0 * cos(state.robot_state.theta); - state.robot_state.y += state.wheel_radius * (delta_r + delta_l) / 2.0 * sin(state.robot_state.theta); - state.robot_state.theta += state.wheel_radius / state.shaft_width * (delta_r - delta_l); + state->robot_state.x += state->wheel_radius * (delta_r + delta_l) / 2.0 * cos(state->robot_state.theta); + state->robot_state.y += state->wheel_radius * (delta_r + delta_l) / 2.0 * sin(state->robot_state.theta); + state->robot_state.theta += state->wheel_radius / state->shaft_width * (delta_r - delta_l); // Normalization of theta - if (state.robot_state.theta > M_PI) { - state.robot_state.theta -= 2*M_PI; - } else if (state.robot_state.theta < -M_PI) { - state.robot_state.theta += 2*M_PI; + if (state->robot_state.theta > M_PI) { + state->robot_state.theta -= 2*M_PI; + } else if (state->robot_state.theta < -M_PI) { + state->robot_state.theta += 2*M_PI; } } timer_waitEvent(&timer); // Wait for the remaining of the sample period } } -void odo_setState(robot_state_t *new_state) { - state.robot_state.x = new_state->x; - state.robot_state.y = new_state->y; - state.robot_state.theta = new_state->theta; +void odo_setState(uint8_t process_num, robot_state_t *new_state) { + state[process_num].robot_state.x = new_state->x; + state[process_num].robot_state.y = new_state->y; + state[process_num].robot_state.theta = new_state->theta; } -void odo_getState(robot_state_t *robot_state) { - robot_state->x = state.robot_state.x; - robot_state->y = state.robot_state.y; - robot_state->theta = state.robot_state.theta; +void odo_getState(uint8_t process_num, robot_state_t *robot_state) { + robot_state->x = state[process_num].robot_state.x; + robot_state->y = state[process_num].robot_state.y; + robot_state->theta = state[process_num].robot_state.theta; } diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/lib/odometry.h b/elec/boards/Controller_Motor_STM32/Firmwares/lib/odometry.h index 2d378a0..cac8c83 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/lib/odometry.h +++ b/elec/boards/Controller_Motor_STM32/Firmwares/lib/odometry.h @@ -14,18 +14,20 @@ #include <drv/timer.h> #include "encoder.h" +#define MAX_ODOMETRY_PROCESSES 2 + typedef struct { float x; float y; float theta; } robot_state_t; -void odometryInit(float Ts, float wheel_radius, float shaft_width, float left_encoder_gain, float right_encoder_gain); -void odo_disable(void); -void odo_restart(void); +void odometryInit(uint8_t process_num, float Ts, float wheel_radius, float shaft_width, float left_encoder_gain, float right_encoder_gain); +void odo_disable(uint8_t process_num); +void odo_restart(uint8_t process_num); -void odo_setState(robot_state_t *new_state); +void odo_setState(uint8_t process_num, robot_state_t *new_state); -void odo_getState(robot_state_t *robot_state); +void odo_getState(uint8_t process_num, robot_state_t *robot_state); #endif /* __ODOMETRY_H */ hooks/post-receive -- krobot |
From: Xavier L. <Ba...@us...> - 2012-05-15 11:54:30
|
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 7e52949ac9a86441f90a1066ffa97cab74d46bc8 (commit) from 73a9d3f6a300ae96cc23d523d57126f1885c1fbc (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 7e52949ac9a86441f90a1066ffa97cab74d46bc8 Author: Xavier Lagorce <Xav...@cr...> Date: Tue May 15 13:53:59 2012 +0200 [Sensor_actuator] jtag flashing script ----------------------------------------------------------------------- Changes: diff --git a/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/jtag/flash.cfg b/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/jtag/flash.cfg new file mode 100644 index 0000000..da25c23 --- /dev/null +++ b/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/jtag/flash.cfg @@ -0,0 +1,8 @@ +jtag_khz 1000 +init +reset halt +stm32f1x mass_erase 0 +flash write_bank 0 fw.bin 0 +reset init +reset run +shutdown diff --git a/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/jtag/flash.mk b/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/jtag/flash.mk new file mode 100644 index 0000000..a2a35bb --- /dev/null +++ b/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/jtag/flash.mk @@ -0,0 +1,8 @@ +# rule to flash the firmware + +flash: size + @cp $(BUILDDIR)/$(PROJECT).bin jtag/fw.bin + @cd jtag; openocd -f openocd.cfg -f flash.cfg + @rm jtag/fw.bin + +# *** EOF *** diff --git a/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/jtag/flash.sh b/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/jtag/flash.sh new file mode 100755 index 0000000..aacb0a8 --- /dev/null +++ b/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/jtag/flash.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +file=images/*.bin +cp $file jtag/fw.bin +cd jtag +openocd -f openocd.cfg -f flash.cfg +rm -f fw.bin + diff --git a/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/jtag/openocd.cfg b/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/jtag/openocd.cfg new file mode 100644 index 0000000..0e09b2b --- /dev/null +++ b/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/jtag/openocd.cfg @@ -0,0 +1,84 @@ +# +# Olimex ARM-USB-OCD +# +# http://www.olimex.com/dev/arm-usb-ocd.html +# + +interface ft2232 +ft2232_device_desc "Olimex OpenOCD JTAG" +ft2232_layout olimex-jtag +ft2232_vid_pid 0x15ba 0x0003 + +# script for stm32 + +if { [info exists CHIPNAME] } { + set _CHIPNAME $CHIPNAME +} else { + set _CHIPNAME stm32 +} + +if { [info exists ENDIAN] } { + set _ENDIAN $ENDIAN +} else { + set _ENDIAN little +} + +# Work-area is a space in RAM used for flash programming +# Use the correct size for the card +set WORKAREASIZE 0xF000 + +# By default use 16kB +if { [info exists WORKAREASIZE] } { + set _WORKAREASIZE $WORKAREASIZE +} else { + set _WORKAREASIZE 0x4000 +} + +# JTAG speed should be <= F_CPU/6. F_CPU after reset is 8MHz, so use F_JTAG = 1MHz +jtag_khz 1000 + +jtag_nsrst_delay 100 +jtag_ntrst_delay 100 + +#jtag scan chain +if { [info exists CPUTAPID ] } { + set _CPUTAPID $CPUTAPID +} else { + # See STM Document RM0008 + # Section 26.6.3 + set _CPUTAPID 0x3ba00477 +} +jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID + +if { [info exists BSTAPID ] } { + # FIXME this never gets used to override defaults... + set _BSTAPID $BSTAPID +} else { + # See STM Document RM0008 + # Section 29.6.2 + # Low density devices, Rev A + set _BSTAPID1 0x06412041 + # Medium density devices, Rev A + set _BSTAPID2 0x06410041 + # Medium density devices, Rev B and Rev Z + set _BSTAPID3 0x16410041 + # High density devices, Rev A + set _BSTAPID4 0x06414041 + # Connectivity line devices, Rev A and Rev Z + set _BSTAPID5 0x06418041 +} +jtag newtap $_CHIPNAME bs -irlen 5 -expected-id $_BSTAPID1 \ + -expected-id $_BSTAPID2 -expected-id $_BSTAPID3 \ + -expected-id $_BSTAPID4 -expected-id $_BSTAPID5 + +set _TARGETNAME $_CHIPNAME.cpu +target create $_TARGETNAME cortex_m3 -endian $_ENDIAN -chain-position $_TARGETNAME + +$_TARGETNAME configure -work-area-phys 0x20000000 -work-area-size $_WORKAREASIZE -work-area-backup 0 + +set _FLASHNAME $_CHIPNAME.flash +flash bank $_FLASHNAME stm32f1x 0 0 0 0 $_TARGETNAME + +# For more information about the configuration files, take a look at: +# openocd.texi + diff --git a/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/jtag/target.ini b/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/jtag/target.ini new file mode 100644 index 0000000..da18158 --- /dev/null +++ b/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/jtag/target.ini @@ -0,0 +1,93 @@ +# +# GDB init file for STM32x family +# + +set complaints 1 +set output-radix 16 +set input-radix 16 + +# GDB must be set to big endian mode first if needed. +#set endian little + +# add str9lib src to gdb search path +#dir /cygdrive/c/progra~1/anglia/idealist/examples/stm32/libstr32x/src +#dir C:/Progra~1/Anglia/IDEaliST/examples/stm32/libstm32x/src + +# change gdb prompt +set prompt (arm-gdb) + +# You will need to change this to reflect the address of your jtag interface. +#target remote localhost:2000 + +# The libremote daemon must be set to big endian before the +# executable is loaded. +#monitor endian little + +# Increase the packet size to improve download speed. +# to view current setting use: +# show remote memory-write-packet-size + +set remote memory-write-packet-size 1024 +set remote memory-write-packet-size fixed + +set remote memory-read-packet-size 1024 +set remote memory-read-packet-size fixed +set remote hardware-watchpoint-limit 6 +set remote hardware-breakpoint-limit 6 + +# Load the program executable (ram only) +#load + +# Set a breakpoint at main(). +#b main + +# Run to the breakpoint. +#c + +# +# GDB command helpers +# + +# +# reset and map 0 to internal ram +# + +define ramreset +reset +set *(int*)0xE000ED08 = 0x20000000 +echo Internal RAM set to address 0x0. +end + +# +# reset and map 0 to flash +# + +define flashreset +reset +thb main +echo Internal Flash set to address 0x0. +end + +# +# reset target +# + +define reset +monitor reset +end + +document ramreset +ramreset +Causes a target reset, remaps Internal RAM to address 0x0. +end + +document flashreset +flashreset +Causes a target reset, remaps Internal Flash to address 0x0. +A temporary breakpoint is set at start of function main +end + +document reset +reset +Causes a target reset. +end hooks/post-receive -- krobot |
From: Xavier L. <Ba...@us...> - 2012-05-15 01:23:11
|
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 73a9d3f6a300ae96cc23d523d57126f1885c1fbc (commit) from 25db4f2c52fbbb93893caa63239965d6fe4156de (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 73a9d3f6a300ae96cc23d523d57126f1885c1fbc Author: Xavier Lagorce <Xav...@cr...> Date: Tue May 15 02:00:49 2012 +0200 [Sensor_Actuator] Update switches data ----------------------------------------------------------------------- Changes: diff --git a/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/sensor_actuator/main.c b/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/sensor_actuator/main.c index fc1feda..0ce4d46 100644 --- a/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/sensor_actuator/main.c +++ b/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/sensor_actuator/main.c @@ -46,7 +46,7 @@ #include "switch/switch.h" PROC_DEFINE_STACK(stack_blinky, KERN_MINSTACKSIZE * 2); - + static I2c i2c; static void init(void) @@ -88,7 +88,6 @@ static void init(void) // Initialize the CAN bus processing can_processes_init(); - } static void NORETURN blinky_process(void) { diff --git a/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/sensor_actuator/switch/switch.c b/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/sensor_actuator/switch/switch.c index 1068008..f2ea524 100644 --- a/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/sensor_actuator/switch/switch.c +++ b/elec/boards/Sensor_Actuator/Firmware/sensor_actuator/sensor_actuator/switch/switch.c @@ -37,10 +37,10 @@ static uint32_t pins[][2] = { {GPIOA_BASE, 5}, {GPIOA_BASE, 6}, {GPIOA_BASE, 7}, - {GPIOB_BASE, 5}, - {GPIOC_BASE, 6}, - {GPIOC_BASE, 7}, - {GPIOC_BASE, 8}, + {GPIOB_BASE, 5}, // Buzzer + {GPIOC_BASE, 7}, // Yellow cover-LED + {GPIOC_BASE, 8}, // Red cover-LED + {GPIOC_BASE, 9}, // Green cover-LED }; void switch_init(void) { @@ -59,15 +59,9 @@ void switch_init(void) { GPIO_MODE_IPU, GPIO_SPEED_50MHZ); - // Initialize D2_4 PC(9), D2_6 PC(12) as floating inputs + // Initialize D2_6 PC(12) as floating inputs stm32_gpioPinConfig((struct stm32_gpio *)GPIOC_BASE, - BV(9) | BV(12), - GPIO_MODE_IN_FLOATING, - GPIO_SPEED_50MHZ); - - // Initialize D2_5 PA(8) as floating input - stm32_gpioPinConfig((struct stm32_gpio *)GPIOA_BASE, - BV(8), + BV(12), GPIO_MODE_IN_FLOATING, GPIO_SPEED_50MHZ); @@ -83,9 +77,9 @@ void switch_init(void) { GPIO_MODE_OUT_PP, GPIO_SPEED_50MHZ); - // Initialize D2_1..3 PC(6..8) as output push-pull + // Initialize D2_2..4 PC(7..9) as output push-pull stm32_gpioPinConfig((struct stm32_gpio *)GPIOC_BASE, - BV(6) | BV(7) | BV(8), + BV(7) | BV(8) | BV(9), GPIO_MODE_OUT_PP, GPIO_SPEED_50MHZ); @@ -95,9 +89,9 @@ void switch_init(void) { void get_switch_status(switch_status *pkt1, switch_status *pkt2) { - pkt1->p.sw1 = BOOL(stm32_gpioPinRead((struct stm32_gpio *)GPIOC_BASE, BV(4))); - pkt1->p.sw2 = BOOL(stm32_gpioPinRead((struct stm32_gpio *)GPIOC_BASE, BV(5))); - pkt1->p.sw3 = BOOL(stm32_gpioPinRead((struct stm32_gpio *)GPIOB_BASE, BV(0))); + pkt1->p.sw1 = BOOL(stm32_gpioPinRead((struct stm32_gpio *)GPIOC_BASE, BV(4))); // Start switch + pkt1->p.sw2 = BOOL(stm32_gpioPinRead((struct stm32_gpio *)GPIOC_BASE, BV(5))); // Team switch + pkt1->p.sw3 = BOOL(stm32_gpioPinRead((struct stm32_gpio *)GPIOB_BASE, BV(0))); // Fault Button pkt1->p.sw4 = BOOL(stm32_gpioPinRead((struct stm32_gpio *)GPIOB_BASE, BV(1))); pkt1->p.sw5 = BOOL(stm32_gpioPinRead((struct stm32_gpio *)GPIOB_BASE, BV(12))); pkt1->p.sw6 = BOOL(stm32_gpioPinRead((struct stm32_gpio *)GPIOB_BASE, BV(15))); @@ -105,8 +99,8 @@ void get_switch_status(switch_status *pkt1, switch_status *pkt2) { pkt2->p.sw1 = 0; //BOOL(stm32_gpioPinRead((struct stm32_gpio *)GPIOC_BASE, BV(6))); pkt2->p.sw2 = 0; //BOOL(stm32_gpioPinRead((struct stm32_gpio *)GPIOC_BASE, BV(7))); pkt2->p.sw3 = 0; //BOOL(stm32_gpioPinRead((struct stm32_gpio *)GPIOC_BASE, BV(8))); - pkt2->p.sw4 = BOOL(stm32_gpioPinRead((struct stm32_gpio *)GPIOC_BASE, BV(9))); - pkt2->p.sw5 = BOOL(stm32_gpioPinRead((struct stm32_gpio *)GPIOA_BASE, BV(8))); + pkt2->p.sw4 = 0; //BOOL(stm32_gpioPinRead((struct stm32_gpio *)GPIOC_BASE, BV(9))); + pkt2->p.sw5 = 0; //BOOL(stm32_gpioPinRead((struct stm32_gpio *)GPIOA_BASE, BV(8))); pkt2->p.sw6 = BOOL(stm32_gpioPinRead((struct stm32_gpio *)GPIOC_BASE, BV(12))); } @@ -126,7 +120,7 @@ void set_switch(switch_request *pkt) { } void set_buzzer(uint8_t state) { - + stm32_gpioPinWrite((struct stm32_gpio *)GPIOB_BASE, BV(5), state); } hooks/post-receive -- krobot |
From: Pierre C. <Ba...@us...> - 2012-05-15 01:09:31
|
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 25db4f2c52fbbb93893caa63239965d6fe4156de (commit) from 08c2505def22aa273c38c7174e02e3b8f2255df8 (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 25db4f2c52fbbb93893caa63239965d6fe4156de Author: chicco <cha...@cr...> Date: Tue May 15 03:09:07 2012 +0200 [camlcv] add missing tests ----------------------------------------------------------------------- Changes: diff --git a/info/vision/camlcv/test/test_contour_canny.ml b/info/vision/camlcv/test/test_contour_canny.ml new file mode 100644 index 0000000..cb820b4 --- /dev/null +++ b/info/vision/camlcv/test/test_contour_canny.ml @@ -0,0 +1,35 @@ +open CvCore +open CvHighGui +open Test_base + +let _ = named_window ~option:CV_WINDOW_AUTOSIZE "canny" +let canny_t1 = create_trackbar ~default:50 ~name:"t1" ~window:"canny" 255 +let canny_t2 = create_trackbar ~default:200 ~name:"t2" ~window:"canny" 255 + +let rec show () = + let src = get_image () in + let hsv = convert_color src bgr2hsv in + let h,s,v = split hsv in + let gray = convert_color src bgr2gray in + (* let gray = s in *) + let gray = gaussian_blur ~size:(3,3) gray 2. 2. in + let gray' = convert_color gray gray2bgr in + let edges = canny gray (float (get_var canny_t1)) (float (get_var canny_t2)) in + let edges' = clone_image edges in + let contours = contours (find_contours ~meth:CV_CHAIN_APPROX_TC89_KCOS edges) in + + List.iter (fun (Contour (c,l)) -> draw_contours ~level:0 gray' c) contours; + + let ellipses = List.map (fun (Contour (c,l)) -> fit_ellipse c) contours in + List.iter (function | None -> () + | Some e -> ellipse' src e) ellipses; + + show_image "canny" edges'; + show_image "gray" gray'; + show_image "src" src; + + match wait_key 10 with + | Some 'q' -> () + | _ -> show () + +let _ = show () diff --git a/info/vision/camlcv/test/test_detect_ellipse.ml b/info/vision/camlcv/test/test_detect_ellipse.ml new file mode 100644 index 0000000..9ca9478 --- /dev/null +++ b/info/vision/camlcv/test/test_detect_ellipse.ml @@ -0,0 +1,49 @@ +open CvCore +open CvHighGui +open Test_base + +let _ = named_window ~option:CV_WINDOW_AUTOSIZE "s" +let _ = named_window ~option:CV_WINDOW_AUTOSIZE "v" + +let smin = create_trackbar ~default:0 ~name:"min" ~window:"s" 256 +let smax = create_trackbar ~default:256 ~name:"max" ~window:"s" 256 + +let vmin = create_trackbar ~default:0 ~name:"min" ~window:"v" 256 +let vmax = create_trackbar ~default:256 ~name:"max" ~window:"v" 256 + +let rec show () = + let src = get_image () in + let src = gaussian_blur src ~size:(3,3) 2. 2. in + let hsv = convert_color src bgr2hsv in + let h,s,v = split hsv in + + let v' = between v (* (equalize_hist v) *) (get_var vmin) (get_var vmax) in + let s' = between s (* (equalize_hist s) *) (get_var smin) (get_var smax) in + + let filtered = copy s' (Some v') in + let filtered = erode filtered (5,5) in + let filtered = dilate filtered (5,5) in + + let filtered_src = copy src (Some filtered) in + +(* let final_src = copy src (Some final) in *) + + let contours = contours (find_contours filtered) in + + List.iter (fun (Contour (c,l)) -> draw_contours ~level:0 src c) contours; + + let ellipses = List.map (fun (Contour (c,l)) -> fit_ellipse c) contours in + List.iter (function | None -> () + | Some e -> ellipse' src e) ellipses; + + show_image "s" s'; + show_image "v" v'; + show_image "src" src; + show_image "filtered" filtered_src; +(* show_image "final" final_src; *) + match wait_key 10 with + | Some 'q' -> + Printf.printf "s: %i %i\nv: %i %i\n%!" (get_var smin) (get_var smax) (get_var vmin) (get_var vmax) + | _ -> show () + +let _ = show () diff --git a/info/vision/camlcv/test/test_detect_lines.ml b/info/vision/camlcv/test/test_detect_lines.ml new file mode 100644 index 0000000..698f56d --- /dev/null +++ b/info/vision/camlcv/test/test_detect_lines.ml @@ -0,0 +1,52 @@ +open CvCore +open CvHighGui +open Test_base + +let _ = named_window ~option:CV_WINDOW_AUTOSIZE "canny" +let canny_t1 = create_trackbar ~default:50 ~name:"t1" ~window:"canny" 255 +let canny_t2 = create_trackbar ~default:200 ~name:"t2" ~window:"canny" 255 + +let _ = named_window ~option:CV_WINDOW_AUTOSIZE "h" +let hmin = create_trackbar ~default:0 ~name:"hmin" ~window:"h" 255 +let hmax = create_trackbar ~default:76 ~name:"hmax" ~window:"h" 255 + +let pi = 4. *. (atan 1.) + +let rec show () = + let src = get_image () in + let hsv = convert_color src bgr2hsv in + let h,s,v = split hsv in + (* let gray = convert_color src bgr2gray in *) + let gray = v in + let a = good_features_to_track + gray + 50 + 0.01 + 5. in + let gray = gaussian_blur ~size:(3,3) gray 1. 1. in + let edges = canny gray (float (get_var canny_t1)) (float (get_var canny_t2)) in + + let h' = between h (get_var hmin) (get_var hmax) in + let dilate_h = erode h' (3,3) in + let edges' = copy edges (Some dilate_h) in + + let lines = + houghLinesP + ~minLineLength:30. + ~maxLineGap:20. + edges' 1. (pi /. 180.) 30 in + + Array.iter (fun (x1,y1,x2,y2) -> line ~color:red src (x1,y1) (x2,y2)) lines; + + draw_points ~color:blue src a; + + show_image "h" h'; + show_image "canny" edges'; + show_image "gray" gray; + show_image "src" src; + + match wait_key 10 with + | Some 'q' -> () + | _ -> show () + +let _ = show () diff --git a/info/vision/camlcv/test/test_homography.ml b/info/vision/camlcv/test/test_homography.ml new file mode 100644 index 0000000..6bee39d --- /dev/null +++ b/info/vision/camlcv/test/test_homography.ml @@ -0,0 +1,66 @@ +open CvCore +open CvHighGui +open Test_base + +let v_prod (x1,y1) (x2,y2) = x1 *. x2 +. y1 *. y2 + +let i_array a = + Array.mapi (fun i a -> + Array.mapi (fun j v -> v,(i,j)) a) a + +let get_minv v a = + List.hd (List.sort (fun (v1,_) (v2,_) -> + compare (v_prod v v1) (v_prod v v2)) a) + +let x_size = 8. +let y_size = 6. + +let float_c (x,y) = int_of_float x, int_of_float y + +let lower_left (ix,iy) a' = + let a = List.flatten (Array.to_list (Array.map Array.to_list (i_array a'))) in + let ix, iy = float ix, float iy in + let p00 = get_minv (ix,-.iy) a in + let pxy = get_minv (-.ix,iy) a in + let p0y = get_minv (ix,iy) a in + let px0 = get_minv (-.ix,-.iy) a in + p00, px0, p0y, pxy + +let norm v = + match v with + | [|a;b;c|] -> [|a/.c;b/.c;1.|] + | _ -> assert false + +let print_a = Array.iter (Printf.printf " %f") + +let rec show () = + let image = get_image () in + let gray = convert_color image bgr2gray in + let r = find_chessboard_corners gray (6,8) in + (match array_of_chessboard_corners r with + | None -> () + | Some a -> + let (p0,_),(p1,_),(p2,_),(p3,_) = lower_left (image_size image) a in + draw_chessboard_corners image r; + circle image ~color:red (float_c p0) 30; + circle image ~color:green (float_c p1) 30; + circle image ~color:blue (float_c p2) 30; + circle image ~color:yellow (float_c p3) 30; + let homo = find_homography + ~obj_pos:[|0.,0.; + x_size,0.; + 0.,y_size; + x_size,y_size|] + ~img_pos:[|p0;p1;p2;p3|] in + let v1 = norm (mult homo [|0.;0.;1.|]) in + let v2 = norm (mult homo [|3.;3.;1.|]) in + line image ~color:red ~thickness:5 (int_of_float v1.(0),int_of_float v1.(1)) + (int_of_float v2.(0),int_of_float v2.(1)); + Array.iter (fun a -> print_a a; Printf.printf "\n") homo; + Printf.printf "\n%!"); + show_image "out" image; + match wait_key 10 with + | Some 'q' -> () + | _ -> show () + +let _ = show () diff --git a/info/vision/camlcv/test/test_houghLines.ml b/info/vision/camlcv/test/test_houghLines.ml new file mode 100644 index 0000000..1ebf008 --- /dev/null +++ b/info/vision/camlcv/test/test_houghLines.ml @@ -0,0 +1,49 @@ +open CvCore +open CvHighGui +open Test_base + +let _ = named_window ~option:CV_WINDOW_AUTOSIZE "canny" +let canny_t1 = create_trackbar ~default:50 ~name:"t1" ~window:"canny" 255 +let canny_t2 = create_trackbar ~default:200 ~name:"t2" ~window:"canny" 255 + +let pi = 4. *. (atan 1.) + +let rec show () = + let src = get_image () in + let hsv = convert_color src bgr2hsv in + let h,s,v = split hsv in + (* let gray = convert_color src bgr2gray in *) + let gray = v in + let gray = gaussian_blur ~size:(3,3) gray 2. 2. in + let edges = canny gray (float (get_var canny_t1)) (float (get_var canny_t2)) in + + let x,y = image_size edges in + let circles = houghCircles gray + ~param1:(float (get_var canny_t1)) + ~param2:(float (get_var canny_t2)) + ~minRadius:0 + ~maxRadius:0 + 1. (float x /. 8.) in + + Array.iter (fun (x1,y1,r) -> + circle src + (int_of_float x1,int_of_float y1) + (int_of_float r)) circles; + + let lines = + houghLinesP + ~minLineLength:50. + ~maxLineGap:20. + edges 1. (pi /. 180.) 50 in + + Array.iter (fun (x1,y1,x2,y2) -> line ~color:red src (x1,y1) (x2,y2)) lines; + + show_image "canny" edges; + show_image "gray" gray; + show_image "src" src; + + match wait_key 10 with + | Some 'q' -> () + | _ -> show () + +let _ = show () hooks/post-receive -- krobot |
From: Pierre C. <Ba...@us...> - 2012-05-14 21:47:29
|
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 08c2505def22aa273c38c7174e02e3b8f2255df8 (commit) via a251326d374e2c0795e63a3202674f2726dd8390 (commit) from 35f2720c1b040772eeefd7d06efd6ad4f3be3220 (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 08c2505def22aa273c38c7174e02e3b8f2255df8 Author: chicco <cha...@cr...> Date: Mon May 14 23:47:06 2012 +0200 update vision, add detection tests commit a251326d374e2c0795e63a3202674f2726dd8390 Author: chicco <cha...@cr...> Date: Mon May 14 23:45:22 2012 +0200 update viewer for the new table, add message for coins position, add tool to detect coins ----------------------------------------------------------------------- Changes: diff --git a/info/control2011/_oasis b/info/control2011/_oasis index 587f26e..3227ab2 100644 --- a/info/control2011/_oasis +++ b/info/control2011/_oasis @@ -240,6 +240,13 @@ Executable "krobot-ax12-clean" CompiledObject: best MainIs: krobot_ax12_clean.ml +Executable "krobot-see-coin" + Path: src/tools + Install: true + CompiledObject: best + MainIs: krobot_see_coin.ml + BuildDepends: krobot, cv, lwt.syntax + # +-------------------------------------------------------------------+ # | Examples | # +-------------------------------------------------------------------+ diff --git a/info/control2011/_tags b/info/control2011/_tags index 8e8eb2b..c2c77dd 100644 --- a/info/control2011/_tags +++ b/info/control2011/_tags @@ -2,7 +2,7 @@ <src/interfaces/*.ml>: -syntax_camlp4o # OASIS_START -# DO NOT EDIT (digest: c7b4424d285a5d14617154af42598aa7) +# DO NOT EDIT (digest: 8b68a015ff8be0607836f173f33170fd) # Ignore VCS directories, you can use the same kind of rule outside # OASIS_START/STOP if you want to exclude directories that contains # useless stuff for the build process @@ -114,6 +114,13 @@ # Executable krobot-hub <src/tools/krobot_hub.{native,byte}>: pkg_lwt.unix <src/tools/krobot_hub.{native,byte}>: pkg_lwt.syntax +# Executable krobot-see-coin +<src/tools/krobot_see_coin.{native,byte}>: use_krobot +<src/tools/krobot_see_coin.{native,byte}>: pkg_lwt.unix +<src/tools/krobot_see_coin.{native,byte}>: pkg_lwt.syntax +<src/tools/krobot_see_coin.{native,byte}>: pkg_lwt.react +<src/tools/krobot_see_coin.{native,byte}>: pkg_cv +<src/tools/*.ml{,i}>: pkg_cv # Executable krobot-sharps <src/tools/krobot_sharps.{native,byte}>: use_krobot <src/tools/krobot_sharps.{native,byte}>: pkg_lwt.unix diff --git a/info/control2011/setup.ml b/info/control2011/setup.ml index a2b32ae..e0ea140 100644 --- a/info/control2011/setup.ml +++ b/info/control2011/setup.ml @@ -1,7 +1,7 @@ (* setup.ml generated for the first time by OASIS v0.2.0~alpha1 *) (* OASIS_START *) -(* DO NOT EDIT (digest: 8dd92996e901c6afd5668c8d5fed679a) *) +(* DO NOT EDIT (digest: 6276a9db280e9f6fd9a16f0e5e4359c8) *) (* Regenerated by OASIS v0.3.0~rc3 Visit http://oasis.forge.ocamlcore.org for more information and @@ -5777,6 +5777,35 @@ let setup_t = {exec_custom = false; exec_main_is = "krobot_hub.ml"; }); Executable ({ + cs_name = "krobot-see-coin"; + 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 ("cv", None); + 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_see_coin.ml"; + }); + Executable + ({ cs_name = "krobot-sharps"; cs_data = PropList.Data.create (); cs_plugin_data = []; @@ -6191,13 +6220,13 @@ let setup_t = }; oasis_fn = Some "_oasis"; oasis_version = "0.3.0~rc3"; - oasis_digest = Some "[\188\237\193\021xw\196\204\204<Y\157o\194F"; + oasis_digest = Some "\189Q=v\151\180\162\208\188\238+\208>;\014V"; oasis_exec = None; oasis_setup_args = []; };; let setup () = BaseSetup.setup setup_t;; -# 6202 "setup.ml" +# 6231 "setup.ml" (* OASIS_STOP *) let () = setup ();; diff --git a/info/control2011/src/can/libkrobot-can_stubs.clib b/info/control2011/src/can/libkrobot-can_stubs.clib new file mode 100644 index 0000000..0c062e7 --- /dev/null +++ b/info/control2011/src/can/libkrobot-can_stubs.clib @@ -0,0 +1,4 @@ +# OASIS_START +# DO NOT EDIT (digest: c331c7eb709b41509f57de577257bebd) +can_stubs.o +# OASIS_STOP diff --git a/info/control2011/src/lib/krobot_bus.ml b/info/control2011/src/lib/krobot_bus.ml index bb2d08a..0776640 100644 --- a/info/control2011/src/lib/krobot_bus.ml +++ b/info/control2011/src/lib/krobot_bus.ml @@ -37,6 +37,7 @@ type message = | Strategy_stop | Strategy_set of Krobot_action.t list | Strategy_path of Bezier.curve list option + | Coins of vertice list type t = { oc : Lwt_io.output_channel; @@ -111,6 +112,10 @@ let string_of_message = function sprintf "Strategy_path(Some [%s])" (String.concat "; " (List.map Bezier.string_of_curve curves)) + | Coins coins -> + sprintf + "Coins [%s]" + (String.concat "; " (List.map string_of_vertice coins)) (* +-----------------------------------------------------------------+ | Sending/receiving messages | diff --git a/info/control2011/src/lib/krobot_bus.mli b/info/control2011/src/lib/krobot_bus.mli index bef8110..59bd8e1 100644 --- a/info/control2011/src/lib/krobot_bus.mli +++ b/info/control2011/src/lib/krobot_bus.mli @@ -69,6 +69,9 @@ type message = (** Message emitted when the robot starts or stops a trajectory. *) + (** Vision *) + | Coins of vertice list + val string_of_message : message -> string (** Returns a string representation of the given message. *) diff --git a/info/control2011/src/lib/krobot_config.ml b/info/control2011/src/lib/krobot_config.ml index 749977a..4c5ef37 100644 --- a/info/control2011/src/lib/krobot_config.ml +++ b/info/control2011/src/lib/krobot_config.ml @@ -9,7 +9,7 @@ let sqr x = x *. x -let world_height = 2.1 +let world_height = 2. let world_width = 3. let robot_size = 0.26 let wheels_diameter = 0.098 @@ -20,3 +20,5 @@ let object_radius = 0.1 let border_safety_distance = sqrt (sqr robot_size /. 2.) +. 0.05 let object_safety_distance = object_radius +. robot_size /. 2. let beacon_safety_distance = 0.7 + +let coin_radius = 0.12 diff --git a/info/control2011/src/lib/krobot_config.mli b/info/control2011/src/lib/krobot_config.mli index deba593..def3497 100644 --- a/info/control2011/src/lib/krobot_config.mli +++ b/info/control2011/src/lib/krobot_config.mli @@ -43,3 +43,6 @@ val object_safety_distance : float val beacon_safety_distance : float (** Minimum distance between the center of the robot and the beacon. *) + +val coin_radius : float + (** Radius of coins. *) diff --git a/info/control2011/src/lib/krobot_geom.ml b/info/control2011/src/lib/krobot_geom.ml index a7a1dea..2f87a84 100644 --- a/info/control2011/src/lib/krobot_geom.ml +++ b/info/control2011/src/lib/krobot_geom.ml @@ -91,6 +91,16 @@ let tangents a b c = let v1 = ba -| bc and v2 = bc -| ba in (v1 /| norm v1, v2 /| norm v2) +let rot_mat theta = + [| [| cos theta; -. (sin theta); 0.; |]; + [| sin theta; cos theta; 0. |]; + [| 0.; 0.; 1. |]; |] + +let mult m v = + Array.init (Array.length m) + (fun k -> Array.fold_left (+.) 0. + (Array.mapi (fun i n -> v.(i) *. n) m.(k))) + (* +-----------------------------------------------------------------+ | Cubic bezier curves | +-----------------------------------------------------------------+ *) diff --git a/info/control2011/src/lib/krobot_geom.mli b/info/control2011/src/lib/krobot_geom.mli index a2fbbd5..71ec7e9 100644 --- a/info/control2011/src/lib/krobot_geom.mli +++ b/info/control2011/src/lib/krobot_geom.mli @@ -46,6 +46,11 @@ val tangents : vertice -> vertice -> vertice -> vector * vector (** [tangents a b c] returns the two unitary vectors tangent to the triangle abc in b. *) +val rot_mat : float -> float array array + +val mult : float array array -> float array -> float array +(** [mult m v] matrix multiplication *) + (** {6 Cubic Bezier curves} *) module Bezier : sig diff --git a/info/control2011/src/lib/libkrobot_stubs.clib b/info/control2011/src/lib/libkrobot_stubs.clib new file mode 100644 index 0000000..2fd3bec --- /dev/null +++ b/info/control2011/src/lib/libkrobot_stubs.clib @@ -0,0 +1,4 @@ +# OASIS_START +# DO NOT EDIT (digest: a4550602349a377958d2b340260718d0) +krobot_message_stubs.o +# OASIS_STOP diff --git a/info/control2011/src/tools/krobot_read_dump.ml b/info/control2011/src/tools/krobot_read_dump.ml new file mode 100644 index 0000000..e69de29 diff --git a/info/control2011/src/tools/krobot_see_coin.ml b/info/control2011/src/tools/krobot_see_coin.ml new file mode 100644 index 0000000..cf859de --- /dev/null +++ b/info/control2011/src/tools/krobot_see_coin.ml @@ -0,0 +1,230 @@ +open Lwt +open Lwt_react +open Krobot_bus +open Krobot_geom +open Krobot_config +open Krobot_message +open CvCore +open CvHighGui + +let section = Lwt_log.Section.make "krobot(see_coin)" + +(* +-----------------------------------------------------------------+ + | vision initialisation | + +-----------------------------------------------------------------+ *) + +let calibration_file = ref None +let homography_file = ref None +let color_filter_file = ref None + +let file_string file = + let file = open_in file in + let l = in_channel_length file in + let s = String.create l in + ignore(Pervasives.input file s 0 l); + s + +type color_filter = + { s_bounds : int * int; + v_bounds : int *int; } + +let load_color_filter () = match !color_filter_file with + | None -> + lwt () = Lwt_log.warning "No color config provided" in + return { s_bounds = 0, 100; + v_bounds = 150, 255; } + | Some file -> + try_lwt + let f = file_string file in + Scanf.sscanf f "s %i %i\nv %i %i\n" + (fun s1 s2 v1 v2 -> + return { v_bounds = v1, v2; s_bounds = s1, s2 }) + with + | exn -> + lwt () = Lwt_log.error ~exn "can't load color file" in + raise_lwt exn + +let load_calibration () = match !calibration_file with + | None -> + lwt () = Lwt_log.warning "No calibration config provided" in + return ([|[|1.;0.;1.;|]; + [|0.;1.;1.;|]; + [|0.;0.;1.;|]|], + [|0.;0.;0.;0.;0.|]) + | Some file -> + try_lwt + return (load_calibration_file file) + with + | exn -> + lwt () = Lwt_log.error ~exn "can't load calibration file" in + raise_lwt exn + +let load_homography () = match !homography_file with + | None -> + lwt () = Lwt_log.warning "No homography config provided" in + return [|[|1.;0.;0.;|]; + [|0.;1.;0.;|]; + [|0.;0.;1.;|]|] + | Some file -> + try_lwt + return (load_homography_file file) + with + | exn -> + lwt () = Lwt_log.error ~exn "can't load homography file" in + raise_lwt exn + +let rec get_cam i m = + if i <= m + then + try + Some (capture_from_cam i) + with + | _ -> get_cam (i+1) m + else None + +type vision = { + capture : cvCapture; + size : cvSize; + color_filter : color_filter; + remap : remap; + homography : float array array; + inv_homography : float array array; +} + +let init_capture () = + match get_cam 0 10 with + | None -> + lwt () = Lwt_log.error "Can't acquire webcam" in + raise_lwt (Failure "Can't acquire webcam") + | Some capture -> + set_capture_property capture CV_CAP_PROP_FRAME_HEIGHT 480.; + set_capture_property capture CV_CAP_PROP_FRAME_WIDTH 640.; + let i = query_frame capture in + let size = image_size i in + lwt color_filter = load_color_filter () in + lwt calibration = load_calibration () in + let remap_info = init_undistort_map size calibration in + lwt homography = load_homography () in + let det, inv_homography = invert homography in + return { capture; + size; + color_filter; + remap = remap_info; + homography; + inv_homography; } + +(* +-----------------------------------------------------------------+ + | Main vision code | + +-----------------------------------------------------------------+ *) + +let rec filter_map f l = + match l with + | [] -> [] + | t::q -> + match f t with + | None -> filter_map f q + | Some t -> t::(filter_map f q) + +let detect_ellipse vision = + let src = query_frame vision.capture in + let src = remap vision.remap src in + let hsv = convert_color src bgr2hsv in + let h,s,v = split hsv in + let vmin, vmax = vision.color_filter.v_bounds in + let v = between v vmin vmax in + let smin, smax = vision.color_filter.s_bounds in + let s = between s smin smax in + + let filtered = copy s (Some v) in + let filtered = erode filtered (5,5) in + let filtered = dilate filtered (5,5) in + let contours = contours (find_contours filtered) in + let ellipses = filter_map (fun (Contour (c,l)) -> + fit_ellipse c) contours in + (* TODO: filter good ellipses *) + ellipses + +let loop bus vision = + let rec aux () = + let time = Unix.gettimeofday () in + let ellipses = detect_ellipse vision in + let time2 = Unix.gettimeofday () in + lwt () = Lwt_log.info_f "vision compute time: %f" (time2 -. time) in + let norm v = + match v with + | [|a;b;c|] -> { x = a/.c; y = b/.c } + | _ -> assert false in + let vertices = List.map + (fun e -> let x,y = e.ellipse_center in + norm (mult vision.inv_homography [|x;y;1.|]) ) + ellipses in + let msg = Coins vertices in + lwt () = Krobot_bus.send bus (time, msg) in + lwt () = Lwt_unix.sleep 0.01 in + aux () in + aux () + +(* +-----------------------------------------------------------------+ + | Message handling | + +-----------------------------------------------------------------+ *) + +let handle_message looker (timestamp, message) = + match message with + | Kill "see_coin" -> + exit 0 + | _ -> + () + +(* +-----------------------------------------------------------------+ + | Command-line arguments | + +-----------------------------------------------------------------+ *) + +let fork = ref true + +let options = Arg.align [ + "-no-fork", Arg.Clear fork, " Run in foreground"; + "-calibration", Arg.String (fun s -> calibration_file:=Some s), "calibration config file"; + "-cam", Arg.String (fun s -> calibration_file:=Some s), "-calibration"; + "-homography", Arg.String (fun s -> homography_file:=Some s), "homography config file"; + "-h", Arg.String (fun s -> homography_file:=Some s), "-homography"; + "-color", Arg.String (fun s -> color_filter_file:=Some s), "color filter config file"; + "-c", Arg.String (fun s -> color_filter_file:=Some s), "-color"; +] + +let usage = "\ +Usage: krobot-see-coin [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 Lwt_daemon.daemonize (); + + let looker = () in + + (* Handle krobot message. *) + E.keep (E.map (handle_message looker) (Krobot_bus.recv bus)); + + (* Kill any running planner. *) + lwt () = Krobot_bus.send bus (Unix.gettimeofday (), Krobot_bus.Kill "see_coin") in + +(* + (* Ask for initial parameters. *) + lwt () = Krobot_bus.send bus (Unix.gettimeofday (), Send) in +*) + + lwt vision = init_capture () in + + (* Loop forever. *) + loop bus vision diff --git a/info/control2011/src/tools/krobot_viewer.ml b/info/control2011/src/tools/krobot_viewer.ml index 7d4b629..92af2d6 100644 --- a/info/control2011/src/tools/krobot_viewer.ml +++ b/info/control2011/src/tools/krobot_viewer.ml @@ -55,6 +55,9 @@ type viewer = { mutable objects : vertice list; (* The objects on the table. *) + + mutable coins : vertice list; + (* The coins on the table *) } (* +-----------------------------------------------------------------+ @@ -69,6 +72,7 @@ type color = | Blue | Yellow | Purple + | Brown let set_color ctx color = let r, g, b = match color with @@ -79,6 +83,7 @@ let set_color ctx color = | Blue -> (0., 59., 128.) | Yellow -> (252., 189., 31.) | Purple -> (128., 0., 128.) + | Brown -> (175., 89., 67.) in Cairo.set_source_rgb ctx (r /. 255.) (g /. 255.) (b /. 255.) @@ -138,96 +143,89 @@ let draw viewer = (* Draw the viewer background *) Cairo.rectangle ctx 0. 0. world_width world_height; - set_color ctx Green; + set_color ctx Blue; Cairo.fill ctx; (* Draw the starting areas *) - Cairo.rectangle ctx 0. (world_height -. 0.4) 0.4 0.4; - set_color ctx Red; + Cairo.rectangle ctx 0. (world_height -. 0.5) 0.5 0.5; + set_color ctx Purple; Cairo.fill ctx; - Cairo.rectangle ctx (world_width -. 0.4) (world_height -. 0.4) 0.4 0.4; - set_color ctx Blue; + Cairo.rectangle ctx (world_width -. 0.5) (world_height -. 0.5) 0.5 0.5; + set_color ctx Red; Cairo.fill ctx; - (* Draw the paving *) - for i = 0 to 5 do - for j = 0 to 5 do - let x = 0.45 +. 0.35 *. float i - and y = 0.35 *. float j in - Cairo.rectangle ctx x y 0.35 0.35; - set_color ctx (if (i + j) mod 2 = 0 then Red else Blue); - Cairo.fill ctx - done - done; - - (* Draw the bands *) + (* draw black lines *) +(* + Cairo.move_to ctx 0.5; + Cairo.line_to ctx (world_height -. 0.45) (0.5 +. 0.15); + Cairo.line_to ctx 0. (0.5 +. 0.15); +*) + Cairo.move_to ctx 0.5 (world_height -. 0.45); + Cairo.line_to ctx (0.5 +. 0.15) (world_height -. 0.45); + Cairo.line_to ctx (0.5 +. 0.15) 0.; + Cairo.move_to ctx (world_width -. 0.5) (world_height -. 0.45); + Cairo.line_to ctx (world_width -. (0.5 +. 0.15)) (world_height -. 0.45); + Cairo.line_to ctx (world_width -. (0.5 +. 0.15)) 0.; set_color ctx Black; + Cairo.set_line_width ctx (5. /. scale); + Cairo.stroke ctx; - Cairo.rectangle ctx 0.4 0. 0.05 world_height; - Cairo.fill ctx; - - Cairo.rectangle ctx (world_width -. 0.45) 0. 0.05 world_height; - Cairo.fill ctx; - - Cairo.rectangle ctx 0.45 0.33 0.7 0.02; + (* draw the homes *) + Cairo.move_to ctx 0. 0.; + Cairo.line_to ctx 0.325 0.; + Cairo.line_to ctx 0.4 (world_height -. 0.5); + Cairo.line_to ctx 0. (world_height -. 0.5); + set_color ctx Brown; Cairo.fill ctx; - Cairo.rectangle ctx (world_width -. 1.15) 0.33 0.7 0.02; + Cairo.move_to ctx world_width 0.; + Cairo.line_to ctx (world_width -. 0.325) 0.; + Cairo.line_to ctx (world_width -. 0.4) (world_height -. 0.5); + Cairo.line_to ctx world_width (world_height -. 0.5); + set_color ctx Brown; Cairo.fill ctx; - Cairo.rectangle ctx 1.13 0. 0.02 0.35; - Cairo.fill ctx; + Cairo.set_antialias ctx Cairo.ANTIALIAS_DEFAULT; - Cairo.rectangle ctx (world_width -. 1.15) 0. 0.02 0.35; + (* Draw plages *) + Cairo.arc ctx 1.5 world_height 0.4 pi (2.*.pi); + set_color ctx Yellow; Cairo.fill ctx; - Cairo.rectangle ctx 0.45 0. 0.7 0.12; + Cairo.arc ctx 1.5 world_height 0.3 pi (2.*.pi); + set_color ctx Green; Cairo.fill ctx; - Cairo.rectangle ctx (world_width -. 1.15) 0. 0.7 0.12; + Cairo.arc ctx (0.64 +. 0.477) (world_height -. 1.) 0.3 0. (2.*.pi); + set_color ctx Yellow; Cairo.fill ctx; - Cairo.rectangle ctx 0.45 0. 0.02 0.25; + Cairo.arc ctx (world_width -. (0.64 +. 0.477)) (world_height -. 1.) 0.3 0. (2.*.pi); + set_color ctx Yellow; Cairo.fill ctx; - Cairo.rectangle ctx (world_width -. 0.47) 0. 0.02 0.25; + Cairo.rectangle ctx (0.64 +. 0.477) 0.75 0.8 0.5; + set_color ctx Yellow; Cairo.fill ctx; - Cairo.move_to ctx 0. (world_height -. 0.4); - Cairo.rel_line_to ctx 0.4 0.; - Cairo.stroke ctx; - - Cairo.move_to ctx 0. (world_height -. 0.422); - Cairo.rel_line_to ctx 0.4 0.; - Cairo.stroke ctx; - - Cairo.move_to ctx (world_width -. 0.4) (world_height -. 0.4); - Cairo.rel_line_to ctx 0.4 0.; - Cairo.stroke ctx; - - Cairo.move_to ctx (world_width -. 0.4) (world_height -. 0.422); - Cairo.rel_line_to ctx 0.4 0.; - Cairo.stroke ctx; - - Cairo.set_antialias ctx Cairo.ANTIALIAS_DEFAULT; - - (* Draw circles on bonus cases *) - Cairo.arc ctx 0.975 0.875 0.05 0. (2. *. pi); - Cairo.fill ctx; - - Cairo.arc ctx 0.975 1.575 0.05 0. (2. *. pi); + Cairo.arc ctx 1.5 0.24 0.55 (pi /. 4.) (3.*.pi/.4.); + set_color ctx Blue; Cairo.fill ctx; - Cairo.arc ctx 2.025 0.875 0.05 0. (2. *. pi); + Cairo.arc ctx 1.5 (world_height -. 0.24) 0.55 (5. *. pi /. 4.) (7.*.pi/.4.); + set_color ctx Blue; Cairo.fill ctx; - Cairo.arc ctx 2.025 1.575 0.05 0. (2. *. pi); + Cairo.arc ctx (0.64 +. 0.477) (world_height -. 1.) 0.2 0. (2.*.pi); + set_color ctx Green; Cairo.fill ctx; - Cairo.arc ctx 1.325 0.175 0.05 0. (2. *. pi); + Cairo.arc ctx (world_width -. (0.64 +. 0.477)) (world_height -. 1.) 0.2 0. (2.*.pi); + set_color ctx Green; Cairo.fill ctx; - Cairo.arc ctx 1.675 0.175 0.05 0. (2. *. pi); + Cairo.arc ctx 1.5 1. 0.1 0. (2.*.pi); + set_color ctx Green; Cairo.fill ctx; (* Draw objects *) @@ -242,6 +240,18 @@ let draw viewer = Cairo.stroke ctx) viewer.objects; + (* Draw coins *) + List.iter + (fun { x; y } -> + set_color ctx White; + Cairo.arc ctx x y Krobot_config.coin_radius 0. (2. *. pi); + Cairo.fill ctx; + + set_color ctx Black; + Cairo.arc ctx x y Krobot_config.coin_radius 0. (2. *. pi); + Cairo.stroke ctx) + viewer.coins; + (* Draw the robot and the ghost *) List.iter (fun (state, alpha) -> @@ -450,6 +460,15 @@ let handle_message viewer (timestamp, message) = viewer.objects <- l; queue_draw viewer + | Coins l -> + viewer.coins <- + List.map + (fun v -> + let v = [|v.x;v.y;1.|] in + let v = mult (rot_mat viewer.state.theta) v in + { x = v.(0); y = v.(1) }) l; + queue_draw viewer + | _ -> () @@ -511,6 +530,7 @@ lwt () = statusbar_context = ui#statusbar#new_context ""; motor_status = (false, false, false, false); objects = []; + coins = []; } in (* Handle messages. *) diff --git a/info/vision/camlcv/_oasis b/info/vision/camlcv/_oasis index b4c3985..198848e 100644 --- a/info/vision/camlcv/_oasis +++ b/info/vision/camlcv/_oasis @@ -29,10 +29,10 @@ Library "cv" CvHighGui CSources: cv_caml.c - CCopt: -x c++ -O2 + CCopt: -g -x c++ -O2 CClib: -lstdc++ XMETADescription: Core Opencv - BuildDepends: bigarray + BuildDepends: bigarray, str Executable "leak" Path: test/ @@ -81,3 +81,33 @@ Executable "test_calib" MainIs: test_calib.ml Install: false BuildDepends: cv + +Executable "test_homography" + Path: test/ + MainIs: test_homography.ml + Install: false + BuildDepends: cv + +Executable "test_detect_ellipse" + Path: test/ + MainIs: test_detect_ellipse.ml + Install: false + BuildDepends: cv + +Executable "test_houghLines" + Path: test/ + MainIs: test_houghLines.ml + Install: false + BuildDepends: cv + +Executable "test_contour_canny" + Path: test/ + MainIs: test_contour_canny.ml + Install: false + BuildDepends: cv + +Executable "test_detect_lines" + Path: test/ + MainIs: test_detect_lines.ml + Install: false + BuildDepends: cv diff --git a/info/vision/camlcv/_tags b/info/vision/camlcv/_tags index 5e875f3..763c3e7 100644 --- a/info/vision/camlcv/_tags +++ b/info/vision/camlcv/_tags @@ -1,5 +1,5 @@ # OASIS_START -# DO NOT EDIT (digest: c93fc9a48b0322812d7d9f91a98e5b8f) +# DO NOT EDIT (digest: dbce26cf07aa2393b0384ca639ce129c) # Ignore VCS directories, you can use the same kind of rule outside # OASIS_START/STOP if you want to exclude directories that contains # useless stuff for the build process @@ -23,33 +23,64 @@ "src/libcv_stubs.a": oasis_library_cv_cclib "src/dllcv_stubs.so": oasis_library_cv_cclib <src/cv.{cma,cmxa}>: use_libcv_stubs +<src/*.ml{,i}>: pkg_str <src/*.ml{,i}>: pkg_bigarray +"src/cv_caml.c": pkg_str "src/cv_caml.c": pkg_bigarray # Executable test_threshold "test/test_threshold.byte": use_cv +"test/test_threshold.byte": pkg_str "test/test_threshold.byte": pkg_bigarray +# Executable test_detect_lines +"test/test_detect_lines.byte": use_cv +"test/test_detect_lines.byte": pkg_str +"test/test_detect_lines.byte": pkg_bigarray # Executable leak "test/leak.byte": use_cv +"test/leak.byte": pkg_str "test/leak.byte": pkg_bigarray +# Executable test_houghLines +"test/test_houghLines.byte": use_cv +"test/test_houghLines.byte": pkg_str +"test/test_houghLines.byte": pkg_bigarray # Executable test_find_chessboard_corners "test/test_find_chessboard_corners.byte": use_cv +"test/test_find_chessboard_corners.byte": pkg_str "test/test_find_chessboard_corners.byte": pkg_bigarray +# Executable test_detect_ellipse +"test/test_detect_ellipse.byte": use_cv +"test/test_detect_ellipse.byte": pkg_str +"test/test_detect_ellipse.byte": pkg_bigarray # Executable test_improcess "test/test_improcess.byte": use_cv +"test/test_improcess.byte": pkg_str "test/test_improcess.byte": pkg_bigarray # Executable test_good_feature_to_track "test/test_good_feature_to_track.byte": use_cv +"test/test_good_feature_to_track.byte": pkg_str "test/test_good_feature_to_track.byte": pkg_bigarray +# Executable test_homography +"test/test_homography.byte": use_cv +"test/test_homography.byte": pkg_str +"test/test_homography.byte": pkg_bigarray # Executable test_drawing "test/test_drawing.byte": use_cv +"test/test_drawing.byte": pkg_str "test/test_drawing.byte": pkg_bigarray # Executable test_split "test/test_split.byte": use_cv +"test/test_split.byte": pkg_str "test/test_split.byte": pkg_bigarray +# Executable test_contour_canny +"test/test_contour_canny.byte": use_cv +"test/test_contour_canny.byte": pkg_str +"test/test_contour_canny.byte": pkg_bigarray # Executable test_calib "test/test_calib.byte": use_cv +"test/test_calib.byte": pkg_str "test/test_calib.byte": pkg_bigarray <test/*.ml{,i}>: use_cv +<test/*.ml{,i}>: pkg_str <test/*.ml{,i}>: pkg_bigarray # OASIS_STOP <src/*>: use_C_opencv diff --git a/info/vision/camlcv/myocamlbuild.ml b/info/vision/camlcv/myocamlbuild.ml index f231df6..8a82ba6 100644 --- a/info/vision/camlcv/myocamlbuild.ml +++ b/info/vision/camlcv/myocamlbuild.ml @@ -1,5 +1,5 @@ (* OASIS_START *) -(* DO NOT EDIT (digest: 4a00093589bdfb2586c46078313938d7) *) +(* DO NOT EDIT (digest: 956f5288d32a7a1c8abb0d0365a3324e) *) module OASISGettext = struct # 21 "/media/data/ocaml/oasis/src/oasis/OASISGettext.ml" @@ -556,6 +556,8 @@ let package_default = S [ A "-ccopt"; + A "-g"; + A "-ccopt"; A "-x"; A "-ccopt"; A "c++"; @@ -574,10 +576,12 @@ let package_default = let dispatch_default = MyOCamlbuildBase.dispatch_default package_default;; -# 578 "myocamlbuild.ml" +# 580 "myocamlbuild.ml" (* OASIS_STOP *) open Ocamlbuild_plugin +let () = Ocamlbuild_pack.Log.classic_display := true + let pkg_config flags package = with_temp_file "lwt" "pkg-config" (fun tmp -> @@ -593,6 +597,8 @@ let define_c_library ?(cplusplus=false) ~name ~c_name () = (* Add flags for linking with the C library: *) flag ["ocamlmklib"; "c"; tag] & S lib; + (* flag ["ocamlmklib"; "c"] & S[A"-verbose"]; *) + (* C stubs using the C library must be compiled with the library specifics flags: *) flag ["c"; "compile"; tag] & S(List.map (fun arg -> S[A"-ccopt"; arg]) opt); diff --git a/info/vision/camlcv/src/META b/info/vision/camlcv/src/META index 26e4895..320d2e5 100644 --- a/info/vision/camlcv/src/META +++ b/info/vision/camlcv/src/META @@ -1,8 +1,8 @@ # OASIS_START -# DO NOT EDIT (digest: 3f508b1b1a49417ae0d748f2f8bc10e1) +# DO NOT EDIT (digest: 74e425b91260fb882dfbdc09cc41cc88) version = "0.1" description = "Core Opencv" -requires = "bigarray" +requires = "bigarray str" archive(byte) = "cv.cma" archive(native) = "cv.cmxa" exists_if = "cv.cma" diff --git a/info/vision/camlcv/src/cvCore.ml b/info/vision/camlcv/src/cvCore.ml index 810965f..c77548b 100644 --- a/info/vision/camlcv/src/cvCore.ml +++ b/info/vision/camlcv/src/cvCore.ml @@ -6,6 +6,26 @@ type color_conversion_ (* int *) type channel_num_ = [ `Channel_1 | `Channel_2 | `Channel_3 | `Channel_4 ] type 'a channel_num = int +type cvScalar = float * float * float * float +type cvPoint = int * int +type cvPoint2D32f = float * float +type cvPoint3D32f = float * float * float +type cvPoint2D64f = float * float +type cvPoint3D64f = float * float * float +type cvSize = int * int +type cvTermCriteria = + { termcrit_iter : bool; + termcrit_epsilon : bool; + max_iter : int; + epsilon : float; } +type vec3f = float * float * float +type vec4f = float * float * float * float +type vec4i = int * int * int * int + +type vec3f_vect +type vec4f_vect +type vec4i_vect + let channel_1 = 1 let channel_2 = 2 let channel_3 = 3 @@ -215,6 +235,26 @@ external adaptive_threshold' : ('a,'b) iplImage -> ('d,'e) iplImage -> float -> external canny' : ([`Channel_1],[`U8]) iplImage -> ([`Channel_1],[`U8]) iplImage -> float -> float -> int -> unit = "ocaml_cvCanny" +external blur' : ('a,'b) iplImage -> ('a,'b) iplImage -> cvSize -> unit = "ocaml_blur" +external gaussian_blur' : ('a,'b) iplImage -> ('a,'b) iplImage -> cvSize -> float -> + float -> unit = "ocaml_GaussianBlur" +external median_blur' : ('a,'b) iplImage -> ('a,'b) iplImage -> int -> unit = "ocaml_medianBlur" + +external equalize_hist' : ([`Channel_1],[`U8]) iplImage -> + ([`Channel_1],[`U8]) iplImage -> unit = "ocaml_cvEqualizeHist" + +type morph_shape = + | MORPH_RECT + | MORPH_ELLIPSE + | MORPH_CROSS + +external dilate' : ('a,[`U8]) iplImage -> + ('a,[`U8]) iplImage -> morph_shape -> cvSize -> int -> unit + = "ocaml_dilate" + +external erode' : ('a,[`U8]) iplImage -> + ('a,[`U8]) iplImage -> morph_shape -> cvSize -> int -> unit + = "ocaml_erode" external cvSplit : ('a,'b) iplImage -> ([`Channel_1],'b) iplImage option -> ([`Channel_1],'b) iplImage option -> ([`Channel_1],'b) iplImage option -> @@ -278,14 +318,77 @@ let canny src ?(apertureSize=3) th1 th2 = canny' src dst th1 th2 apertureSize; dst +let blur ?(size=(3,3)) src = + let dst = create_image_from src in + blur' src dst size; + dst + +let gaussian_blur ?(size=(3,3)) src sigmaX sigmaY = + let dst = create_image_from src in + gaussian_blur' src dst size sigmaX sigmaY; + dst + +let median_blur ?(size=3) src = + let dst = create_image_from src in + median_blur' src dst size; + dst + +let equalize_hist src = + let dst = create_image_from src in + equalize_hist' src dst; + dst + +let dilate ?(iter=1) ?(shape=MORPH_ELLIPSE) src size = + let dst = create_image_from src in + dilate' src dst shape size iter; + dst + +let erode ?(iter=1) ?(shape=MORPH_ELLIPSE) src size = + let dst = create_image_from src in + erode' src dst shape size iter; + dst + type image_data = (int, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array2.t external image_data : ('a,[`U8]) iplImage -> image_data = "ocaml_image_to_bigarray" +(* +let between src min max = + let dst = create_image_from ~channels:1 ~depth:8 src in + let data_src = image_data src in + let data_dst = image_data dst in + let x, y = Bigarray.Array2.dim1 data_src, + Bigarray.Array2.dim2 data_src in + for i = 0 to x - 1 do + for j = 0 to y - 1 do + let r = Bigarray.Array2.unsafe_get data_src i j in + Bigarray.Array2.unsafe_set data_dst i j (if r >= min && r < max then 255 else 0); + done + done; + dst +*) + external zero_image : ('a,'b) iplImage -> unit = "ocaml_cvZero" external clone_image : ('a,'b) iplImage -> ('a,'b) iplImage = "ocaml_cvCloneImage" +external copy' : ('a,'b) iplImage -> ('a,'b) iplImage -> ([`Channel_1],[`U8]) iplImage option -> unit + = "ocaml_cvCopy" + +let copy src mask = + let dst = create_image_from src in + zero_image dst; + copy' src dst mask; + dst + +external set : ('a,'b) iplImage -> cvScalar -> ([`Channel_1],[`U8]) iplImage option -> unit + = "ocaml_cvSet" + +let between src min max = + let i_max = threshold src (float max -. 1.) 255. CV_THRESH_BINARY_INV in + let i_min = threshold src (float min -. 1.) 255. CV_THRESH_BINARY in + copy i_max (Some i_min) + let create_image ~x ~y _type i = cvCreateImage (x,y) (get_cvType _type) i let convert_color' ~src ~dst color_conversion = @@ -299,27 +402,21 @@ let convert_color src color_conversion = cvCvtColor src dst (get_color_conversion color_conversion); dst -type cvScalar = float * float * float * float -type cvPoint = int * int -type cvPoint2D32f = float * float -type cvPoint3D32f = float * float * float -type cvPoint2D64f = float * float -type cvPoint3D64f = float * float * float -type cvSize = int * int -type cvTermCriteria = - { termcrit_iter : bool; - termcrit_epsilon : bool; - max_iter : int; - epsilon : float; } -type vec3f = float * float * float - -type vec3f_vect - external create_vec3f_vect : unit -> vec3f_vect = "ocaml_create_Vec3f_vector" external vec3f_vect_size : vec3f_vect -> int = "ocaml_vector_size_Vec3f" external vec3f_vect_add : vec3f_vect -> vec3f -> unit = "ocaml_vector_add_Vec3f" external vec3f_vect_get : vec3f_vect -> int -> vec3f = "ocaml_vector_get_Vec3f" +external create_vec4f_vect : unit -> vec4f_vect = "ocaml_create_Vec4f_vector" +external vec4f_vect_size : vec4f_vect -> int = "ocaml_vector_size_Vec4f" +external vec4f_vect_add : vec4f_vect -> vec4f -> unit = "ocaml_vector_add_Vec4f" +external vec4f_vect_get : vec4f_vect -> int -> vec4f = "ocaml_vector_get_Vec4f" + +external create_vec4i_vect : unit -> vec4i_vect = "ocaml_create_Vec4i_vector" +external vec4i_vect_size : vec4i_vect -> int = "ocaml_vector_size_Vec4i" +external vec4i_vect_add : vec4i_vect -> vec4i -> unit = "ocaml_vector_add_Vec4i" +external vec4i_vect_get : vec4i_vect -> int -> vec4i = "ocaml_vector_get_Vec4i" + external cvCircle : ('a,[`U8]) iplImage -> cvPoint -> int -> cvScalar -> int -> unit = "ocaml_cvCircle" external cvEllipse : ('a,[`U8]) iplImage -> cvPoint -> cvSize -> float -> float -> float -> cvScalar -> int -> unit = @@ -344,7 +441,11 @@ let circle dst ?(thickness=1) ?(color=blue) center radius = let ellipse dst ?(thickness=1) ?(color=blue) ?(angle=0.) ?(start_angle=0.) ?(end_angle=360.) center size = - cvEllipse dst center size angle start_angle end_angle (scalar_color color) thickness + let (x,y) = center in + let (w,h) = size in + (* try to avoid segfault in opencv drawing... *) + if x > 10000 || y > 10000 || w > 10000 || h > 10000 then () + else cvEllipse dst center size angle start_angle end_angle (scalar_color color) thickness type ellipse = { ellipse_center : float * float; @@ -359,8 +460,9 @@ let ellipse' dst ?thickness ?color ?start_angle ?end_angle ellipse_angle = angle; } = ellipse dst ?thickness ?color ?start_angle ?end_angle + ~angle (int_of_float x, int_of_float y) - (int_of_float w, int_of_float h) + (int_of_float (w/.2.), int_of_float (h/.2.)) let rectangle dst ?(thickness=1) ?(color=blue) p1 p2 = cvRectangle dst p1 p2 (scalar_color color) thickness @@ -394,7 +496,7 @@ type contour_approximation_method = type cvSeq external cvFindContours : ([`Channel_1],[`U8]) iplImage -> cvMemStorage -> - contour_retrieval_mode -> contour_approximation_method -> cvPoint -> cvSeq = + contour_retrieval_mode -> contour_approximation_method -> cvPoint -> cvSeq option = "ocaml_cvFindContours" type cvSeq_info = { @@ -406,40 +508,60 @@ type cvSeq_info = { external cvSeq_info : cvSeq -> cvSeq_info = "ocaml_CvSeq_info" -type seq = { +type contour = { seq_stor : cvMemStorage; seq : cvSeq; } -type seq_info = { - h_prev : seq option; - h_next : seq option; - v_prev : seq option; - v_next : seq option; +type contour_info = { + h_prev : contour option; + h_next : contour option; + v_prev : contour option; + v_next : contour option; } let add_stor s = function | None -> None | Some v -> Some { seq_stor = s; seq = v } -let seq_info seq = +let contour_info seq = let info = cvSeq_info seq.seq in { h_prev = add_stor seq.seq_stor info.cv_h_prev; h_next = add_stor seq.seq_stor info.cv_h_next; v_prev = add_stor seq.seq_stor info.cv_v_prev; v_next = add_stor seq.seq_stor info.cv_v_next; } +type contours = Contour of (contour * contours list) + +let rec contour_list contour = + let { h_next } = contour_info contour in + match h_next with + | None -> [contour] + | Some v -> contour::(contour_list v) + +let rec contours c = + match c with + | None -> [] + | Some c -> + let l = contour_list c in + let aux c = Contour (c,contours (contour_info c).v_next) in + List.map aux l + let find_contours ?(mode=CV_RETR_LIST) ?(meth=CV_CHAIN_APPROX_SIMPLE) image = let stor = create_CvMemStorage () in - let cvSeq = cvFindContours image stor mode meth (0,0) in - { seq_stor = stor; - seq = cvSeq } + match cvFindContours image stor mode meth (0,0) with + | Some cvSeq -> + Some { seq_stor = stor; + seq = cvSeq } + | None -> None external cvDrawContours : ('a,[`U8]) iplImage -> cvSeq -> cvScalar -> cvScalar -> int -> int -> cvPoint -> unit = "ocaml_cvDrawContours_bytecode" "ocaml_cvDrawContours" -let draw_contours image seq in_color out_color level thickness offset = - cvDrawContours image seq.seq in_color out_color level thickness offset +let draw_contours ?(in_color=red) ?(out_color=green) ?(thickness=1) ?(offset=(0,0)) + ?(level=0) image seq = + cvDrawContours image seq.seq + (scalar_color in_color) (scalar_color out_color) level thickness offset external cvFitEllipse2 : cvSeq -> (float * float * float * float * float) option = "ocaml_cvFitEllipse2" @@ -482,6 +604,17 @@ let houghCircles img ?(param1=100.) ?(param2=100.) ?(minRadius=0) ?(maxRadius=0) houghCircles' img vec dp minDist param1 param2 minRadius maxRadius; Array.init (vec3f_vect_size vec) (fun i -> vec3f_vect_get vec i) +external houghLinesP' : + ('a,[`U8]) iplImage -> + vec4i_vect -> + float -> float -> int -> float -> float -> unit + = "ocaml_HoughLinesP_bytecode" "ocaml_HoughLinesP" + +let houghLinesP img ?(minLineLength=0.) ?(maxLineGap=0.) rho theta threshold = + let vec = create_vec4i_vect () in + houghLinesP' img vec rho theta threshold minLineLength maxLineGap; + Array.init (vec4i_vect_size vec) (fun i -> vec4i_vect_get vec i) + type calib_cb = | CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_NORMALIZE_IMAGE @@ -658,3 +791,69 @@ external cvFindHomography : [`Channel_1] cvMat_float64 -> unit = "ocaml_cvFindHomography" + +let find_homography ~obj_pos ~img_pos = + let convert a = + Bigarray.Array3.of_array Bigarray.float64 Bigarray.c_layout + [|Array.map (fun (x,y) -> [|x;y|]) a|] in + let out = + Bigarray.Array3.of_array Bigarray.float64 Bigarray.c_layout + (Array.init 3 (fun _ -> Array.init 3 (fun _ -> [|0.|]))) in + cvFindHomography (convert obj_pos) (convert img_pos) out; + Array.init 3 (fun i -> Array.init 3 (fun j -> out.{i,j,0})) + +let replace_comma = + let r = Str.regexp "," in + Str.global_replace r "." + +let file_string file = + let file = open_in file in + let l = in_channel_length file in + let s = String.create l in + ignore(Pervasives.input file s 0 l); + s + +let load_calibration_file file = + let f s = Scanf.sscanf (replace_comma s) " %f %f %f\n %f %f %f\n %f %f %f\n\n %f %f %f %f %f" + (fun v11 v12 v13 v21 v22 v23 v31 v32 v33 + v1 v2 v3 v4 v5 -> + [|[|v11;v12;v13|]; + [|v21;v22;v23|]; + [|v31;v32;v33|]|], + [|v1;v2;v3;v4;v5|]) in + + let s = file_string file in + f s + +let load_homography_file file = + let f s = Scanf.sscanf (replace_comma s) " %f %f %f\n %f %f %f\n %f %f %f" + (fun v11 v12 v13 v21 v22 v23 v31 v32 v33 -> + [|[|v11;v12;v13|]; + [|v21;v22;v23|]; + [|v31;v32;v33|]|]) in + + let s = file_string file in + f s + + +external cvInvert : + [`Channel_1] cvMat_float64 -> + [`Channel_1] cvMat_float64 -> + float + = "ocaml_cvInvert" + +let invert src = + let src' = Array.map (fun e -> Array.map (fun x -> [|x|]) e) src in + let src_ba = Bigarray.Array3.of_array Bigarray.float64 Bigarray.c_layout src' in + let i = Bigarray.Array3.dim1 src_ba in + let j = Bigarray.Array3.dim2 src_ba in + let dst_ba = Bigarray.Array3.create Bigarray.float64 Bigarray.c_layout j i 1 in + let det = cvInvert src_ba dst_ba in + let dst = Array.init j + (fun x -> Array.init i (fun y -> dst_ba.{x,y,0})) in + det, dst + +let mult m v = + Array.init (Array.length m) + (fun k -> Array.fold_left (+.) 0. + (Array.mapi (fun i n -> v.(i) *. n) m.(k))) diff --git a/info/vision/camlcv/src/cvCore.mli b/info/vision/camlcv/src/cvCore.mli index 3aa6239..9c559f3 100644 --- a/info/vision/camlcv/src/cvCore.mli +++ b/info/vision/camlcv/src/cvCore.mli @@ -12,6 +12,8 @@ type cvTermCriteria = max_iter : int; epsilon : float; } type vec3f = float * float * float +type vec4f = float * float * float * float +type vec4i = int * int * int * int type ('chan_num,'depth) iplImage @@ -35,6 +37,15 @@ val create_image : x:int -> y:int -> 'depth image_depth -> 'chan_num channel_num val clone_image : ('a,'b) iplImage -> ('a,'b) iplImage val zero_image : ('a,'b) iplImage -> unit +val copy' : ('a,'b) iplImage -> ('a,'b) iplImage -> + ([`Channel_1],[`U8]) iplImage option -> unit + +val copy : ('a,'b) iplImage -> + ([`Channel_1],[`U8]) iplImage option -> ('a,'b) iplImage + +val set : ('a,'b) iplImage -> cvScalar -> + ([`Channel_1],[`U8]) iplImage option -> unit + val image_size : ('a,'b) iplImage -> int * int val image_channels : ('a,'b) iplImage -> int val image_depth : ('a,'b) iplImage -> int @@ -109,6 +120,9 @@ val adaptive_threshold : ([`Channel_1],'b) iplImage -> float -> adaptive_method -> threshold_type -> int -> float -> ([`Channel_1],'b) iplImage (** [adaptive_threshold src maxValue adaptiveMethod thresholdType blockSize param1] *) +val between : ([`Channel_1],[`U8]) iplImage -> int -> int -> ([`Channel_1],[`U8]) iplImage +(** [between src min max] is 255 for each point p when min <= p < max *) + (** edge detection *) val canny' : ([`Channel_1],[`U8]) iplImage -> ([`Channel_1],[`U8]) iplImage -> @@ -118,6 +132,47 @@ val canny : ([ `Channel_1 ], [ `U8 ]) iplImage -> float -> float -> ([ `Channel_1 ], [ `U8 ]) iplImage (** [canny src threshold1 threshold2] *) +(** image processing *) + +val blur' : ('a,'b) iplImage -> ('a,'b) iplImage -> cvSize -> unit +val blur : ?size:cvSize -> ('a, 'b) iplImage -> ('a, 'b) iplImage + +val gaussian_blur' : ('a,'b) iplImage -> ('a,'b) iplImage -> cvSize -> float -> + float -> unit +val gaussian_blur : ?size:cvSize -> ('a,'b) iplImage -> float -> + float -> ('a,'b) iplImage + +val median_blur' : ('a,'b) iplImage -> ('a,'b) iplImage -> int -> unit +val median_blur : ?size:int -> ('a, 'b) iplImage -> ('a, 'b) iplImage + +val equalize_hist' : ([`Channel_1],[`U8]) iplImage -> + ([`Channel_1],[`U8]) iplImage -> unit +val equalize_hist : ([`Channel_1],[`U8]) iplImage -> + ([`Channel_1],[`U8]) iplImage + +type morph_shape = + | MORPH_RECT + | MORPH_ELLIPSE + | MORPH_CROSS + +val dilate' : ('a, [ `U8 ]) iplImage -> + ('a, [ `U8 ]) iplImage -> + morph_shape -> cvSize -> int -> unit + +val erode' : ('a, [ `U8 ]) iplImage -> + ('a, [ `U8 ]) iplImage -> + morph_shape -> cvSize -> int -> unit + +val dilate : ?iter:int -> + ?shape:morph_shape -> + ('a, [ `U8 ]) iplImage -> + cvSize -> ('a, [ `U8 ]) iplImage + +val erode : ?iter:int -> + ?shape:morph_shape -> + ('a, [ `U8 ]) iplImage -> + cvSize -> ('a, [ `U8 ]) iplImage + (** drawing *) type color = int * int * int (** red, green, blue *) @@ -188,22 +243,32 @@ type contour_approximation_method = | CV_CHAIN_APPROX_TC89_KCOS | CV_LINK_RUNS -type seq +type contour -type seq_info = { - h_prev : seq option; - h_next : seq option; - v_prev : seq option; - v_next : seq option; +type contour_info = { + h_prev : contour option; + h_next : contour option; + v_prev : contour option; + v_next : contour option; } -val seq_info : seq -> seq_info +type contours = Contour of (contour * contours list) + +val contours : contour option -> contours list + +val contour_info : contour -> contour_info val find_contours : ?mode:contour_retrieval_mode -> ?meth:contour_approximation_method -> - ([`Channel_1],[`U8]) iplImage -> seq + ([`Channel_1],[`U8]) iplImage -> contour option -val draw_contours : ('a,[`U8]) iplImage -> seq -> cvScalar -> cvScalar -> int -> int -> cvPoint -> unit +val draw_contours : + ?in_color:color -> + ?out_color:color -> + ?thickness:int -> + ?offset:cvPoint -> + ?level:int -> + ('a, [ `U8 ]) iplImage -> contour -> unit -val fit_ellipse : seq -> ellipse option +val fit_ellipse : contour -> ellipse option val good_features_to_track : ([ `Channel_1 ], 'a) iplImage -> @@ -221,6 +286,12 @@ val good_features_to_track : ?minRadius:int -> ?maxRadius:int -> float -> float -> vec3f array (** [houghCircles img dp minDist] *) + val houghLinesP : + ('a, [ `U8 ]) iplImage -> + ?minLineLength:float -> + ?maxLineGap:float -> float -> float -> int -> vec4i array +(** [houghLinesP img rho theta threshold] *) + type calib_cb = | CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_NORMALIZE_IMAGE @@ -249,21 +320,18 @@ val add_calibration_image : calibration -> ([ `Channel_1 ], [ `U8 ]) iplImage -> calibration val calibrate : calibration -> float * ( float array array * float array ) +val load_calibration_file : string -> ( float array array * float array ) +val load_homography_file : string -> float array array + type remap val init_undistort_map : cvSize -> ( float array array * float array ) -> remap val remap' : remap -> ('a, 'b) iplImage -> ('a, 'b) iplImage -> unit val remap : remap -> ('a, 'b) iplImage -> ('a, 'b) iplImage -type ('channel) cvMat_float32 = - (float, Bigarray.float32_elt, Bigarray.c_layout) Bigarray.Array3.t +val find_homography : obj_pos: (float*float) array -> img_pos: (float*float) array -> + float array array -type ('channel) cvMat_float64 = - (float, Bigarray.float64_elt, Bigarray.c_layout) Bigarray.Array3.t +val invert : float array array -> float * float array array -external cvFindHomography : - [`Channel_2] cvMat_float64 -> - [`Channel_2] cvMat_float64 -> - [`Channel_1] cvMat_float64 -> - unit - = "ocaml_cvFindHomography" +val mult : float array array -> float array -> float array diff --git a/info/vision/camlcv/src/cvHighGui.ml b/info/vision/camlcv/src/cvHighGui.ml index e10f58f..3fffc22 100644 --- a/info/vision/camlcv/src/cvHighGui.ml +++ b/info/vision/camlcv/src/cvHighGui.ml @@ -20,6 +20,8 @@ external cvLoadImage : string -> iscolor_ -> ('a,'b) iplImage = "ocaml_cvLoadIma let load_image file iscolor = cvLoadImage file (get_iscolor iscolor) +external save_image : string -> ('a,'b) iplImage -> int = "ocaml_cvSaveImage" + (* capture *) type cvCapture diff --git a/info/vision/camlcv/src/cvHighGui.mli b/info/vision/camlcv/src/cvHighGui.mli index 6e54b60..563d928 100644 --- a/info/vision/camlcv/src/cvHighGui.mli +++ b/info/vision/camlcv/src/cvHighGui.mli @@ -8,6 +8,7 @@ val load_color : [`Channel_3] load_color val load_grayscale : [`Channel_1] load_color val load_image : string -> 'depth load_color -> ('depth,[`U8]) iplImage +val save_image : string -> ('a,'b) iplImage -> int (** camera capture *) diff --git a/info/vision/camlcv/src/cv_caml.c b/info/vision/camlcv/src/cv_caml.c index a49aaf1..f7a0a55 100644 --- a/info/vision/camlcv/src/cv_caml.c +++ b/info/vision/camlcv/src/cv_caml.c @@ -35,6 +35,17 @@ catch (const cv::Exception &e) \ caml_failwith(e.what()); \ } +static value Val_some(value v) +{ + CAMLparam1(v); + CAMLlocal1(res); + res = caml_alloc(1,0); + Field(res,0) = v; + CAMLreturn(res); +} + +static value Val_none = Val_unit; + static Vec3f Vec3f_val(value v) { double v0 = Double_val(Field(v,0)); double v1 = Double_val(Field(v,1)); @@ -52,6 +63,42 @@ static value Val_Vec3f(Vec3f v) { CAMLreturn(res); } +static Vec4f Vec4f_val(value v) { + double v0 = Double_val(Field(v,0)); + double v1 = Double_val(Field(v,1)); + double v2 = Double_val(Field(v,2)); + double v3 = Double_val(Field(v,3)); + return (Vec4f(v0,v1,v2,v3)); +} + +static value Val_Vec4f(Vec4f v) { + CAMLparam0(); + CAMLlocal1(res); + res = caml_alloc_tuple(4); + for(int i = 0; i < 4; i++) { + Field(res,i) = caml_copy_double(v[i]); + } + CAMLreturn(res); +} + +static Vec4i Vec4i_val(value v) { + int v0 = Int_val(Field(v,0)); + int v1 = Int_val(Field(v,1)); + int v2 = Int_val(Field(v,2)); + int v3 = Int_val(Field(v,3)); + return (Vec4i(v0,v1,v2,v3)); +} + +static value Val_Vec4i(Vec4i v) { + CAMLparam0(); + CAMLlocal1(res); + res = caml_alloc_tuple(4); + for(int i = 0; i < 4; i++) { + Field(res,i) = Val_int(v[i]); + } + CAMLreturn(res); +} + /* c++ vector */ template <typename Type> @@ -158,6 +205,48 @@ extern "C" CAMLprim value ocaml_vector_get_Vec3f(value v, value x) CAMLreturn(Val_Vec3f(r)); } +extern "C" CAMLprim value ocaml_create_Vec4f_vector(value v) +{ + return(ocaml_create_vector<Vec4f>(v)); +} + +extern "C" CAMLprim value ocaml_vector_size_Vec4f(value v) +{ + return(ocaml_vector_size<Vec4f>(v)); +} + +extern "C" CAMLprim value ocaml_vector_add_Vec4f(value v, value x) +{ + return(ocaml_vector_add<Vec4f>(v,x,Vec4f_val(x))); +} +extern "C" CAMLprim value ocaml_vector_get_Vec4f(value v, value x) +{ + CAMLparam2(v,x); + Vec4f r = ocaml_vector_get<Vec4f>(v,x); + CAMLreturn(Val_Vec4f(r)); +} + +extern "C" CAMLprim value ocaml_create_Vec4i_vector(value v) +{ + return(ocaml_create_vector<Vec4i>(v)); +} + +extern "C" CAMLprim value ocaml_vector_size_Vec4i(value v) +{ + return(ocaml_vector_size<Vec4i>(v)); +} + +extern "C" CAMLprim value ocaml_vector_add_Vec4i(value v, value x) +{ + return(ocaml_vector_add<Vec4i>(v,x,Vec4i_val(x))); +} +extern "C" CAMLprim value ocaml_vector_get_Vec4i(value v, value x) +{ + CAMLparam2(v,x); + Vec4i r = ocaml_vector_get<Vec4i>(v,x); + CAMLreturn(Val_Vec4i(r)); +} + /* basic caml value conversions */ static CvScalar CvScalar_val(value v) { @@ -284,7 +373,7 @@ static CvMat CvMat_val(value v) { return (cvMat(rows, cols, type, data)); } -int cvType_table[] = { +uint cvType_table[] = { IPL_DEPTH_1U, IPL_DEPTH_8U, IPL_DEPTH_16U, @@ -410,16 +499,47 @@ extern "C" CAMLprim value ocaml_cvLoadImage(value vfile, value viscolor) CAMLreturn (res); } +extern "C" CAMLprim value ocaml_cvSaveImage(value vfile, value vimg) +{ + CAMLparam2 (vfile, vimg); + + int ret = cvSaveImage(String_val(vfile), + Image_val(vimg)->image); + + CAMLreturn (Val_int(ret)); +} + extern "C" CAMLprim value ocaml_cvCloneImage(value vimage) { CAMLparam1 (vimage); CAMLlocal1 (res); IplImage* image = cvCloneImage( Image_val(vimage)->image ); - if(image == 0) { caml_failwith("load_image: can't load image"); }; res = caml_alloc_IplImage(image); CAMLreturn (res); } +extern "C" CAMLprim value ocaml_cvCopy(value vsrc, value vdst, value vmask) +{ + CAMLparam3 (vsrc, vdst, vmask); + CvArr* mask = Is_long(vmask) ? NULL : Image_val(Field(vmask,0))->image; + ERRWRAP( + cvCopy(Image_val(vsrc)->image, + Image_val(vdst)->image, + mask)); + CAMLreturn (Val_unit); +} + +extern "C" CAMLprim value ocaml_cvSet(value vdst, value vval, value vmask) +{ + CAMLparam3 (vdst, vval, vmask); + CvArr* mask = Is_long(vmask) ? NULL : Image_val(Field(vmask,0))->image; + ERRWRAP( + cvSet(Image_val(vdst)->image, + CvScalar_val(vval), + mask)); + CAMLreturn (Val_unit); +} + extern "C" CAMLprim value ocaml_cvZero(value vimage) { CAMLparam1 (vimage); @@ -672,8 +792,10 @@ extern "C" CAMLprim value ocaml_set_int_var(value vvar, value vval) extern "C" CAMLprim value ocaml_cvCreateTrackbar(value vname, value vwindow, value vvar, value vmax) { CAMLparam4 (vname, vwindow, vvar, vmax); - int res = cvCreateTrackbar(String_val(vname), String_val(vwindow), - Int_var_val(vvar), Int_val(vmax), NULL); + int res; + ERRWRAP( + res = cvCreateTrackbar(String_val(vname), String_val(vwindow), + Int_var_val(vvar), Int_val(vmax), NULL)); CAMLreturn (Val_int(res)); } @@ -867,7 +989,65 @@ extern "C" CAMLprim value ocaml_cvCanny(value vimage, value vedges, CAMLreturn(Val_unit); } -/* +extern "C" CAMLprim value ocaml_cvEqualizeHist(value vsrc, value vdst) +{ + CAMLparam2 (vsrc, vdst); + + ERRWRAP( + cvEqualizeHist(Image_val(vsrc)->image, + Image_val(vdst)->image)); + CAMLreturn (Val_unit); +} + + +int morph_table[] = { + MORPH_RECT, + MORPH_ELLIPSE, + MORPH_CROSS +}; + +extern "C" CAMLprim value ocaml_dilate(value vsrc, value vdst, value shape, + value ksize, value viter) +{ + CAMLparam5 (vsrc, vdst, shape, ksize, viter); + + Mat sel = getStructuringElement(morph_table[Int_val(shape)], + CvSize_val(ksize)); + + Mat src = Mat(Image_val(vsrc)->image); + Mat dst = Mat(Image_val(vdst)->image); + + ERRWRAP( + dilate(src, + dst, + sel, + Point(-1,-1), + Int_val(viter))); + + CAMLreturn (Val_unit); +} + +extern "C" CAMLprim value ocaml_erode(value vsrc, value vdst, value shape, + value ksize, value viter) +{ + CAMLparam5 (vsrc, vdst, shape, ksize, viter); + + Mat sel = getStructuringElement(morph_table[Int_val(shape)], + CvSize_val(ksize)); + + Mat src = Mat(Image_val(vsrc)->image); + Mat dst = Mat(Image_val(vdst)->image); + + ERRWRAP( + erode(src, + dst, + sel, + Point(-1,-1), + Int_val(viter))); + + CAMLreturn (Val_unit); +} + extern "C" CAMLprim value ocaml_medianBlur(value vsrc, value vdst, value ksize) { CAMLparam3(vsrc, vdst, ksize); @@ -876,12 +1056,43 @@ extern "C" CAMLprim value ocaml_medianBlur(value vsrc, value vdst, value ksize) ERRWRAP( medianBlur(Mat(Image_val(vsrc)->image), - &dst, + dst, Int_val(ksize))); CAMLreturn(Val_unit); } -*/ + +extern "C" CAMLprim value ocaml_blur(value vsrc, value vdst, value ksize) +{ + CAMLparam3(vsrc, vdst, ksize); + + Mat dst = Mat(Image_val(vdst)->image); + + ERRWRAP( + blur(Mat(Image_val(vsrc)->image), + dst, + CvSize_val(ksize))); + + CAMLreturn(Val_unit); +} + +extern "C" CAMLprim value ocaml_GaussianBlur(value vsrc, value vdst, value ksize, + value sigmaX, value sigmaY) +{ + CAMLparam5(vsrc, vdst, ksize, sigmaX, sigmaY); + + Mat dst = Mat(Image_val(vdst)->image); + + ERRWRAP( + GaussianBlur(Mat(Image_val(vsrc)->image), + dst, + CvSize_val(ksize), + Double_val(sigmaX), + Double_val(sigmaY))); + + CAMLreturn(Val_unit); +} + extern "C" CAMLprim value ocaml_cvGoodFeaturesToTrack( value image, @@ -976,9 +1187,10 @@ extern "C" CAMLprim value ocaml_cvEllipse(value vimg, value vcenter, { CAMLparam5(vimg, vcenter, vaxes, vangle, vstart_angle); CAMLxparam3(vend_angle, vcolor, vthickness); + ERRWRAP( cvEllipse(Image_val(vimg)->image, CvPoint_val(vcenter), CvSize_val(vaxes), Double_val(vangle), Double_val(vstart_angle), Double_val(vend_angle), - CvScalar_val(vcolor), Int_val(vthickness), CV_AA, 0); + CvScalar_val(vcolor), Int_val(vthickness), CV_AA, 0)); CAMLreturn(Val_unit); } @@ -1061,7 +1273,12 @@ extern "C" CAMLprim value ocaml_cvFindContours(value vimg, value vstor, value vm contour_approximation_method_table[Int_val(vmethod)], CvPoint_val(voffset))); - res = caml_alloc_cvSeq(first_contour); + if(first_contour) { + res = Val_some(caml_alloc_cvSeq(first_contour)); + } + else { + res = Val_none; + } CAMLreturn(res); } @@ -1098,21 +1315,42 @@ extern "C" CAMLprim value ocaml_HoughCircles_bytecode( value * argv, int argn ) argv[4], argv[5], argv[6], argv[7] ); } -static value Val_some(value v) +/* houghlines */ + +extern "C" CAMLprim value ocaml_HoughLinesP(value vimg, + value vlines, + value rho, + value theta, + value threshold, + value minLineLength, + value maxLineGap) { - CAMLparam1(v); - CAMLlocal1(res); - res = caml_alloc(1,0); - Field(res,0) = v; - CAMLreturn(res); + CAMLparam5( vimg, vlines, rho, theta, threshold ); + CAMLxparam2( minLineLength, maxLineGap ); + + ERRWRAP( + HoughLinesP(Mat(Image_val(vimg)->image), + *Vector_val<Vec4i>(vlines), + Double_val(rho), + Double_val(theta), + Int_val(threshold), + Double_val(minLineLength), + Double_val(maxLineGap))); + + CAMLreturn(Val_unit); } -static value Val_none = Val_unit; +extern "C" CAMLprim value ocaml_HoughLinesP_bytecode( value * argv, int argn ) +{ + return ocaml_HoughLinesP( argv[0], argv[1], argv[2], argv[3], + argv[4], argv[5], argv[6] ); +} extern "C" CAMLprim value ocaml_CvSeq_info(value vseq) { CAMLparam1(vseq); CAMLlocal1(res); + CvSeq *seq = CvSeq_val(vseq); res = caml_alloc_tuple(4); @@ -1160,7 +1398,8 @@ extern "C" CAMLprim value ocaml_cvFitEllipse2( value vpoints ) res = caml_alloc_tuple(5); CvSeq *points = CvSeq_val(vpoints); if(points->total < 5) CAMLreturn(Val_none); - CvBox2D box = cvFitEllipse2(points); + CvBox2D box; + ERRWRAP (box = cvFitEllipse2(points)); Field(res,0) = caml_copy_double(box.center.x); Field(res,1) = caml_copy_double(box.center.y); Field(res,2) = caml_copy_double(box.size.width); @@ -1333,3 +1572,15 @@ extern "C" CAMLprim value ocaml_cvFindHomography( value vsrc, value vdst, value CAMLreturn(Val_unit); } + +extern "C" CAMLprim value ocaml_cvInvert( value vsrc, value vdst... [truncated message content] |
From: Pierre C. <Ba...@us...> - 2012-05-12 17:08:00
|
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 35f2720c1b040772eeefd7d06efd6ad4f3be3220 (commit) via b519178ead26f7d6f931e609886b493adf805696 (commit) from 293b6fc50d49888734dcd618762fe9cafff39bfd (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 35f2720c1b040772eeefd7d06efd6ad4f3be3220 Author: chicco <cha...@cr...> Date: Sat May 12 19:07:04 2012 +0200 [camlcv] more tests, catch errors, fix calibration commit b519178ead26f7d6f931e609886b493adf805696 Author: chicco <cha...@cr...> Date: Thu May 10 17:35:35 2012 +0200 [camlcv] easier to use, have tests ----------------------------------------------------------------------- Changes: diff --git a/info/vision/camlcv/_oasis b/info/vision/camlcv/_oasis index e586f57..b4c3985 100644 --- a/info/vision/camlcv/_oasis +++ b/info/vision/camlcv/_oasis @@ -29,5 +29,55 @@ Library "cv" CvHighGui CSources: cv_caml.c + CCopt: -x c++ -O2 + CClib: -lstdc++ XMETADescription: Core Opencv BuildDepends: bigarray + +Executable "leak" + Path: test/ + MainIs: leak.ml + Install: false + BuildDepends: cv + +Executable "test_drawing" + Path: test/ + MainIs: test_drawing.ml + Install: false + BuildDepends: cv + +Executable "test_good_feature_to_track" + Path: test/ + MainIs: test_good_feature_to_track.ml + Install: false + BuildDepends: cv + +Executable "test_improcess" + Path: test/ + MainIs: test_improcess.ml + Install: false + BuildDepends: cv + +Executable "test_split" + Path: test/ + MainIs: test_split.ml + Install: false + BuildDepends: cv + +Executable "test_threshold" + Path: test/ + MainIs: test_threshold.ml + Install: false + BuildDepends: cv + +Executable "test_find_chessboard_corners" + Path: test/ + MainIs: test_find_chessboard_corners.ml + Install: false + BuildDepends: cv + +Executable "test_calib" + Path: test/ + MainIs: test_calib.ml + Install: false + BuildDepends: cv diff --git a/info/vision/camlcv/_tags b/info/vision/camlcv/_tags index b018bdb..5e875f3 100644 --- a/info/vision/camlcv/_tags +++ b/info/vision/camlcv/_tags @@ -1,5 +1,5 @@ # OASIS_START -# DO NOT EDIT (digest: b8f60d120ef9d7618b2ed02d64b8ef03) +# DO NOT EDIT (digest: c93fc9a48b0322812d7d9f91a98e5b8f) # Ignore VCS directories, you can use the same kind of rule outside # OASIS_START/STOP if you want to exclude directories that contains # useless stuff for the build process @@ -15,8 +15,41 @@ "_darcs": not_hygienic # Library cv "src/cv.cmxs": use_cv +<src/*.ml{,i}>: oasis_library_cv_ccopt +"src/cv_caml.c": oasis_library_cv_ccopt +<src/cv.{cma,cmxa}>: oasis_library_cv_cclib +"src/libcv_stubs.lib": oasis_library_cv_cclib +"src/dllcv_stubs.dll": oasis_library_cv_cclib +"src/libcv_stubs.a": oasis_library_cv_cclib +"src/dllcv_stubs.so": oasis_library_cv_cclib <src/cv.{cma,cmxa}>: use_libcv_stubs <src/*.ml{,i}>: pkg_bigarray "src/cv_caml.c": pkg_bigarray +# Executable test_threshold +"test/test_threshold.byte": use_cv +"test/test_threshold.byte": pkg_bigarray +# Executable leak +"test/leak.byte": use_cv +"test/leak.byte": pkg_bigarray +# Executable test_find_chessboard_corners +"test/test_find_chessboard_corners.byte": use_cv +"test/test_find_chessboard_corners.byte": pkg_bigarray +# Executable test_improcess +"test/test_improcess.byte": use_cv +"test/test_improcess.byte": pkg_bigarray +# Executable test_good_feature_to_track +"test/test_good_feature_to_track.byte": use_cv +"test/test_good_feature_to_track.byte": pkg_bigarray +# Executable test_drawing +"test/test_drawing.byte": use_cv +"test/test_drawing.byte": pkg_bigarray +# Executable test_split +"test/test_split.byte": use_cv +"test/test_split.byte": pkg_bigarray +# Executable test_calib +"test/test_calib.byte": use_cv +"test/test_calib.byte": pkg_bigarray +<test/*.ml{,i}>: use_cv +<test/*.ml{,i}>: pkg_bigarray # OASIS_STOP <src/*>: use_C_opencv diff --git a/info/vision/camlcv/myocamlbuild.ml b/info/vision/camlcv/myocamlbuild.ml index ed0acd9..f231df6 100644 --- a/info/vision/camlcv/myocamlbuild.ml +++ b/info/vision/camlcv/myocamlbuild.ml @@ -1,5 +1,5 @@ (* OASIS_START *) -(* DO NOT EDIT (digest: 4691146961f957a78ce95a45557aba80) *) +(* DO NOT EDIT (digest: 4a00093589bdfb2586c46078313938d7) *) module OASISGettext = struct # 21 "/media/data/ocaml/oasis/src/oasis/OASISGettext.ml" @@ -548,14 +548,33 @@ let package_default = { MyOCamlbuildBase.lib_ocaml = [("cv", ["src"])]; lib_c = [("cv", "src/", [])]; - flags = []; - includes = []; + flags = + [ + (["oasis_library_cv_ccopt"; "compile"], + [ + (OASISExpr.EBool true, + S + [ + A "-ccopt"; + A "-x"; + A "-ccopt"; + A "c++"; + A "-ccopt"; + A "-O2" + ]) + ]); + (["oasis_library_cv_cclib"; "link"], + [(OASISExpr.EBool true, S [A "-cclib"; A "-lstdc++"])]); + (["oasis_library_cv_cclib"; "ocamlmklib"; "c"], + [(OASISExpr.EBool true, S [A "-lstdc++"])]) + ]; + includes = [("test", ["src"])]; } ;; let dispatch_default = MyOCamlbuildBase.dispatch_default package_default;; -# 559 "myocamlbuild.ml" +# 578 "myocamlbuild.ml" (* OASIS_STOP *) open Ocamlbuild_plugin diff --git a/info/vision/camlcv/src/cvCore.ml b/info/vision/camlcv/src/cvCore.ml index 155690a..810965f 100644 --- a/info/vision/camlcv/src/cvCore.ml +++ b/info/vision/camlcv/src/cvCore.ml @@ -132,10 +132,89 @@ let rgb2gray = CV_RGB2GRAY let gray2rgb = CV_GRAY2RGB let rgb2rgba = CV_RGB2RGBA +(* zeros are: I don't know *) +let convert_output_channels = function + | CV_BGR2BGRA -> 4 + | CV_RGB2RGBA -> 4 + | CV_BGRA2BGR -> 3 + | CV_RGBA2RGB -> 3 + | CV_BGR2RGBA -> 4 + | CV_RGB2BGRA -> 4 + | CV_RGBA2BGR -> 3 + | CV_BGRA2RGB -> 3 + | CV_BGR2RGB -> 3 + | CV_RGB2BGR -> 3 + | CV_BGRA2RGBA -> 4 + | CV_RGBA2BGRA -> 4 + | CV_BGR2GRAY -> 1 + | CV_RGB2GRAY -> 1 + | CV_GRAY2BGR -> 3 + | CV_GRAY2RGB -> 3 + | CV_GRAY2BGRA -> 4 + | CV_GRAY2RGBA -> 4 + | CV_BGRA2GRAY -> 1 + | CV_RGBA2GRAY -> 1 + | CV_BGR2BGR565 -> 0 + | CV_RGB2BGR565 -> 0 + | CV_BGR5652BGR -> 3 + | CV_BGR5652RGB -> 3 + | CV_BGRA2BGR565 -> 0 + | CV_RGBA2BGR565 -> 0 + | CV_BGR5652BGRA -> 4 + | CV_BGR5652RGBA -> 4 + | CV_GRAY2BGR565 -> 0 + | CV_BGR5652GRAY -> 1 + | CV_BGR2BGR555 -> 0 + | CV_RGB2BGR555 -> 0 + | CV_BGR5552BGR -> 3 + | CV_BGR5552RGB -> 3 + | CV_BGRA2BGR555 -> 0 + | CV_RGBA2BGR555 -> 0 + | CV_BGR5552BGRA -> 4 + | CV_BGR5552RGBA -> 4 + | CV_GRAY2BGR555 -> 0 + | CV_BGR5552GRAY -> 1 + | CV_BGR2XYZ -> 3 + | CV_RGB2XYZ -> 3 + | CV_XYZ2BGR -> 3 + | CV_XYZ2RGB -> 3 + | CV_BGR2YCrCb -> 0 + | CV_RGB2YCrCb -> 0 + | CV_YCrCb2BGR -> 3 + | CV_YCrCb2RGB -> 3 + | CV_BGR2HSV -> 3 + | CV_RGB2HSV -> 3 + | CV_BGR2Lab -> 3 + | CV_RGB2Lab -> 3 + | CV_BayerBG2BGR -> 3 + | CV_BayerGB2BGR -> 3 + | CV_BayerRG2BGR -> 3 + | CV_BayerGR2BGR -> 3 + | CV_BayerBG2RGB -> 3 + | CV_BayerGB2RGB -> 3 + | CV_BayerRG2RGB -> 3 + | CV_BayerGR2RGB -> 3 + | CV_BGR2Luv -> 3 + | CV_RGB2Luv -> 3 + | CV_BGR2HLS -> 3 + | CV_RGB2HLS -> 3 + | CV_HSV2BGR -> 3 + | CV_HSV2RGB -> 3 + | CV_Lab2BGR -> 3 + | CV_Lab2RGB -> 3 + | CV_Luv2BGR -> 3 + | CV_Luv2RGB -> 3 + | CV_HLS2BGR -> 3 + | CV_HLS2RGB -> 3 + + external cvCreateImage : (int*int) -> cvType_ -> int -> ('a,'b) iplImage = "ocaml_cvCreateImage" external cvCvtColor : ('a,'b) iplImage -> ('d,'e) iplImage -> color_conversion_ -> unit = "ocaml_cvCvtColor" -external threshold : ('a,'b) iplImage -> ('d,'e) iplImage -> float -> float -> threshold_type -> unit = "ocaml_cvThreshold" -external adaptive_threshold : ('a,'b) iplImage -> ('d,'e) iplImage -> float -> adaptive_method -> threshold_type -> int -> float -> unit = "ocaml_cvAdaptiveThreshold_bytecode" "ocaml_cvAdaptiveThreshold" +external threshold' : ([`Channel_1],'b) iplImage -> ([`Channel_1],'b) iplImage -> float -> float -> threshold_type -> unit = "ocaml_cvThreshold" +external adaptive_threshold' : ('a,'b) iplImage -> ('d,'e) iplImage -> float -> adaptive_method -> threshold_type -> int -> float -> unit = "ocaml_cvAdaptiveThreshold_bytecode" "ocaml_cvAdaptiveThreshold" + +external canny' : ([`Channel_1],[`U8]) iplImage -> ([`Channel_1],[`U8]) iplImage -> + float -> float -> int -> unit = "ocaml_cvCanny" external cvSplit : ('a,'b) iplImage -> ([`Channel_1],'b) iplImage option -> ([`Channel_1],'b) iplImage option -> ([`Channel_1],'b) iplImage option -> @@ -145,13 +224,8 @@ external cvMerge : ([`Channel_1],'b) iplImage option -> ([`Channel_1],'b) iplIma ([`Channel_1],'b) iplImage option -> ([`Channel_1],'b) iplImage option -> ('a,'b) iplImage -> unit = "ocaml_cvMerge" -let split_3 src c1 c2 c3 = - cvSplit src (Some c1) (Some c2) (Some c3) None - -let merge_3 c1 c2 c3 dst = - cvMerge (Some c1) (Some c2) (Some c3) None dst - external get_cvType : cvType -> cvType_ = "ocaml_get_cvType" +external cvType_int : int -> cvType_ = "%identity" external get_color_conversion : color_conversion -> color_conversion_ = "ocaml_get_color_conversion" external image_size : ('a,'b) iplImage -> (int*int) = "ocaml_image_size" @@ -159,35 +233,50 @@ external image_channels : ('a,'b) iplImage -> int = "ocaml_image_channels" external image_depth : ('a,'b) iplImage -> int = "ocaml_image_depth" external image_data_order : ('a,'b) iplImage -> int = "ocaml_image_data_order" -(* type float_3point = *) -(* { mutable f0 : float; *) -(* mutable f1 : float; *) -(* mutable f2 : float; } *) +let create_image_from ?channels ?depth src = + let size = image_size src in + let type_ = cvType_int (match depth with + | None -> image_depth src + | Some d -> d) in + let channels = match channels with + | None -> image_channels src + | Some c -> c in + cvCreateImage size type_ channels + +let split_3' src c1 c2 c3 = + cvSplit src (Some c1) (Some c2) (Some c3) None -(* type int_3point = *) -(* { mutable i0 : int; *) -(* mutable i1 : int; *) -(* mutable i2 : int; } *) +let split src = + let size = image_size src in + let type_ = cvType_int (image_depth src) in + let c1 = cvCreateImage size type_ 1 in + let c2 = cvCreateImage size type_ 1 in + let c3 = cvCreateImage size type_ 1 in + cvSplit src (Some c1) (Some c2) (Some c3) None; + c1,c2,c3 + +let merge_3' c1 c2 c3 dst = + cvMerge (Some c1) (Some c2) (Some c3) None dst -(* external get_float_3point : *) -(* ([`One],[`F32],[`BGR | `RGB | `HSV ]) iplImage -> *) -(* float_point -> unit *) -(* = "ocaml_get_float_3point" "noalloc" *) +let merge c1 c2 c3 = + let dst = create_image_from ~channels:3 c1 in + cvMerge (Some c1) (Some c2) (Some c3) None dst; + dst -(* external set_float_3point : *) -(* ([`One],[`F32],[`BGR | `RGB | `HSV ]) iplImage -> *) -(* float_point -> unit *) -(* = "ocaml_set_float_3point" "noalloc" *) +let threshold src threshold maxValue thresholdType = + let dst = create_image_from src in + threshold' src dst threshold maxValue thresholdType; + dst -(* external unsafe_get_int_3point : *) -(* ([`One],[`U8],[<`BGR | `RGB | `HSV ]) iplImage -> *) -(* int -> int_3point -> unit *) -(* = "ocaml_get_int_3point" "noalloc" *) +let adaptive_threshold src maxValue adaptiveMethod thresholdType blockSize param1 = + let dst = create_image_from src in + adaptive_threshold' src dst maxValue adaptiveMethod thresholdType blockSize param1; + dst -(* external unsafe_set_int_3point : *) -(* ([`One],[`U8],[<`BGR | `RGB | `HSV ]) iplImage -> *) -(* int -> int_3point -> unit *) -(* = "ocaml_set_int_3point" "noalloc" *) +let canny src ?(apertureSize=3) th1 th2 = + let dst = create_image_from src in + canny' src dst th1 th2 apertureSize; + dst type image_data = (int, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array2.t @@ -198,9 +287,18 @@ external zero_image : ('a,'b) iplImage -> unit = "ocaml_cvZero" external clone_image : ('a,'b) iplImage -> ('a,'b) iplImage = "ocaml_cvCloneImage" let create_image ~x ~y _type i = cvCreateImage (x,y) (get_cvType _type) i -let convert_color ~src ~dst color_conversion = + +let convert_color' ~src ~dst color_conversion = cvCvtColor src dst (get_color_conversion color_conversion) +let convert_color src color_conversion = + let channels = convert_output_channels color_conversion in + let size = image_size src in + let type_ = cvType_int (image_depth src) in + let dst = cvCreateImage size type_ channels in + cvCvtColor src dst (get_color_conversion color_conversion); + dst + type cvScalar = float * float * float * float type cvPoint = int * int type cvPoint2D32f = float * float @@ -213,6 +311,14 @@ type cvTermCriteria = termcrit_epsilon : bool; max_iter : int; epsilon : float; } +type vec3f = float * float * float + +type vec3f_vect + +external create_vec3f_vect : unit -> vec3f_vect = "ocaml_create_Vec3f_vector" +external vec3f_vect_size : vec3f_vect -> int = "ocaml_vector_size_Vec3f" +external vec3f_vect_add : vec3f_vect -> vec3f -> unit = "ocaml_vector_add_Vec3f" +external vec3f_vect_get : vec3f_vect -> int -> vec3f = "ocaml_vector_get_Vec3f" external cvCircle : ('a,[`U8]) iplImage -> cvPoint -> int -> cvScalar -> int -> unit = "ocaml_cvCircle" external cvEllipse : ('a,[`U8]) iplImage -> cvPoint -> cvSize -> @@ -221,6 +327,50 @@ external cvEllipse : ('a,[`U8]) iplImage -> cvPoint -> cvSize -> external cvRectangle : ('a,[`U8]) iplImage -> cvPoint -> cvPoint -> cvScalar -> int -> unit = "ocaml_cvRectangle" external cvLine : ('a,[`U8]) iplImage -> cvPoint -> cvPoint -> cvScalar -> int -> unit = "ocaml_cvLine" +type color = int * int * int + +let red = 255, 0, 0 +let green = 0, 255, 0 +let blue = 0, 0, 255 +let yellow = 255, 255, 0 +let magenta = 255, 0, 255 +let black = 0, 0, 0 +let white = 255, 255, 255 + +let scalar_color (r,g,b) = (float b, float g, float r, 0.) + +let circle dst ?(thickness=1) ?(color=blue) center radius = + cvCircle dst center radius (scalar_color color) thickness + +let ellipse dst ?(thickness=1) ?(color=blue) ?(angle=0.) ?(start_angle=0.) ?(end_angle=360.) + center size = + cvEllipse dst center size angle start_angle end_angle (scalar_color color) thickness + +type ellipse = { + ellipse_center : float * float; + ellipse_size : float * float; + ellipse_angle : float; +} + +let ellipse' dst ?thickness ?color ?start_angle ?end_angle + { + ellipse_center = x,y; + ellipse_size = w,h; + ellipse_angle = angle; + } = + ellipse dst ?thickness ?color ?start_angle ?end_angle + (int_of_float x, int_of_float y) + (int_of_float w, int_of_float h) + +let rectangle dst ?(thickness=1) ?(color=blue) p1 p2 = + cvRectangle dst p1 p2 (scalar_color color) thickness + +let line dst ?(thickness=1) ?(color=blue) p1 p2 = + cvLine dst p1 p2 (scalar_color color) thickness + +let draw_points ?(color=red) ?(size=2) i a = + Array.iter (fun (x,y) -> circle i ~color (int_of_float x,int_of_float y) size) a + (* memory handling *) type cvMemStorage @@ -291,12 +441,6 @@ external cvDrawContours : ('a,[`U8]) iplImage -> cvSeq -> cvScalar -> cvScalar - let draw_contours image seq in_color out_color level thickness offset = cvDrawContours image seq.seq in_color out_color level thickness offset -type ellipse = { - ellipse_center : float * float; - ellipse_size : float * float; - ellipse_angle : float; -} - external cvFitEllipse2 : cvSeq -> (float * float * float * float * float) option = "ocaml_cvFitEllipse2" let fit_ellipse seq = @@ -307,6 +451,37 @@ let fit_ellipse seq = ellipse_size = width,height; ellipse_angle = angle } +external cvGoodFeaturesToTrack : + ([`Channel_1],'b) iplImage -> + (float, Bigarray.float32_elt, Bigarray.c_layout) Bigarray.Array2.t -> + float -> float -> + ([`Channel_1],[`U8]) iplImage option -> + int -> + bool -> + float -> + int + = "ocaml_cvGoodFeaturesToTrack_bytecode" "ocaml_cvGoodFeaturesToTrack" + +let good_features_to_track image ?mask ?(blockSize=3) ?(useHarris=false) ?(k=0.04) + maxCorners qualityLevel minDistance = + let ba = Bigarray.Array2.create Bigarray.float32 Bigarray.c_layout maxCorners 2 in + let count = cvGoodFeaturesToTrack image ba + qualityLevel minDistance + mask blockSize useHarris k in + Array.init count (fun i -> ba.{i,0}, ba.{i,1}) + +external houghCircles' : + ('a,[`U8]) iplImage -> + vec3f_vect -> + float -> float -> float -> float -> + int -> int -> unit + = "ocaml_HoughCircles_bytecode" "ocaml_HoughCircles" + +let houghCircles img ?(param1=100.) ?(param2=100.) ?(minRadius=0) ?(maxRadius=0) dp minDist = + let vec = create_vec3f_vect () in + houghCircles' img vec dp minDist param1 param2 minRadius maxRadius; + Array.init (vec3f_vect_size vec) (fun i -> vec3f_vect_get vec i) + type calib_cb = | CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_NORMALIZE_IMAGE @@ -362,14 +537,17 @@ let find_corner_subpix ?(criteria=default_criteria) ?(winSize=11,11) ?(zeroZone= cvFindCornerSubPix i ba count (11,11) (-1,-1) criteria; end - (** camera calibration *) type ('channel) cvMat_float32 = (float, Bigarray.float32_elt, Bigarray.c_layout) Bigarray.Array3.t +type ('channel) cvMat_float64 = + (float, Bigarray.float64_elt, Bigarray.c_layout) Bigarray.Array3.t + type ('channel) cvMat_int = - (int, Bigarray.int_elt, Bigarray.c_layout) Bigarray.Array3.t + (int32, Bigarray.int32_elt, Bigarray.c_layout) Bigarray.Array3.t +(* there is no 64 bit type in CvMat... so stick to int32 *) external cvCalibrateCamera2 : [`Channel_3] cvMat_float32 -> [`Channel_2] cvMat_float32 -> [`Channel_1] cvMat_int -> cvSize -> [`Channel_1] cvMat_float32 -> @@ -381,8 +559,8 @@ type calibration = cvSize * float * cvSize option * ((float*float) array array*( let init_calibration cb_size square_size : calibration = (cb_size, square_size, None, []) let corner_positions (x,y) square_size = - Array.init x - (fun i -> Array.init y + Array.init y + (fun i -> Array.init x (fun j -> (float j) *. square_size, (float i) *. square_size, 0.)) let add_calibration_image ((cb_size, square_size, i_size, state):calibration) image : calibration = @@ -420,8 +598,8 @@ let calibrate (cal:calibration) = let img_pos = Bigarray.reshape_3 (Bigarray.genarray_of_array3 img_pos) ((List.length state) * points) 1 2 in - let point_count = Array.create (List.length state) points in - let point_count = Bigarray.Array1.of_array Bigarray.int Bigarray.c_layout point_count in + let point_count = Array.map Int32.of_int (Array.create (List.length state) points) in + let point_count = Bigarray.Array1.of_array Bigarray.int32 Bigarray.c_layout point_count in let point_count = Bigarray.reshape_3 (Bigarray.genarray_of_array1 point_count) (List.length state) 1 1 in @@ -442,7 +620,9 @@ external cvInitUndistortMap : ([`Channel_1],[`F32]) iplImage -> ([`Channel_1],[`F32]) iplImage -> unit - = "cvInitUndistortMap" + = "ocaml_cvInitUndistortMap" + +type remap = ([ `Channel_1 ], [ `F32 ]) iplImage * ([ `Channel_1 ], [ `F32 ]) iplImage let init_undistort_map (x,y) (mat,v) = let mat = Bigarray.Array3.of_array Bigarray.float32 Bigarray.c_layout @@ -459,4 +639,22 @@ external cvRemap : ([`Channel_1],[`F32]) iplImage -> ([`Channel_1],[`F32]) iplImage -> unit - = "cvRemap" + = "ocaml_cvRemap" + +let remap' ((mapx,mapy):remap) src dst = + cvRemap src dst mapx mapy + +let remap ((mapx,mapy):remap) src = + let size = image_size src in + let type_ = cvType_int (image_depth src) in + let channels = image_channels src in + let dst = cvCreateImage size type_ channels in + cvRemap src dst mapx mapy; + dst + +external cvFindHomography : + [`Channel_2] cvMat_float64 -> + [`Channel_2] cvMat_float64 -> + [`Channel_1] cvMat_float64 -> + unit + = "ocaml_cvFindHomography" diff --git a/info/vision/camlcv/src/cvCore.mli b/info/vision/camlcv/src/cvCore.mli index 658edc5..3aa6239 100644 --- a/info/vision/camlcv/src/cvCore.mli +++ b/info/vision/camlcv/src/cvCore.mli @@ -11,6 +11,7 @@ type cvTermCriteria = termcrit_epsilon : bool; max_iter : int; epsilon : float; } +type vec3f = float * float * float type ('chan_num,'depth) iplImage @@ -54,18 +55,29 @@ val rgb2gray : ([`Channel_3],[`Channel_1]) conversion val gray2rgb : ([`Channel_1],[`Channel_3]) conversion val rgb2rgba : ([`Channel_3],[`Channel_4]) conversion -val convert_color : +val convert_color' : src:('c_src,'b) iplImage -> dst:('c_dst,'b) iplImage -> ('c_src,'c_dst) conversion -> unit -val split_3 : ([`Channel_3],'b) iplImage -> ([`Channel_1],'b) iplImage -> +val convert_color : + ('c_src,'b) iplImage -> + ('c_src,'c_dst) conversion -> + ('c_dst,'b) iplImage + +val split_3' : ([`Channel_3],'b) iplImage -> ([`Channel_1],'b) iplImage -> ([`Channel_1],'b) iplImage -> ([`Channel_1],'b) iplImage -> unit -val merge_3 : ([`Channel_1],'b) iplImage -> ([`Channel_1],'b) iplImage -> +val split : ([`Channel_3],'b) iplImage -> + ([`Channel_1],'b) iplImage * ([`Channel_1],'b) iplImage * ([`Channel_1],'b) iplImage + +val merge_3' : ([`Channel_1],'b) iplImage -> ([`Channel_1],'b) iplImage -> ([`Channel_1],'b) iplImage -> ([`Channel_3],'b) iplImage -> unit +val merge : ([`Channel_1],'b) iplImage -> ([`Channel_1],'b) iplImage -> + ([`Channel_1],'b) iplImage -> ([`Channel_3],'b) iplImage + (** threshold *) type threshold_type = @@ -81,17 +93,79 @@ type adaptive_method = | CV_ADAPTIVE_THRESH_MEAN_C | CV_ADAPTIVE_THRESH_GAUSSIAN_C -val threshold : ('a,'b) iplImage -> ('d,'e) iplImage -> float -> float -> threshold_type -> unit -(** [threshold src dst threshold maxValue thresholdType] *) -val adaptive_threshold : ('a,'b) iplImage -> ('d,'e) iplImage -> float -> adaptive_method -> threshold_type -> int -> float -> unit -(** [adaptive_threshold src dst maxValue adaptiveMethod thresholdType blockSize param1] *) +val threshold' : ([`Channel_1],'b) iplImage -> ([`Channel_1],'b) iplImage -> + float -> float -> threshold_type -> unit +(** [threshold' src dst threshold maxValue thresholdType] *) + +val threshold : ([`Channel_1],'b) iplImage -> float -> float -> threshold_type -> + ([`Channel_1],'b) iplImage +(** [threshold src threshold maxValue thresholdType] *) + +val adaptive_threshold' : ([`Channel_1],'b) iplImage -> ([`Channel_1],'b) iplImage -> + float -> adaptive_method -> threshold_type -> int -> float -> unit +(** [adaptive_threshold' src dst maxValue adaptiveMethod thresholdType blockSize param1] *) + +val adaptive_threshold : ([`Channel_1],'b) iplImage -> + float -> adaptive_method -> threshold_type -> int -> float -> ([`Channel_1],'b) iplImage +(** [adaptive_threshold src maxValue adaptiveMethod thresholdType blockSize param1] *) + +(** edge detection *) + +val canny' : ([`Channel_1],[`U8]) iplImage -> ([`Channel_1],[`U8]) iplImage -> + float -> float -> int -> unit +val canny : ([ `Channel_1 ], [ `U8 ]) iplImage -> + ?apertureSize:int -> + float -> float -> ([ `Channel_1 ], [ `U8 ]) iplImage +(** [canny src threshold1 threshold2] *) (** drawing *) -val cvCircle : ('a,[`U8]) iplImage -> cvPoint -> int -> cvScalar -> int -> unit -val cvEllipse : ('a,[`U8]) iplImage -> cvPoint -> cvSize -> float -> float -> float -> cvScalar -> int -> unit -val cvRectangle : ('a,[`U8]) iplImage -> cvPoint -> cvPoint -> cvScalar -> int -> unit -val cvLine : ('a,[`U8]) iplImage -> cvPoint -> cvPoint -> cvScalar -> int -> unit +type color = int * int * int (** red, green, blue *) + +val red : color +val green : color +val blue : color +val yellow : color +val magenta : color +val black : color +val white : color + +val circle : ('a, [ `U8 ]) iplImage -> + ?thickness:int -> ?color:color -> + cvPoint -> int -> unit + +type ellipse = { + ellipse_center : float * float; + ellipse_size : float * float; + ellipse_angle : float; +} + +val ellipse : ('a, [ `U8 ]) iplImage -> + ?thickness:int -> + ?color:color -> + ?angle:float -> + ?start_angle:float -> ?end_angle:float -> cvPoint -> cvSize -> unit + +val ellipse' : ('a, [ `U8 ]) iplImage -> + ?thickness:int -> + ?color:color -> + ?start_angle:float -> ?end_angle:float -> + ellipse -> unit + +val rectangle : ('a, [ `U8 ]) iplImage -> + ?thickness:int -> ?color:color -> + cvPoint -> cvPoint -> unit + +val line : ('a, [ `U8 ]) iplImage -> + ?thickness:int -> ?color:color -> + cvPoint -> cvPoint -> unit + +val draw_points : + ?color:color -> + ?size:int -> + ('a, [ `U8 ]) iplImage -> + cvPoint2D32f array -> unit + (**/**) val image_data_order : ('a,'b) iplImage -> int @@ -129,14 +203,24 @@ val find_contours : ?mode:contour_retrieval_mode -> ?meth:contour_approximation_ val draw_contours : ('a,[`U8]) iplImage -> seq -> cvScalar -> cvScalar -> int -> int -> cvPoint -> unit -type ellipse = { - ellipse_center : float * float; - ellipse_size : float * float; - ellipse_angle : float; -} - val fit_ellipse : seq -> ellipse option +val good_features_to_track : + ([ `Channel_1 ], 'a) iplImage -> + ?mask:([ `Channel_1 ], [ `U8 ]) iplImage -> + ?blockSize:int -> + ?useHarris:bool -> + ?k:float -> int -> float -> float -> cvPoint2D32f array +(** [good_features_to_track image ?mask ?(blockSize=3) ?(useHarris=false) ?(k=0.04) + maxCorners qualityLevel minDistance] *) + + val houghCircles : + ('a, [ `U8 ]) iplImage -> + ?param1:float -> + ?param2:float -> + ?minRadius:int -> ?maxRadius:int -> float -> float -> vec3f array +(** [houghCircles img dp minDist] *) + type calib_cb = | CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_NORMALIZE_IMAGE @@ -165,12 +249,21 @@ val add_calibration_image : calibration -> ([ `Channel_1 ], [ `U8 ]) iplImage -> calibration val calibrate : calibration -> float * ( float array array * float array ) -val init_undistort_map : cvSize -> ( float array array * float array ) -> - ([ `Channel_1 ], [ `F32 ]) iplImage * ([ `Channel_1 ], [ `F32 ]) iplImage +type remap + +val init_undistort_map : cvSize -> ( float array array * float array ) -> remap +val remap' : remap -> ('a, 'b) iplImage -> ('a, 'b) iplImage -> unit +val remap : remap -> ('a, 'b) iplImage -> ('a, 'b) iplImage + +type ('channel) cvMat_float32 = + (float, Bigarray.float32_elt, Bigarray.c_layout) Bigarray.Array3.t + +type ('channel) cvMat_float64 = + (float, Bigarray.float64_elt, Bigarray.c_layout) Bigarray.Array3.t -external cvRemap : - ('a,'b) iplImage -> ('a,'b) iplImage -> - ([`Channel_1],[`F32]) iplImage -> - ([`Channel_1],[`F32]) iplImage -> +external cvFindHomography : + [`Channel_2] cvMat_float64 -> + [`Channel_2] cvMat_float64 -> + [`Channel_1] cvMat_float64 -> unit - = "cvRemap" + = "ocaml_cvFindHomography" diff --git a/info/vision/camlcv/src/cvHighGui.ml b/info/vision/camlcv/src/cvHighGui.ml index bc5ada3..e10f58f 100644 --- a/info/vision/camlcv/src/cvHighGui.ml +++ b/info/vision/camlcv/src/cvHighGui.ml @@ -40,14 +40,109 @@ let named_window ?(option=CV_WINDOW_DEFAULT) name = | CV_WINDOW_AUTOSIZE -> 1 in cvNamedWindow name opt -external wait_key : int -> char = "ocaml_cvWaitKey" +external destroy_window : string -> unit = "ocaml_cvDestroyWindow" +external destroy_all_windows : unit -> unit = "ocaml_cvDestroyAllWindows" + +external wait_key' : int -> int = "ocaml_cvWaitKey" + +let wait_key i = + let c = wait_key' i in + if c > 0 + then Some (Char.chr (c land 255)) + else None + external show_image : string -> ('a,'b) iplImage -> unit = "ocaml_cvShowImage" type int_var external create_int_var : int -> int_var = "ocaml_create_int_var" -external get_int_var : int_var -> int = "ocaml_get_int_var" -external set_int_var : int_var -> int -> unit = "ocaml_set_int_var" +external get_var : int_var -> int = "ocaml_get_int_var" +external set_var : int_var -> int -> unit = "ocaml_set_int_var" external cvCreateTrackbar : string -> string -> int_var -> int -> int = "ocaml_cvCreateTrackbar" -let create_trackbar ~name ~window var max = ignore (cvCreateTrackbar name window var max) +let create_trackbar ?default ~name ~window max = + let default = match default with + | None -> max / 2 + | Some d -> d in + let var = create_int_var default in + ignore (cvCreateTrackbar name window var max); + var + +type cap_prop = + | CV_CAP_PROP_DC1394_OFF + | CV_CAP_PROP_DC1394_MODE_MANUAL + | CV_CAP_PROP_DC1394_MODE_AUTO + | CV_CAP_PROP_DC1394_MODE_ONE_PUSH_AUTO + | CV_CAP_PROP_POS_MSEC + | CV_CAP_PROP_POS_FRAMES + | CV_CAP_PROP_POS_AVI_RATIO + | CV_CAP_PROP_FRAME_WIDTH + | CV_CAP_PROP_FRAME_HEIGHT + | CV_CAP_PROP_FPS + | CV_CAP_PROP_FOURCC + | CV_CAP_PROP_FRAME_COUNT + | CV_CAP_PROP_FORMAT + | CV_CAP_PROP_MODE + | CV_CAP_PROP_BRIGHTNESS + | CV_CAP_PROP_CONTRAST + | CV_CAP_PROP_SATURATION + | CV_CAP_PROP_HUE + | CV_CAP_PROP_GAIN + | CV_CAP_PROP_EXPOSURE + | CV_CAP_PROP_CONVERT_RGB + | CV_CAP_PROP_WHITE_BALANCE_BLUE_U + | CV_CAP_PROP_RECTIFICATION + | CV_CAP_PROP_MONOCROME + | CV_CAP_PROP_SHARPNESS + | CV_CAP_PROP_AUTO_EXPOSURE + | CV_CAP_PROP_GAMMA + | CV_CAP_PROP_TEMPERATURE + | CV_CAP_PROP_TRIGGER + | CV_CAP_PROP_TRIGGER_DELAY + | CV_CAP_PROP_WHITE_BALANCE_RED_V + | CV_CAP_PROP_MAX_DC1394 + | CV_CAP_PROP_AUTOGRAB + | CV_CAP_PROP_SUPPORTED_PREVIEW_SIZES_STRING + | CV_CAP_PROP_PREVIEW_FORMAT + | CV_CAP_OPENNI_DEPTH_GENERATOR + | CV_CAP_OPENNI_IMAGE_GENERATOR + | CV_CAP_OPENNI_GENERATORS_MASK + | CV_CAP_PROP_OPENNI_OUTPUT_MODE + | CV_CAP_PROP_OPENNI_FRAME_MAX_DEPTH + | CV_CAP_PROP_OPENNI_BASELINE + | CV_CAP_PROP_OPENNI_FOCAL_LENGTH + | CV_CAP_PROP_OPENNI_REGISTRATION_ON + | CV_CAP_PROP_OPENNI_REGISTRATION + | CV_CAP_OPENNI_IMAGE_GENERATOR_OUTPUT_MODE + | CV_CAP_OPENNI_DEPTH_GENERATOR_BASELINE + | CV_CAP_OPENNI_DEPTH_GENERATOR_FOCAL_LENGTH + | CV_CAP_OPENNI_DEPTH_GENERATOR_REGISTRATION_ON + | CV_CAP_GSTREAMER_QUEUE_LENGTH + | CV_CAP_PROP_PVAPI_MULTICASTIP + | CV_CAP_PROP_XI_DOWNSAMPLING + | CV_CAP_PROP_XI_DATA_FORMAT + | CV_CAP_PROP_XI_OFFSET_X + | CV_CAP_PROP_XI_OFFSET_Y + | CV_CAP_PROP_XI_TRG_SOURCE + | CV_CAP_PROP_XI_TRG_SOFTWARE + | CV_CAP_PROP_XI_GPI_SELECTOR + | CV_CAP_PROP_XI_GPI_MODE + | CV_CAP_PROP_XI_GPI_LEVEL + | CV_CAP_PROP_XI_GPO_SELECTOR + | CV_CAP_PROP_XI_GPO_MODE + | CV_CAP_PROP_XI_LED_SELECTOR + | CV_CAP_PROP_XI_LED_MODE + | CV_CAP_PROP_XI_MANUAL_WB + | CV_CAP_PROP_XI_AUTO_WB + | CV_CAP_PROP_XI_AEAG + | CV_CAP_PROP_XI_EXP_PRIORITY + | CV_CAP_PROP_XI_AE_MAX_LIMIT + | CV_CAP_PROP_XI_AG_MAX_LIMIT + | CV_CAP_PROP_XI_AEAG_LEVEL + | CV_CAP_PROP_XI_TIMEOUT + +external set_capture_property : cvCapture -> cap_prop -> float -> unit = + "ocaml_cvSetCaptureProperty" + +external get_capture_property : cvCapture -> cap_prop -> float = + "ocaml_cvGetCaptureProperty" diff --git a/info/vision/camlcv/src/cvHighGui.mli b/info/vision/camlcv/src/cvHighGui.mli index 8e93588..6e54b60 100644 --- a/info/vision/camlcv/src/cvHighGui.mli +++ b/info/vision/camlcv/src/cvHighGui.mli @@ -16,6 +16,82 @@ type cvCapture val capture_from_cam : int -> cvCapture val query_frame : cvCapture -> ([`Channel_3],[`U8]) iplImage +type cap_prop = + | CV_CAP_PROP_DC1394_OFF + | CV_CAP_PROP_DC1394_MODE_MANUAL + | CV_CAP_PROP_DC1394_MODE_AUTO + | CV_CAP_PROP_DC1394_MODE_ONE_PUSH_AUTO + | CV_CAP_PROP_POS_MSEC + | CV_CAP_PROP_POS_FRAMES + | CV_CAP_PROP_POS_AVI_RATIO + | CV_CAP_PROP_FRAME_WIDTH + | CV_CAP_PROP_FRAME_HEIGHT + | CV_CAP_PROP_FPS + | CV_CAP_PROP_FOURCC + | CV_CAP_PROP_FRAME_COUNT + | CV_CAP_PROP_FORMAT + | CV_CAP_PROP_MODE + | CV_CAP_PROP_BRIGHTNESS + | CV_CAP_PROP_CONTRAST + | CV_CAP_PROP_SATURATION + | CV_CAP_PROP_HUE + | CV_CAP_PROP_GAIN + | CV_CAP_PROP_EXPOSURE + | CV_CAP_PROP_CONVERT_RGB + | CV_CAP_PROP_WHITE_BALANCE_BLUE_U + | CV_CAP_PROP_RECTIFICATION + | CV_CAP_PROP_MONOCROME + | CV_CAP_PROP_SHARPNESS + | CV_CAP_PROP_AUTO_EXPOSURE + | CV_CAP_PROP_GAMMA + | CV_CAP_PROP_TEMPERATURE + | CV_CAP_PROP_TRIGGER + | CV_CAP_PROP_TRIGGER_DELAY + | CV_CAP_PROP_WHITE_BALANCE_RED_V + | CV_CAP_PROP_MAX_DC1394 + | CV_CAP_PROP_AUTOGRAB + | CV_CAP_PROP_SUPPORTED_PREVIEW_SIZES_STRING + | CV_CAP_PROP_PREVIEW_FORMAT + | CV_CAP_OPENNI_DEPTH_GENERATOR + | CV_CAP_OPENNI_IMAGE_GENERATOR + | CV_CAP_OPENNI_GENERATORS_MASK + | CV_CAP_PROP_OPENNI_OUTPUT_MODE + | CV_CAP_PROP_OPENNI_FRAME_MAX_DEPTH + | CV_CAP_PROP_OPENNI_BASELINE + | CV_CAP_PROP_OPENNI_FOCAL_LENGTH + | CV_CAP_PROP_OPENNI_REGISTRATION_ON + | CV_CAP_PROP_OPENNI_REGISTRATION + | CV_CAP_OPENNI_IMAGE_GENERATOR_OUTPUT_MODE + | CV_CAP_OPENNI_DEPTH_GENERATOR_BASELINE + | CV_CAP_OPENNI_DEPTH_GENERATOR_FOCAL_LENGTH + | CV_CAP_OPENNI_DEPTH_GENERATOR_REGISTRATION_ON + | CV_CAP_GSTREAMER_QUEUE_LENGTH + | CV_CAP_PROP_PVAPI_MULTICASTIP + | CV_CAP_PROP_XI_DOWNSAMPLING + | CV_CAP_PROP_XI_DATA_FORMAT + | CV_CAP_PROP_XI_OFFSET_X + | CV_CAP_PROP_XI_OFFSET_Y + | CV_CAP_PROP_XI_TRG_SOURCE + | CV_CAP_PROP_XI_TRG_SOFTWARE + | CV_CAP_PROP_XI_GPI_SELECTOR + | CV_CAP_PROP_XI_GPI_MODE + | CV_CAP_PROP_XI_GPI_LEVEL + | CV_CAP_PROP_XI_GPO_SELECTOR + | CV_CAP_PROP_XI_GPO_MODE + | CV_CAP_PROP_XI_LED_SELECTOR + | CV_CAP_PROP_XI_LED_MODE + | CV_CAP_PROP_XI_MANUAL_WB + | CV_CAP_PROP_XI_AUTO_WB + | CV_CAP_PROP_XI_AEAG + | CV_CAP_PROP_XI_EXP_PRIORITY + | CV_CAP_PROP_XI_AE_MAX_LIMIT + | CV_CAP_PROP_XI_AG_MAX_LIMIT + | CV_CAP_PROP_XI_AEAG_LEVEL + | CV_CAP_PROP_XI_TIMEOUT + +val set_capture_property : cvCapture -> cap_prop -> float -> unit +val get_capture_property : cvCapture -> cap_prop -> float + (** Gui interface *) type window_option = @@ -25,10 +101,14 @@ type window_option = val named_window : ?option:window_option -> string -> unit (** [named_window name] create a window named [name] *) +val destroy_window : string -> unit +val destroy_all_windows : unit -> unit + val show_image : string -> ('a,'b) iplImage -> unit (** [show_image window image] display the image [image] in the window [window] *) -val wait_key : int -> char +val wait_key' : int -> int +val wait_key : int -> char option (** [wait_key time] wait for [time] milliseconds for an event to occur. If [time < 0] it waits indefinitely. Nothing happens in the gui until this function is called. *) @@ -36,6 +116,6 @@ val wait_key : int -> char type int_var val create_int_var : int -> int_var -val get_int_var : int_var -> int -val set_int_var : int_var -> int -> unit -val create_trackbar : name:string -> window:string -> int_var -> int -> unit +val get_var : int_var -> int +val set_var : int_var -> int -> unit +val create_trackbar : ?default:int -> name:string -> window:string -> int -> int_var diff --git a/info/vision/camlcv/src/cv_caml.c b/info/vision/camlcv/src/cv_caml.c index 42cb9cd..a49aaf1 100644 --- a/info/vision/camlcv/src/cv_caml.c +++ b/info/vision/camlcv/src/cv_caml.c @@ -1,3 +1,4 @@ +extern "C" { #include <caml/alloc.h> #include <caml/fail.h> #include <caml/mlvalues.h> @@ -6,6 +7,7 @@ #include <caml/custom.h> #include <caml/bigarray.h> #include <caml/callback.h> +} #include <assert.h> #include <stdio.h> @@ -21,6 +23,267 @@ #undef uint64 #undef schar +using namespace cv; + +#define ERRWRAP(expr) \ +try \ +{ \ + expr; \ +} \ +catch (const cv::Exception &e) \ +{ \ + caml_failwith(e.what()); \ +} + +static Vec3f Vec3f_val(value v) { + double v0 = Double_val(Field(v,0)); + double v1 = Double_val(Field(v,1)); + double v2 = Double_val(Field(v,2)); + return (Vec3f(v0,v1,v2)); +} + +static value Val_Vec3f(Vec3f v) { + CAMLparam0(); + CAMLlocal1(res); + res = caml_alloc_tuple(3); + for(int i = 0; i < 3; i++) { + Field(res,i) = caml_copy_double(v[i]); + } + CAMLreturn(res); +} + +/* c++ vector */ + +template <typename Type> +vector<Type>* Vector_val(value v) +{ + return *(vector<Type>**) Data_custom_val(v); +} + +extern "C" void caml_finalize_vector(value vec) +{ + //it is the same finalizer for all types... problems ? + vector<void*>* del = Vector_val<void*>(vec); + delete del; + return; +} + +static struct custom_operations vector_operations = { + (char*) "ocaml_vector", + caml_finalize_vector, + custom_compare_default, + custom_hash_default, + custom_serialize_default, + custom_deserialize_default +}; +template <typename Type> +value ocaml_create_vector(value v) +{ + CAMLparam1(v); + CAMLlocal1(res); + res = caml_alloc_custom(&vector_operations, sizeof(vector<Type>*), 1, 10); + *(vector<Type>**) Data_custom_val(res) = new vector<Type>(); + CAMLreturn(res); +} + +template <typename Type> +value ocaml_vector_size(value v) +{ + CAMLparam1(v); + vector<Type>* vec = Vector_val<Type>(v); + CAMLreturn(Val_int(vec->size())); +} + +template <typename Type> +value ocaml_vector_add(value v, value vx, Type x) +{ + CAMLparam2(v,vx); + Vector_val<Type>(v)->push_back(x); + CAMLreturn(Val_unit); +} + +template <typename Type> +Type ocaml_vector_get(value v, value x) +{ + vector<Type>* vec = Vector_val<Type>(v); + Type ret; + try { + ret = vec->at(Int_val(x)); + } + catch (const std::exception &e) { + caml_failwith(e.what()); + }; + return(ret); +} + +extern "C" CAMLprim value ocaml_create_int_vector(value v) +{ + return(ocaml_create_vector<int>(v)); +} + +extern "C" CAMLprim value ocaml_vector_size_int(value v) +{ + return(ocaml_vector_size<int>(v)); +} + +extern "C" CAMLprim value ocaml_vector_add_int(value v, value x) +{ + return(ocaml_vector_add<int>(v,x,Int_val(x))); +} + +extern "C" CAMLprim value ocaml_vector_get_int(value v, value x) +{ + CAMLparam2(v,x); + CAMLreturn(Val_int(ocaml_vector_get<int>(v,x))); +} + +extern "C" CAMLprim value ocaml_create_Vec3f_vector(value v) +{ + return(ocaml_create_vector<Vec3f>(v)); +} + +extern "C" CAMLprim value ocaml_vector_size_Vec3f(value v) +{ + return(ocaml_vector_size<Vec3f>(v)); +} + +extern "C" CAMLprim value ocaml_vector_add_Vec3f(value v, value x) +{ + return(ocaml_vector_add<Vec3f>(v,x,Vec3f_val(x))); +} +extern "C" CAMLprim value ocaml_vector_get_Vec3f(value v, value x) +{ + CAMLparam2(v,x); + Vec3f r = ocaml_vector_get<Vec3f>(v,x); + CAMLreturn(Val_Vec3f(r)); +} + +/* basic caml value conversions */ + +static CvScalar CvScalar_val(value v) { + double v0 = Double_val(Field(v,0)); + double v1 = Double_val(Field(v,1)); + double v2 = Double_val(Field(v,2)); + double v3 = Double_val(Field(v,3)); + return (cvScalar(v0,v1,v2,v3)); +} + +static CvPoint CvPoint_val(value v) { + int v0 = Int_val(Field(v,0)); + int v1 = Int_val(Field(v,1)); + return (cvPoint(v0,v1)); +} + +/* unused +static CvPoint2D32f CvPoint2D32f_val(value v) { + double v0 = Double_val(Field(v,0)); + double v1 = Double_val(Field(v,1)); + return (cvPoint2D32f(v0,v1)); +} + +static CvPoint3D32f CvPoint3D32f_val(value v) { + double v0 = Double_val(Field(v,0)); + double v1 = Double_val(Field(v,1)); + double v2 = Double_val(Field(v,2)); + return (cvPoint3D32f(v0,v1,v2)); +} + +static CvPoint2D64f CvPoint2D64f_val(value v) { + double v0 = Double_val(Field(v,0)); + double v1 = Double_val(Field(v,1)); + return (cvPoint2D64f(v0,v1)); +} + +static CvPoint3D64f CvPoint3D64f_val(value v) { + double v0 = Double_val(Field(v,0)); + double v1 = Double_val(Field(v,1)); + double v2 = Double_val(Field(v,2)); + return (cvPoint3D64f(v0,v1,v2)); +} +*/ + +static CvSize CvSize_val(value v) { + int v0 = Int_val(Field(v,0)); + int v1 = Int_val(Field(v,1)); + return (cvSize(v0,v1)); +} + +static CvTermCriteria CvTermCriteria_val(value v) { + int tc_iter = Int_val(Field(v,0)); + int tc_eps = Int_val(Field(v,1)); + int type = 0; + if (tc_iter) type |= CV_TERMCRIT_ITER; + if (tc_eps) type |= CV_TERMCRIT_EPS; + int max_iter = Int_val(Field(v,2)); + double epsilon = Double_val(Field(v,3)); + return (cvTermCriteria(type,max_iter,epsilon)); +} + +static CvMat CvMat_val(value v) { + void* data = Data_bigarray_val(v); + int rows = Bigarray_val(v)->dim[0]; + int cols = Bigarray_val(v)->dim[1]; + int channels = Bigarray_val(v)->dim[2]; + int kind = Bigarray_val(v)->flags & BIGARRAY_KIND_MASK; + int type = 0; + switch (kind) { + + case BIGARRAY_FLOAT32: + switch (channels) { + case 1: + type = CV_32FC1; + break; + case 2: + type = CV_32FC2; + break; + case 3: + type = CV_32FC3; + break; + default: + break; + } + break; + + case BIGARRAY_FLOAT64: + switch (channels) { + case 1: + type = CV_64FC1; + break; + case 2: + type = CV_64FC2; + break; + case 3: + type = CV_64FC3; + break; + default: + break; + } + break; + + case BIGARRAY_INT32: + switch (channels) { + case 1: + type = CV_32SC1; + break; + case 2: + type = CV_32SC2; + break; + case 3: + type = CV_32SC3; + break; + default: + break; + } + break; + + default: + break; + } + if(type == 0) caml_failwith("CvMat_val case not handled"); + + return (cvMat(rows, cols, type, data)); +} + int cvType_table[] = { IPL_DEPTH_1U, IPL_DEPTH_8U, @@ -31,7 +294,7 @@ int cvType_table[] = { IPL_DEPTH_32S }; -int ocaml_get_cvType(int vtype) +extern "C" CAMLprim value ocaml_get_cvType(value vtype) { return (Val_int(cvType_table[Int_val(vtype)])); } @@ -44,7 +307,7 @@ int iscolor_table[] = { CV_LOAD_IMAGE_ANYCOLOR }; -int ocaml_get_iscolor(int iscolor) +extern "C" CAMLprim value ocaml_get_iscolor(value iscolor) { return (Val_int(iscolor_table[Int_val(iscolor)])); } @@ -61,7 +324,7 @@ void caml_finalize_CvMemStorage(value vstor) } static struct custom_operations CvMemStorage_operations = { - "ocaml_opencv_CvMemStorage", + (char*) "ocaml_opencv_CvMemStorage", caml_finalize_CvMemStorage, custom_compare_default, custom_hash_default, @@ -69,7 +332,7 @@ static struct custom_operations CvMemStorage_operations = { custom_deserialize_default }; -CAMLexport value ocaml_create_CvMemStorage(value vunit) +extern "C" CAMLprim value ocaml_create_CvMemStorage(value vunit) { CAMLparam1(vunit); CAMLlocal1 (res); @@ -79,7 +342,7 @@ CAMLexport value ocaml_create_CvMemStorage(value vunit) CAMLreturn (res); } -CAMLexport value ocaml_free_CvMemStorage(value vstor) +extern "C" CAMLprim value ocaml_free_CvMemStorage(value vstor) { CAMLparam1(vstor); caml_finalize_CvMemStorage(vstor); @@ -101,7 +364,7 @@ void caml_finalize_IplImage(value vimage) } static struct custom_operations IplImage_operations = { - "ocaml_opencv_IplImage", + (char*) "ocaml_opencv_IplImage", caml_finalize_IplImage, custom_compare_default, custom_hash_default, @@ -119,18 +382,25 @@ CAMLexport value caml_alloc_IplImage(IplImage *image) CAMLreturn (res); } -CAMLprim value ocaml_cvCreateImage(value vsize, value vtype, value vi) +extern "C" CAMLprim value ocaml_cvCreateImage(value vsize, value vtype, value vi) { CAMLparam3 (vsize, vtype, vi); CAMLlocal1 (res); - IplImage* image = cvCreateImage(cvSize(Int_val(Field (vsize, 0)), - Int_val(Field (vsize, 1))), - Int_val(vtype), Int_val(vi)); + IplImage* image = cvCreateImage(CvSize_val(vsize), Int_val(vtype), Int_val(vi)); + res = caml_alloc_IplImage(image); + CAMLreturn (res); +} + +extern "C" CAMLprim value ocaml_cvCreateImage_depth(value vsize, value vdepth, value vi) +{ + CAMLparam3 (vsize, vdepth, vi); + CAMLlocal1 (res); + IplImage* image = cvCreateImage(CvSize_val(vsize), Int_val(vdepth), Int_val(vi)); res = caml_alloc_IplImage(image); CAMLreturn (res); } -CAMLprim value ocaml_cvLoadImage(value vfile, value viscolor) +extern "C" CAMLprim value ocaml_cvLoadImage(value vfile, value viscolor) { CAMLparam2 (vfile, viscolor); CAMLlocal1 (res); @@ -140,7 +410,7 @@ CAMLprim value ocaml_cvLoadImage(value vfile, value viscolor) CAMLreturn (res); } -CAMLprim value ocaml_cvCloneImage(value vimage) +extern "C" CAMLprim value ocaml_cvCloneImage(value vimage) { CAMLparam1 (vimage); CAMLlocal1 (res); @@ -150,21 +420,21 @@ CAMLprim value ocaml_cvCloneImage(value vimage) CAMLreturn (res); } -CAMLprim value ocaml_cvZero(value vimage) +extern "C" CAMLprim value ocaml_cvZero(value vimage) { CAMLparam1 (vimage); cvZero( Image_val(vimage)->image ); CAMLreturn (Val_unit); } -CAMLprim value ocaml_cvShowImage(value vwindow, value vimage) +extern "C" CAMLprim value ocaml_cvShowImage(value vwindow, value vimage) { CAMLparam2 (vwindow, vimage); cvShowImage( String_val(vwindow), Image_val(vimage)->image); CAMLreturn (Val_unit); } -CAMLprim value ocaml_image_size(value vimage) +extern "C" CAMLprim value ocaml_image_size(value vimage) { CAMLparam1 (vimage); CAMLlocal1 (res); @@ -175,14 +445,28 @@ CAMLprim value ocaml_image_size(value vimage) CAMLreturn (res); } -CAMLprim value ocaml_cvNamedWindow(value vwindow, value vi) +extern "C" CAMLprim value ocaml_cvNamedWindow(value vwindow, value vi) { CAMLparam2 (vwindow, vi); - cvNamedWindow(String_val(vwindow), Int_val(vi)); + ERRWRAP(cvNamedWindow(String_val(vwindow), Int_val(vi))); + CAMLreturn (Val_unit); +} + +extern "C" CAMLprim value ocaml_cvDestroyWindow(value vwindow) +{ + CAMLparam1 (vwindow); + ERRWRAP(cvDestroyWindow(String_val(vwindow))); + CAMLreturn (Val_unit); +} + +extern "C" CAMLprim value ocaml_cvDestroyAllWindows(value vunit) +{ + CAMLparam1 (vunit); + ERRWRAP(cvDestroyAllWindows()); CAMLreturn (Val_unit); } -CAMLprim value ocaml_cvWaitKey(value vi) +extern "C" CAMLprim value ocaml_cvWaitKey(value vi) { return (Val_int(cvWaitKey(Int_val(vi)))); } @@ -196,7 +480,7 @@ CAMLexport void caml_finalize_CvCapture(value vcapture) } static struct custom_operations CvCapture_operations = { - "ocaml_opencv_CvCapture", + (char*) "ocaml_opencv_CvCapture", caml_finalize_CvCapture, custom_compare_default, custom_hash_default, @@ -212,7 +496,7 @@ CAMLexport value caml_alloc_CvCapture(CvCapture *capture) return res; } -CAMLprim value ocaml_cvCaptureFromCAM(value vsource) +extern "C" CAMLprim value ocaml_cvCaptureFromCAM(value vsource) { CAMLparam1 (vsource); CAMLlocal1 (res); @@ -222,7 +506,7 @@ CAMLprim value ocaml_cvCaptureFromCAM(value vsource) CAMLreturn (res); } -CAMLprim value ocaml_cvQueryFrame(value vcapture) +extern "C" CAMLprim value ocaml_cvQueryFrame(value vcapture) { CAMLparam1 (vcapture); CAMLlocal1 (res); @@ -233,6 +517,99 @@ CAMLprim value ocaml_cvQueryFrame(value vcapture) CAMLreturn (res); } +int cv_cap_table[] = { + CV_CAP_PROP_DC1394_OFF, + CV_CAP_PROP_DC1394_MODE_MANUAL, + CV_CAP_PROP_DC1394_MODE_AUTO, + CV_CAP_PROP_DC1394_MODE_ONE_PUSH_AUTO, + CV_CAP_PROP_POS_MSEC, + CV_CAP_PROP_POS_FRAMES, + CV_CAP_PROP_POS_AVI_RATIO, + CV_CAP_PROP_FRAME_WIDTH, + CV_CAP_PROP_FRAME_HEIGHT, + CV_CAP_PROP_FPS, + CV_CAP_PROP_FOURCC, + CV_CAP_PROP_FRAME_COUNT, + CV_CAP_PROP_FORMAT, + CV_CAP_PROP_MODE, + CV_CAP_PROP_BRIGHTNESS, + CV_CAP_PROP_CONTRAST, + CV_CAP_PROP_SATURATION, + CV_CAP_PROP_HUE, + CV_CAP_PROP_GAIN, + CV_CAP_PROP_EXPOSURE, + CV_CAP_PROP_CONVERT_RGB, + CV_CAP_PROP_WHITE_BALANCE_BLUE_U, + CV_CAP_PROP_RECTIFICATION, + CV_CAP_PROP_MONOCROME, + CV_CAP_PROP_SHARPNESS, + CV_CAP_PROP_AUTO_EXPOSURE, + CV_CAP_PROP_GAMMA, + CV_CAP_PROP_TEMPERATURE, + CV_CAP_PROP_TRIGGER, + CV_CAP_PROP_TRIGGER_DELAY, + CV_CAP_PROP_WHITE_BALANCE_RED_V, + CV_CAP_PROP_MAX_DC1394, + CV_CAP_PROP_AUTOGRAB, + CV_CAP_PROP_SUPPORTED_PREVIEW_SIZES_STRING, + CV_CAP_PROP_PREVIEW_FORMAT, + CV_CAP_OPENNI_DEPTH_GENERATOR, + CV_CAP_OPENNI_IMAGE_GENERATOR, + CV_CAP_OPENNI_GENERATORS_MASK, + CV_CAP_PROP_OPENNI_OUTPUT_MODE, + CV_CAP_PROP_OPENNI_FRAME_MAX_DEPTH, + CV_CAP_PROP_OPENNI_BASELINE, + CV_CAP_PROP_OPENNI_FOCAL_LENGTH, + CV_CAP_PROP_OPENNI_REGISTRATION_ON, + CV_CAP_PROP_OPENNI_REGISTRATION, + CV_CAP_OPENNI_IMAGE_GENERATOR_OUTPUT_MODE, + CV_CAP_OPENNI_DEPTH_GENERATOR_BASELINE, + CV_CAP_OPENNI_DEPTH_GENERATOR_FOCAL_LENGTH, + CV_CAP_OPENNI_DEPTH_GENERATOR_REGISTRATION_ON, + CV_CAP_GSTREAMER_QUEUE_LENGTH, + CV_CAP_PROP_PVAPI_MULTICASTIP, + CV_CAP_PROP_XI_DOWNSAMPLING, + CV_CAP_PROP_XI_DATA_FORMAT, + CV_CAP_PROP_XI_OFFSET_X, + CV_CAP_PROP_XI_OFFSET_Y, + CV_CAP_PROP_XI_TRG_SOURCE, + CV_CAP_PROP_XI_TRG_SOFTWARE, + CV_CAP_PROP_XI_GPI_SELECTOR, + CV_CAP_PROP_XI_GPI_MODE, + CV_CAP_PROP_XI_GPI_LEVEL, + CV_CAP_PROP_XI_GPO_SELECTOR, + CV_CAP_PROP_XI_GPO_MODE, + CV_CAP_PROP_XI_LED_SELECTOR, + CV_CAP_PROP_XI_LED_MODE, + CV_CAP_PROP_XI_MANUAL_WB, + CV_CAP_PROP_XI_AUTO_WB, + CV_CAP_PROP_XI_AEAG, + CV_CAP_PROP_XI_EXP_PRIORITY, + CV_CAP_PROP_XI_AE_MAX_LIMIT, + CV_CAP_PROP_XI_AG_MAX_LIMIT, + CV_CAP_PROP_XI_AEAG_LEVEL, + CV_CAP_PROP_XI_TIMEOUT +}; + +extern "C" CAMLprim value ocaml_cvSetCaptureProperty(value vcapture,value vprop, + value vval) +{ + CAMLparam3(vcapture, vprop, vval); + ERRWRAP(cvSetCaptureProperty(Capture_val(vcapture), + cv_cap_table[Int_val(vprop)], + Double_val(vval))); + CAMLreturn(Val_unit); +} + +extern "C" CAMLprim value ocaml_cvGetCaptureProperty(value vcapture,value vprop) +{ + CAMLparam2(vcapture, vprop); + double ret; + ERRWRAP(ret = cvGetCaptureProperty(Capture_val(vcapture), + cv_cap_table[Int_val(vprop)])); + CAMLreturn(caml_copy_double(ret)); +} + #define Int_var_val(v) (*(int**) (Data_custom_val(v))) CAMLexport void caml_finalize_Int_var(value vvar) @@ -242,7 +619,7 @@ CAMLexport void caml_finalize_Int_var(value vvar) } static struct custom_operations int_var_operations = { - "ocaml_opencv_int_var", + (char*) "ocaml_opencv_int_var", caml_finalize_Int_var, custom_compare_default, custom_hash_default, @@ -264,12 +641,12 @@ CAMLexport value caml_alloc_int_var(int def) { value res; res = caml_alloc_custom(&int_var_operations, sizeof(int*), 1, 1000); - Int_var_val(res) = cv_malloc(sizeof(int)); + Int_var_val(res) = (int*) cv_malloc(sizeof(int)); *(Int_var_val(res)) = def; return res; } -CAMLprim value ocaml_create_int_var(value vdef) +extern "C" CAMLprim value ocaml_create_int_var(value vdef) { CAMLparam1 (vdef); CAMLlocal1 (res); @@ -277,14 +654,14 @@ CAMLprim value ocaml_create_int_var(value vdef) CAMLreturn (res); } -CAMLprim value ocaml_get_int_var(value vvar) +extern "C" CAMLprim value ocaml_get_int_var(value vvar) { CAMLparam1 (vvar); int* var = Int_var_val(vvar); CAMLreturn (Val_int(*var)); } -CAMLprim value ocaml_set_int_var(value vvar, value vval) +extern "C" CAMLprim value ocaml_set_int_var(value vvar, value vval) { CAMLparam2 (vvar, vval); int* var = Int_var_val(vvar); @@ -292,7 +669,7 @@ CAMLprim value ocaml_set_int_var(value vvar, value vval) CAMLreturn (Val_unit); } -CAMLprim value ocaml_cvCreateTrackbar(value vname, value vwindow, value vvar, value vmax) +extern "C" CAMLprim value ocaml_cvCreateTrackbar(value vname, value vwindow, value vvar, value vmax) { CAMLparam4 (vname, vwindow, vvar, vmax); int res = cvCreateTrackbar(String_val(vname), String_val(vwindow), @@ -375,12 +752,12 @@ int conversion_table[] = { CV_HLS2RGB }; -int ocaml_get_color_conversion(int vtype) +extern "C" CAMLprim value ocaml_get_color_conversion(value vtype) { return (Val_int(conversion_table[Int_val(vtype)])); } -CAMLprim value ocaml_cvCvtColor(value vsrc, value vdst, value vtype) +extern "C" CAMLprim value ocaml_cvCvtColor(value vsrc, value vdst, value vtype) { CAMLparam3(vsrc, vdst, vtype); cvCvtColor(Image_val(vsrc)->image, @@ -389,7 +766,7 @@ CAMLprim value ocaml_cvCvtColor(value vsrc, value vdst, value vtype) CAMLreturn(Val_unit); } -CAMLprim value ocaml_cvSplit(value vsrc, value vdst0, +extern "C" CAMLprim value ocaml_cvSplit(value vsrc, value vdst0, value vdst1, value vdst2, value vdst3) { CAMLparam5(vsrc, vdst0, vdst1, vdst2, vdst3); @@ -408,7 +785,7 @@ CAMLprim value ocaml_cvSplit(value vsrc, value vdst0, CAMLreturn(Val_unit); } -CAMLprim value ocaml_cvMerge(value vsrc0, value vsrc1, value vsrc2, +extern "C" CAMLprim value ocaml_cvMerge(value vsrc0, value vsrc1, value vsrc2, value vsrc3, value vdst) { CAMLparam5(vsrc0, vsrc1, vsrc2, vsrc3, vdst); @@ -442,7 +819,7 @@ int adaptiveMethod_table[] = { CV_ADAPTIVE_THRESH_GAUSSIAN_C, }; -CAMLprim value ocaml_cvThreshold(value vsrc, value vdst, value vthreshold, +extern "C" CAMLprim value ocaml_cvThreshold(value vsrc, value vdst, value vthreshold, value vmaxValue, value vthresholdType) { CAMLparam5(vsrc, vdst, vthreshold, vmaxValue, vthresholdType); @@ -454,7 +831,7 @@ CAMLprim value ocaml_cvThreshold(value vsrc, value vdst, value vthreshold, CAMLreturn(Val_unit); } -CAMLprim value ocaml_cvAdaptiveThreshold(value vsrc, value vdst, value vmaxValue, +extern "C" CAMLprim value ocaml_cvAdaptiveThreshold(value vsrc, value vdst, value vmaxValue, value vadaptiveMethod, value vthresholdType, value vblockSize, value vparam1) { @@ -470,52 +847,88 @@ CAMLprim value ocaml_cvAdaptiveThreshold(value vsrc, value vdst, value vmaxValue CAMLreturn(Val_unit); } -CAMLprim value ocaml_cvAdaptiveThreshold_bytecode( value * argv, int argn ) +extern "C" CAMLprim value ocaml_cvAdaptiveThreshold_bytecode( value * argv, int argn ) { return ocaml_cvAdaptiveThreshold( argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6] ); } -/* CAMLprim value ocaml_get_float_3point(value vimage, value vindex, value vres) */ -/* { */ -/* IplImage* image = Image_val(vsrc)->image; */ -/* int index = Int_val(vindex); */ -/* Store_double_field(vres,0,image->imageData[3*i]); */ -/* Store_double_field(vres,1,image->imageData[3*i+1]); */ -/* Store_double_field(vres,2,image->imageData[3*i+2]); */ -/* CAMLreturn(Val_unit); */ -/* } */ - -/* CAMLprim value ocaml_set_float_3point(value vimage, value vindex, value vval) */ -/* { */ -/* IplImage* image = Image_val(vsrc)->image; */ -/* int index = Int_val(vindex); */ -/* camlimage->imageData[3*i] = Double_field(vval,0); */ -/* camlimage->imageData[3*i+1] = Double_field(vval,1); */ -/* camlimage->imageData[3*i+2] = Double_field(vval,2); */ -/* CAMLreturn(Val_unit); */ -/* } */ - -/* CAMLprim value ocaml_get_int_3point(value vimage, value vindex, value vres) */ -/* { */ -/* IplImage* image = Image_val(vimage)->image; */ -/* int i = Int_val(vindex); */ -/* Field(vres,0) = image->imageData[3*i]; */ -/* Field(vres,1) = image->imageData[3*i+1]; */ -/* Field(vres,2) = image->imageData[3*i+2]; */ -/* return Val_unit; */ -/* } */ - -/* CAMLprim value ocaml_set_int_3point(value vimage, value vindex, value vres) */ -/* { */ -/* IplImage* image = Image_val(vimage)->image; */ -/* int i = Int_val(vindex); */ -/* image->imageData[3*i] = Field(vres,0); */ -/* image->imageData[3*i+1] = Field(vres,1); */ -/* image->imageData[3*i+2] = Field(vres,2); */ -/* return Val_unit; */ -/* } */ - -CAMLprim value ocaml_image_to_bigarray(value vimage) +extern "C" CAMLprim value ocaml_cvCanny(value vimage, value vedges, + value vthreshold1, value vthreshold2, + value vapertureSize) +{ + CAMLparam5(vimage, vedges, vthreshold1, vthreshold2, vapertureSize); + + cvCanny(Image_val(vimage)->image, + Image_val(vedges)->image, + Double_val(vthreshold1), + Double_val(vthreshold2), + Int_val(vapertureSize)); + + CAMLreturn(Val_unit); +} + +/* +extern "C" CAMLprim value ocaml_medianBlur(value vsrc, value vdst, value ksize) +{ + CAMLparam3(vsrc, vdst, ksize); + + Mat dst = Mat(Image_val(vdst)->image); + + ERRWRAP( + medianBlur(Mat(Image_val(vsrc)->image), + &dst, + Int_val(ksize))); + + CAMLreturn(Val_unit); +} +*/ + +extern "C" CAMLprim value ocaml_cvGoodFeaturesToTrack( + value image, + value vcorners, + value qualityLevel, + value minDistance, + value vmask, + value blockSize, + value useHarris, + value k) +{ + CAMLparam5(image, + vcorners, + qualityLevel, + minDistance, + vmask); + CAMLxparam3(blockSize, + useHarris, + k); + + CvArr* mask = Is_long(vmask) ? NULL : Image_val(Field(vmask,0))->image; + CvPoint2D32f* corners = (CvPoint2D32f*) Data_bigarray_val(vcorners); + int cornerCount = Bigarray_val(vcorners)->dim[0];; + + ERRWRAP( + cvGoodFeaturesToTrack(Image_val(image)->image, + NULL, + NULL, + corners, + &cornerCount, + Double_val(qualityLevel), + Double_val(minDistance), + mask, + Int_val(blockSize), + Bool_val(useHarris), + Double_val(k))); + + CAMLreturn(Val_int(cornerCount)); +} + +extern "C" CAMLprim value ocaml_cvGoodFeaturesToTrack_bytecode( value * argv, int argn ) +{ + return ocaml_cvGoodFeaturesToTrack( argv[0], argv[1], argv[2], argv[3], + argv[4], argv[5], argv[6], argv[7] ); +} + +extern "C" CAMLprim value ocaml_image_to_bigarray(value vimage) { CAMLparam1(vimage); CAMLlocal1(ba); @@ -528,150 +941,26 @@ CAMLprim value ocaml_image_to_bigarray(value vimage) CAMLreturn(ba); } -CAMLprim value ocaml_image_channels(value vimage) +extern "C" CAMLprim value ocaml_image_channels(value vimage) { CAMLparam1(vimage); CAMLreturn(Val_int(Image_val(vimage)->image->nChannels)); } -CAMLprim value ocaml_image_depth(value vimage) +extern "C" CAMLprim value ocaml_image_depth(value vimage) { CAMLparam1(vimage); CAMLreturn(Val_int(Image_val(vimage)->image->depth)); } -CAMLprim value ocaml_image_data_order(value vimage) +extern "C" CAMLprim value ocaml_image_data_order(value vimage) { CAMLparam1(vimage); CAMLreturn(Val_int(Image_val(vimage)->image->dataOrder)); } -static CvScalar CvScalar_val(value v) { - double v0 = Double_val(Field(v,0)); - double v1 = Double_val(Field(v,1)); - double v2 = Double_val(Field(v,2)); - double v3 = Double_val(Field(v,3)); - return (cvScalar(v0,v1,v2,v3)); -} - -static CvPoint CvPoint_val(value v) { - int v0 = Int_val(Field(v,0)); - int v1 = Int_val(Field(v,1)); - return (cvPoint(v0,v1)); -} - -/* unused -static CvPoint2D32f CvPoint2D32f_val(value v) { - double v0 = Double_val(Field(v,0)); - double v1 = Double_val(Field(v,1)); - return (cvPoint2D32f(v0,v1)); -} - -static CvPoint3D32f CvPoint3D32f_val(value v) { - double v0 = Double_val(Field(v,0)); - double v1 = Double_val(Field(v,1)); - double v2 = Double_val(Field(v,2)); - return (cvPoint3D32f(v0,v1,v2)); -} - -static CvPoint2D64f CvPoint2D64f_val(value v) { - double v0 = Double_val(Field(v,0)); - double v1 = Double_val(Field(v,1)); - return (cvPoint2D64f(v0,v1)); -} - -static CvPoint3D64f CvPoint3D64f_val(value v) { - double v0 = Double_val(Field(v,0)); - double v1 = Double_val(Field(v,1)); - double v2 = Double_val(Field(v,2)); - return (cvPoint3D64f(v0,v1,v2)); -} -*/ - -static CvSize CvSize_val(value v) { - int v0 = Int_val(Field(v,0)); - int v1 = Int_val(Field(v,1)); - return (cvSize(v0,v1)); -} - -static CvTermCriteria CvTermCriteria_val(value v) { - int tc_iter = Int_val(Field(v,0)); - int tc_eps = Int_val(Field(v,1)); - int type = 0; - if (tc_iter) type |= CV_TERMCRIT_ITER; - if (tc_eps) type |= CV_TERMCRIT_EPS; - int max_iter = Int_val(Field(v,2)); - double epsilon = Double_val(Field(v,3)); - return (cvTermCriteria(type,max_iter,epsilon)); -} - -static CvMat CvMat_val(value v) { - void* data = Data_bigarray_val(v); - int rows = Bigarray_val(v)->dim[0]; - int cols = Bigarray_val(v)->dim[1]; - int channels = Bigarray_val(v)->dim[2]; - int kind = Bigarray_val(v)->flags & BIGARRAY_KIND_MASK; - int type = 0; - switch (kind) { - - case BIGARRAY_FLOAT32: - switch (channels) { - case 1: - type = CV_32FC1; - break... [truncated message content] |
From: Pierre C. <Ba...@us...> - 2012-05-09 23:28: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 293b6fc50d49888734dcd618762fe9cafff39bfd (commit) from 74be0d4bea5261dc4196f4d9e3c6a9850ea9aa7e (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 293b6fc50d49888734dcd618762fe9cafff39bfd Author: chicco <cha...@cr...> Date: Thu May 10 01:28:06 2012 +0200 [ax12 recording] fix a few problems ----------------------------------------------------------------------- Changes: diff --git a/info/control2011/src/tools/krobot_ax12_clean.ml b/info/control2011/src/tools/krobot_ax12_clean.ml index 62b5030..121990e 100644 --- a/info/control2011/src/tools/krobot_ax12_clean.ml +++ b/info/control2011/src/tools/krobot_ax12_clean.ml @@ -82,7 +82,7 @@ let prepare l = l let map_speed l c = - let f v = { v with speed = v.speed *. c; time = v.time /. c } in + let f v = { v with speed = abs_float (v.speed *. c); time = v.time /. c } in List.map f l let print_info { id; pos; speed; torque; time } = diff --git a/info/control2011/src/tools/krobot_ax12_control.ml b/info/control2011/src/tools/krobot_ax12_control.ml index d50c324..b906cdc 100644 --- a/info/control2011/src/tools/krobot_ax12_control.ml +++ b/info/control2011/src/tools/krobot_ax12_control.ml @@ -9,8 +9,9 @@ type action = let run_file = ref None let ax12_id = ref 0 -let ax12_speed = ref 1 +let ax12_speed = ref 50 let commands = ref [] +let reset = ref false let add_goto pos = commands := ( Do (Ax12_Goto (!ax12_id, pos, !ax12_speed)) ) :: !commands let add_sleep t = commands := ( Sleep t ) :: !commands let add_torque b = commands := ( Do (Ax12_Set_Torque_Enable (!ax12_id, b)) ) :: !commands @@ -27,6 +28,7 @@ let spec = "-state", Unit add_request, "request the ax12 state"; "-sleep", Float add_sleep, "sleep"; "-file", String (fun s -> run_file := Some s), "run sequence from file"; + "-reset", Unit (fun () -> reset := true), "reset position"; ] let msg = "do things with ax12" @@ -41,7 +43,6 @@ let run = function let rec go = function | [] -> Lwt.return () | t::q -> - Printf.printf "go\n%!"; lwt () = run t in go q @@ -73,11 +74,22 @@ let to_actions l = let _, l = List.fold_left f (0.,[]) l in List.rev l +let init_servos l = + let f l v = + try ignore (List.find (fun x -> x.id = v.id) l); + l + with + | Not_found -> v::l in + let l = List.fold_left f [] l in + List.map (fun v -> { v with speed = float !ax12_speed }) l + lwt () = match !run_file with | None -> go (List.rev !commands) | Some f -> - Printf.printf "run file\n%!"; - let actions = to_actions (read (open_in f)) in - Printf.printf "truc %i\n%!" (List.length actions); - go actions + let file = read (open_in f) in + let orders = + if !reset + then init_servos file + else file in + go (to_actions orders) hooks/post-receive -- krobot |