summaryrefslogtreecommitdiff
path: root/digital/io-hub/src/apbirthday
diff options
context:
space:
mode:
authorNicolas Schodet2013-03-29 23:29:57 +0100
committerNicolas Schodet2013-03-30 00:01:58 +0100
commitf7f01cbf53034fb656572758c22f2f392c01290f (patch)
tree9489c820f9129c14329117709a02f4db0a8028f7 /digital/io-hub/src/apbirthday
parent49c97fc3dedbeb92a8169a38ea782113e3e5b575 (diff)
digital/io-hub/src/apbirthday: add mimot & pressure sensor
Diffstat (limited to 'digital/io-hub/src/apbirthday')
-rw-r--r--digital/io-hub/src/apbirthday/Makefile3
-rw-r--r--digital/io-hub/src/apbirthday/hardware.hh2
-rw-r--r--digital/io-hub/src/apbirthday/hardware.host.cc3
-rw-r--r--digital/io-hub/src/apbirthday/hardware.stm32.cc4
-rw-r--r--digital/io-hub/src/apbirthday/robot.cc21
-rw-r--r--digital/io-hub/src/apbirthday/robot.hh7
6 files changed, 36 insertions, 4 deletions
diff --git a/digital/io-hub/src/apbirthday/Makefile b/digital/io-hub/src/apbirthday/Makefile
index f9aa26ed..a785d171 100644
--- a/digital/io-hub/src/apbirthday/Makefile
+++ b/digital/io-hub/src/apbirthday/Makefile
@@ -4,7 +4,8 @@ TARGETS = host stm32f4
PROGS = apbirthday
apbirthday_SOURCES = main.cc robot.cc hardware.host.cc hardware.stm32.cc \
zb_avrisp.stm32.cc \
- i2c_queue.cc asserv.cc chrono.host.cc chrono.stm32.cc \
+ i2c_queue.cc asserv.cc mimot.cc \
+ pressure.cc chrono.host.cc chrono.stm32.cc \
outputs.cc \
top.cc init.cc move.cc candles.cc \
angfsm.host.c angfsm_gen_arm_AI.arm.c fsm_queue.cc \
diff --git a/digital/io-hub/src/apbirthday/hardware.hh b/digital/io-hub/src/apbirthday/hardware.hh
index 5713f921..0cd4c7a5 100644
--- a/digital/io-hub/src/apbirthday/hardware.hh
+++ b/digital/io-hub/src/apbirthday/hardware.hh
@@ -88,8 +88,10 @@ struct Hardware
#ifdef TARGET_stm32
ucoo::AdcHard adc;
ucoo::AdcHardChannel adc_dist0, adc_dist1, adc_dist2, adc_dist3;
+ ucoo::AdcHardChannel adc_pressure;
#else
ucoo::AdcHost adc_dist0, adc_dist1, adc_dist2, adc_dist3;
+ ucoo::AdcHost adc_pressure;
#endif
Hardware ();
// Wait until next cycle.
diff --git a/digital/io-hub/src/apbirthday/hardware.host.cc b/digital/io-hub/src/apbirthday/hardware.host.cc
index 1cffaa7e..a53962b7 100644
--- a/digital/io-hub/src/apbirthday/hardware.host.cc
+++ b/digital/io-hub/src/apbirthday/hardware.host.cc
@@ -65,7 +65,8 @@ Hardware::Hardware ()
adc_dist0 (host, "dist0", 1 << 12),
adc_dist1 (host, "dist1", 1 << 12),
adc_dist2 (host, "dist2", 1 << 12),
- adc_dist3 (host, "dist3", 1 << 12)
+ adc_dist3 (host, "dist3", 1 << 12),
+ adc_pressure (host, "pressure", 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 ed051a4a..a6938643 100644
--- a/digital/io-hub/src/apbirthday/hardware.stm32.cc
+++ b/digital/io-hub/src/apbirthday/hardware.stm32.cc
@@ -57,7 +57,8 @@ Hardware::Hardware ()
pneum_open (GPIOD, 5),
adc (0),
adc_dist0 (adc, 0), adc_dist1 (adc, 1),
- adc_dist2 (adc, 2), adc_dist3 (adc, 3)
+ adc_dist2 (adc, 2), adc_dist3 (adc, 3),
+ adc_pressure (adc, 8)
{
rcc_peripheral_enable_clock (&RCC_AHB1ENR, RCC_AHB1ENR_IOPAEN);
rcc_peripheral_enable_clock (&RCC_AHB1ENR, RCC_AHB1ENR_IOPBEN);
@@ -90,6 +91,7 @@ Hardware::Hardware ()
// ADC.
gpio_mode_setup (GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE,
GPIO0 | GPIO1 | GPIO2 | GPIO3);
+ gpio_mode_setup (GPIOB, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO5);
// 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 6e63b96a..5eff14df 100644
--- a/digital/io-hub/src/apbirthday/robot.cc
+++ b/digital/io-hub/src/apbirthday/robot.cc
@@ -33,16 +33,18 @@ Robot *robot;
Robot::Robot ()
: main_i2c_queue_ (hardware.main_i2c),
asserv (main_i2c_queue_, BOT_SCALE),
+ mimot (main_i2c_queue_),
dev_proto (*this, hardware.dev_uart),
zb_proto (*this, hardware.zb_uart),
usb_proto (*this, hardware.usb),
chrono (90000 - 1000),
+ pressure (hardware.adc_pressure, hardware.pneum_open, mimot.motor0),
candles (1),
fsm_debug_state_ (FSM_DEBUG_RUN),
outputs_set_ (outputs_, lengthof (outputs_)),
stats_proto_ (0),
stats_chrono_ (false), stats_chrono_last_s_ (-1),
- stats_inputs_ (0), stats_usdist_ (0)
+ stats_inputs_ (0), stats_usdist_ (0), stats_pressure_ (0)
{
robot = this;
unsigned i = 0;
@@ -91,6 +93,7 @@ Robot::main_loop ()
// Wait until next cycle.
hardware.wait ();
// Update IO modules.
+ pressure.update ();
outputs_set_.update ();
// Handle communications.
bool sync = main_i2c_queue_.sync ();
@@ -172,6 +175,11 @@ Robot::proto_handle (ucoo::Proto &proto, char cmd, const uint8_t *args, int size
asserv.goto_xy (pos, Asserv::DirectionConsign (args[4]));
}
break;
+ case c ('f', 2):
+ // Set low pressure threshold.
+ // 1w: sensor value, 4096 is full scale.
+ pressure.set (ucoo::bytes_pack (args[0], args[1]));
+ break;
case c ('o', 5):
// Set/clear/toggle outputs.
// - 1d: mask.
@@ -220,6 +228,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 ('F', 1):
+ // Pressure stats.
+ // 1B: stat interval.
+ stats_pressure_cpt_ = stats_pressure_ = args[0];
+ stats_proto_ = &proto;
+ break;
default:
proto.send ('?');
return;
@@ -263,5 +277,10 @@ Robot::proto_stats ()
hardware.adc_dist3.read ());
stats_usdist_cpt_ = stats_usdist_;
}
+ if (stats_pressure_ && !--stats_pressure_cpt_)
+ {
+ stats_proto_->send ('F', "H", pressure.get ());
+ stats_pressure_cpt_ = stats_pressure_;
+ }
}
diff --git a/digital/io-hub/src/apbirthday/robot.hh b/digital/io-hub/src/apbirthday/robot.hh
index c447953e..ceae26b0 100644
--- a/digital/io-hub/src/apbirthday/robot.hh
+++ b/digital/io-hub/src/apbirthday/robot.hh
@@ -27,6 +27,7 @@
#include "asserv.hh"
#include "fsm_queue.hh"
#include "chrono.hh"
+#include "pressure.hh"
#include "outputs.hh"
#include "candles.hh"
@@ -55,6 +56,8 @@ class Robot : public ucoo::Proto::Handler
public:
/// Public access to asserv class.
Asserv asserv;
+ /// Public access to mimot class.
+ Mimot mimot;
private:
/// Proto associated to each serial interface.
ucoo::Proto dev_proto, zb_proto, usb_proto;
@@ -63,6 +66,8 @@ class Robot : public ucoo::Proto::Handler
FsmQueue fsm_queue;
/// Public access to chrono.
Chrono chrono;
+ /// Public access to pressure handling.
+ Pressure pressure;
/// Candles.
Candles candles;
private:
@@ -93,6 +98,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_;
+ /// Pressure stats interval and counter.
+ int stats_pressure_, stats_pressure_cpt_;
};
/// Global instance pointer.