summaryrefslogtreecommitdiff
path: root/digital
diff options
context:
space:
mode:
authorNicolas Schodet2013-03-26 21:00:36 +0100
committerNicolas Schodet2013-03-26 22:22:20 +0100
commit52d4a4917e49e3864cb50cb37cfd86537e42a287 (patch)
tree8bca37e49f76dc18eb546853704e05a969dbf000 /digital
parentfd2970444d83ac38e0d6af53a6b4dada4226250e (diff)
digital/io-hub/src/apbirthday: add US sensors ADC
Diffstat (limited to 'digital')
-rw-r--r--digital/io-hub/src/apbirthday/Makefile2
-rw-r--r--digital/io-hub/src/apbirthday/hardware.hh7
-rw-r--r--digital/io-hub/src/apbirthday/hardware.host.cc6
-rw-r--r--digital/io-hub/src/apbirthday/hardware.stm32.cc8
-rw-r--r--digital/io-hub/src/apbirthday/robot.cc18
-rw-r--r--digital/io-hub/src/apbirthday/robot.hh2
-rw-r--r--digital/io-hub/tools/io_hub/mex.py7
7 files changed, 45 insertions, 5 deletions
diff --git a/digital/io-hub/src/apbirthday/Makefile b/digital/io-hub/src/apbirthday/Makefile
index 473acdff..02cd0d4e 100644
--- a/digital/io-hub/src/apbirthday/Makefile
+++ b/digital/io-hub/src/apbirthday/Makefile
@@ -10,7 +10,7 @@ apbirthday_SOURCES = main.cc robot.cc hardware.host.cc hardware.stm32.cc \
angfsm.host.c angfsm_gen_arm_AI.arm.c fsm_queue.cc \
$(AVR_SOURCES)
-MODULES = utils hal/gpio hal/uart hal/usb hal/i2c hal/spi \
+MODULES = utils hal/gpio hal/adc hal/uart hal/usb hal/i2c hal/spi \
base/proto dev/avrisp
# Hack mode, include old code from AVR modules.
diff --git a/digital/io-hub/src/apbirthday/hardware.hh b/digital/io-hub/src/apbirthday/hardware.hh
index f3378170..5713f921 100644
--- a/digital/io-hub/src/apbirthday/hardware.hh
+++ b/digital/io-hub/src/apbirthday/hardware.hh
@@ -26,6 +26,7 @@
#include "ucoolib/hal/uart/uart.hh"
#include "ucoolib/hal/gpio/gpio.hh"
+#include "ucoolib/hal/adc/adc.hh"
#include "ucoolib/hal/i2c/i2c.hh"
#ifdef TARGET_stm32
# include "ucoolib/hal/usb/usb.hh"
@@ -84,6 +85,12 @@ struct Hardware
pneum_open;
static const int inputs_nb = 9;
static const int outputs_nb = 21;
+#ifdef TARGET_stm32
+ ucoo::AdcHard adc;
+ ucoo::AdcHardChannel adc_dist0, adc_dist1, adc_dist2, adc_dist3;
+#else
+ ucoo::AdcHost adc_dist0, adc_dist1, adc_dist2, adc_dist3;
+#endif
Hardware ();
// Wait until next cycle.
void wait ();
diff --git a/digital/io-hub/src/apbirthday/hardware.host.cc b/digital/io-hub/src/apbirthday/hardware.host.cc
index ba25401b..1cffaa7e 100644
--- a/digital/io-hub/src/apbirthday/hardware.host.cc
+++ b/digital/io-hub/src/apbirthday/hardware.host.cc
@@ -61,7 +61,11 @@ Hardware::Hardware ()
gift_out (host, "gift_out"),
gift_in (host, "gift_in"),
ballon_funny_action (host, "ballon_funny_action"),
- pneum_open (host, "pneum_open")
+ pneum_open (host, "pneum_open"),
+ adc_dist0 (host, "dist0", 1 << 12),
+ adc_dist1 (host, "dist1", 1 << 12),
+ adc_dist2 (host, "dist2", 1 << 12),
+ adc_dist3 (host, "dist3", 1 << 12)
{
dev_uart.block (false);
zb_uart.block (false);
diff --git a/digital/io-hub/src/apbirthday/hardware.stm32.cc b/digital/io-hub/src/apbirthday/hardware.stm32.cc
index a3cd4c1d..ed051a4a 100644
--- a/digital/io-hub/src/apbirthday/hardware.stm32.cc
+++ b/digital/io-hub/src/apbirthday/hardware.stm32.cc
@@ -54,7 +54,10 @@ Hardware::Hardware ()
glass_upper_clamp_up (GPIOD, 3), glass_upper_clamp_down (GPIOC, 10),
gift_out (GPIOD, 4), gift_in (GPIOC, 11),
ballon_funny_action (GPIOB, 7),
- pneum_open (GPIOD, 5)
+ pneum_open (GPIOD, 5),
+ adc (0),
+ adc_dist0 (adc, 0), adc_dist1 (adc, 1),
+ adc_dist2 (adc, 2), adc_dist3 (adc, 3)
{
rcc_peripheral_enable_clock (&RCC_AHB1ENR, RCC_AHB1ENR_IOPAEN);
rcc_peripheral_enable_clock (&RCC_AHB1ENR, RCC_AHB1ENR_IOPBEN);
@@ -84,6 +87,9 @@ Hardware::Hardware ()
gpio_set_af (GPIOA, GPIO_AF4, GPIO8);
gpio_set_af (GPIOC, GPIO_AF4, GPIO9);
main_i2c.enable ();
+ // ADC.
+ gpio_mode_setup (GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE,
+ GPIO0 | GPIO1 | GPIO2 | GPIO3);
// Cycle timer, 4 ms period.
rcc_peripheral_enable_clock (&RCC_APB1ENR, RCC_APB1ENR_TIM3EN);
TIM3_PSC = 2 * rcc_ppre1_frequency / 1000000 - 1; // 1 ┬Ás prescaler
diff --git a/digital/io-hub/src/apbirthday/robot.cc b/digital/io-hub/src/apbirthday/robot.cc
index 2dc3de95..d8b47387 100644
--- a/digital/io-hub/src/apbirthday/robot.cc
+++ b/digital/io-hub/src/apbirthday/robot.cc
@@ -41,7 +41,7 @@ Robot::Robot ()
outputs_set_ (outputs_, lengthof (outputs_)),
stats_proto_ (0),
stats_chrono_ (false), stats_chrono_last_s_ (-1),
- stats_inputs_ (0)
+ stats_inputs_ (0), stats_usdist_ (0)
{
robot = this;
unsigned i = 0;
@@ -212,6 +212,12 @@ Robot::proto_handle (ucoo::Proto &proto, char cmd, const uint8_t *args, int size
stats_inputs_cpt_ = stats_inputs_ = args[0];
stats_proto_ = &proto;
break;
+ case c ('U', 1):
+ // US distance sensors stats.
+ // 1B: stat interval.
+ stats_usdist_cpt_ = stats_usdist_ = args[0];
+ stats_proto_ = &proto;
+ break;
default:
proto.send ('?');
return;
@@ -245,5 +251,15 @@ Robot::proto_stats ()
stats_proto_->send ('I', "L", inputs);
stats_inputs_cpt_ = stats_inputs_;
}
+ if (stats_usdist_ && !--stats_usdist_cpt_)
+ {
+ // TODO: this is a hack, only work in simulation.
+ stats_proto_->send ('U', "HHHH",
+ hardware.adc_dist0.read (),
+ hardware.adc_dist1.read (),
+ hardware.adc_dist2.read (),
+ hardware.adc_dist3.read ());
+ stats_usdist_cpt_ = stats_usdist_;
+ }
}
diff --git a/digital/io-hub/src/apbirthday/robot.hh b/digital/io-hub/src/apbirthday/robot.hh
index 99997fd0..492b6e2d 100644
--- a/digital/io-hub/src/apbirthday/robot.hh
+++ b/digital/io-hub/src/apbirthday/robot.hh
@@ -88,6 +88,8 @@ class Robot : public ucoo::Proto::Handler
int stats_chrono_last_s_;
/// Input stats interval and counter.
int stats_inputs_, stats_inputs_cpt_;
+ /// US distance sensors stats interval and counter.
+ int stats_usdist_, stats_usdist_cpt_;
};
/// Global instance pointer.
diff --git a/digital/io-hub/tools/io_hub/mex.py b/digital/io-hub/tools/io_hub/mex.py
index 9ad38a69..ff3bea61 100644
--- a/digital/io-hub/tools/io_hub/mex.py
+++ b/digital/io-hub/tools/io_hub/mex.py
@@ -26,6 +26,7 @@
from utils.observable import Observable
import simu.mex.msg
import simu.link.mex_gpio
+import simu.link.mex_adc_channel
ADC_NB = 8
@@ -254,7 +255,8 @@ class Mex:
self.notify ()
def __init__ (self, node, instance = 'io-hub0',
- pwm_nb = 0, contact_nb = 0, output_nb = 0, gpios = False, codebar = False):
+ pwm_nb = 0, contact_nb = 0, output_nb = 0, gpios = False,
+ adc_channels = False, codebar = False):
self.adc = tuple (self.ADC (node, instance, i) for i in range (0, ADC_NB))
if pwm_nb:
self.pwm = tuple (self.PWM () for i in range (0, pwm_nb))
@@ -269,6 +271,9 @@ class Mex:
self.output)
if gpios:
self.gpios = simu.link.mex_gpio.MexGpio.Pack (node, instance)
+ if adc_channels:
+ self.adc_channels = simu.link.mex_adc_channel.MexAdcChannel.Pack (
+ node, instance)
if codebar:
self.__codebar_pack = self.Codebar.Pack (node, instance)
self.codebar = tuple (self.Codebar (self.__codebar_pack, i)