From f5ad780b2d16abcb0d8da15cdbf6075815109023 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Mon, 1 Apr 2013 18:42:23 +0200 Subject: digital/io-hub/src/apbirthday: add cake distance sensors support --- digital/io-hub/src/apbirthday/hardware.hh | 2 ++ digital/io-hub/src/apbirthday/hardware.host.cc | 2 ++ digital/io-hub/src/apbirthday/hardware.stm32.cc | 3 ++- digital/io-hub/src/apbirthday/robot.cc | 14 +++++++++++++- digital/io-hub/src/apbirthday/robot.hh | 2 ++ 5 files changed, 21 insertions(+), 2 deletions(-) (limited to 'digital/io-hub/src') diff --git a/digital/io-hub/src/apbirthday/hardware.hh b/digital/io-hub/src/apbirthday/hardware.hh index 63665222..dbf98e62 100644 --- a/digital/io-hub/src/apbirthday/hardware.hh +++ b/digital/io-hub/src/apbirthday/hardware.hh @@ -93,9 +93,11 @@ struct Hardware #ifdef TARGET_stm32 ucoo::AdcHard adc; ucoo::AdcHardChannel adc_dist0, adc_dist1, adc_dist2, adc_dist3; + ucoo::AdcHardChannel adc_cake_front, adc_cake_back; ucoo::AdcHardChannel adc_pressure; #else ucoo::AdcHost adc_dist0, adc_dist1, adc_dist2, adc_dist3; + ucoo::AdcHost adc_cake_front, adc_cake_back; ucoo::AdcHost adc_pressure; #endif #ifdef TARGET_host diff --git a/digital/io-hub/src/apbirthday/hardware.host.cc b/digital/io-hub/src/apbirthday/hardware.host.cc index 39fe110b..2a906864 100644 --- a/digital/io-hub/src/apbirthday/hardware.host.cc +++ b/digital/io-hub/src/apbirthday/hardware.host.cc @@ -66,6 +66,8 @@ Hardware::Hardware () adc_dist1 (host, "dist1", 1 << 12), adc_dist2 (host, "dist2", 1 << 12), adc_dist3 (host, "dist3", 1 << 12), + adc_cake_front (host, "cake_front", 1 << 12), + adc_cake_back (host, "cake_back", 1 << 12), adc_pressure (host, "pressure", 1 << 12), simu_report (host) { diff --git a/digital/io-hub/src/apbirthday/hardware.stm32.cc b/digital/io-hub/src/apbirthday/hardware.stm32.cc index 46e1972b..be0c9729 100644 --- a/digital/io-hub/src/apbirthday/hardware.stm32.cc +++ b/digital/io-hub/src/apbirthday/hardware.stm32.cc @@ -60,6 +60,7 @@ Hardware::Hardware () adc (0), adc_dist0 (adc, 0), adc_dist1 (adc, 1), adc_dist2 (adc, 2), adc_dist3 (adc, 3), + adc_cake_front (adc, 6), adc_cake_back (adc, 7), adc_pressure (adc, 8) { rcc_peripheral_enable_clock (&RCC_AHB1ENR, RCC_AHB1ENR_IOPAEN); @@ -92,7 +93,7 @@ Hardware::Hardware () main_i2c.enable (); // ADC. gpio_mode_setup (GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, - GPIO0 | GPIO1 | GPIO2 | GPIO3); + GPIO0 | GPIO1 | GPIO2 | GPIO3 | GPIO6 | GPIO7); gpio_mode_setup (GPIOB, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO0); adc.enable (); // Cycle timer, 4 ms period. diff --git a/digital/io-hub/src/apbirthday/robot.cc b/digital/io-hub/src/apbirthday/robot.cc index 35dc891a..900a4fda 100644 --- a/digital/io-hub/src/apbirthday/robot.cc +++ b/digital/io-hub/src/apbirthday/robot.cc @@ -50,7 +50,7 @@ Robot::Robot () outputs_set_ (outputs_, lengthof (outputs_)), stats_proto_ (0), stats_asserv_ (0), stats_chrono_ (false), stats_chrono_last_s_ (-1), - stats_inputs_ (0), stats_usdist_ (0), stats_pressure_ (0) + stats_inputs_ (0), stats_usdist_ (0), stats_cake_ (0), stats_pressure_ (0) { robot = this; // Fill I/O arrays. @@ -257,6 +257,12 @@ Robot::proto_handle (ucoo::Proto &proto, char cmd, const uint8_t *args, int size stats_usdist_cpt_ = stats_usdist_ = args[0]; stats_proto_ = &proto; break; + case c ('G', 1): + // Cake distance sensors stats. + // 1B: stat interval. + stats_cake_cpt_ = stats_cake_ = args[0]; + stats_proto_ = &proto; + break; case c ('F', 1): // Pressure stats. // 1B: stat interval. @@ -309,6 +315,12 @@ Robot::proto_stats () usdist2_.get (), usdist3_.get ()); stats_usdist_cpt_ = stats_usdist_; } + if (stats_cake_ && !--stats_cake_cpt_) + { + stats_proto_->send ('G', "HH", hardware.adc_cake_front.read (), + hardware.adc_cake_back.read ()); + stats_cake_cpt_ = stats_cake_; + } if (stats_pressure_ && !--stats_pressure_cpt_) { stats_proto_->send ('F', "H", pressure.get ()); diff --git a/digital/io-hub/src/apbirthday/robot.hh b/digital/io-hub/src/apbirthday/robot.hh index 1e3a1c97..e9275388 100644 --- a/digital/io-hub/src/apbirthday/robot.hh +++ b/digital/io-hub/src/apbirthday/robot.hh @@ -113,6 +113,8 @@ class Robot : public ucoo::Proto::Handler int stats_inputs_, stats_inputs_cpt_; /// US distance sensors stats interval and counter. int stats_usdist_, stats_usdist_cpt_; + /// Cake distance sensors stats interval and counter. + int stats_cake_, stats_cake_cpt_; /// Pressure stats interval and counter. int stats_pressure_, stats_pressure_cpt_; }; -- cgit v1.2.3