2013-07-04 20:56:38 +02:00
|
|
|
#include <timer.h>
|
|
|
|
#include <switch.h>
|
|
|
|
#include "supervisor.h"
|
2013-12-16 21:20:15 +01:00
|
|
|
#include "link.h"
|
2013-07-04 20:56:38 +02:00
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
#include "protocol.h"
|
|
|
|
#include "pwmin.h"
|
|
|
|
#include "blinker.h"
|
2013-12-17 20:48:07 +01:00
|
|
|
#include "servos.h"
|
2013-12-19 00:52:02 +01:00
|
|
|
#include "minbitarray.h"
|
2014-02-21 22:46:56 +01:00
|
|
|
#include "imu.h"
|
2013-07-04 20:56:38 +02:00
|
|
|
|
2013-12-27 21:35:37 +01:00
|
|
|
class RoverIf {
|
|
|
|
public:
|
2013-07-04 20:56:38 +02:00
|
|
|
static void init();
|
|
|
|
static void run();
|
|
|
|
|
|
|
|
static void poll();
|
|
|
|
static void tick();
|
|
|
|
|
2014-01-05 16:21:28 +01:00
|
|
|
static void supervisor_changed();
|
2013-12-29 21:08:31 +01:00
|
|
|
|
2013-12-27 20:16:04 +01:00
|
|
|
static Servos servos;
|
2013-07-04 20:56:38 +02:00
|
|
|
static PWMIn pwmin;
|
2014-02-21 22:46:56 +01:00
|
|
|
static IMU imu;
|
2013-12-16 21:20:15 +01:00
|
|
|
static Link link;
|
2013-07-04 20:56:38 +02:00
|
|
|
static Blinker blinker;
|
|
|
|
static Supervisor supervisor;
|
2013-12-17 20:48:07 +01:00
|
|
|
|
2013-12-29 21:08:31 +01:00
|
|
|
static const int ThrottleChannel = 2;
|
|
|
|
static const int ShutdownChannel = 3;
|
|
|
|
static const int SwitchChannel = 4;
|
2013-12-29 21:14:19 +01:00
|
|
|
|
2013-12-27 21:35:37 +01:00
|
|
|
private:
|
2013-12-29 21:08:31 +01:00
|
|
|
enum class Pending {
|
2013-12-19 00:52:02 +01:00
|
|
|
PWMIn,
|
2014-02-21 22:46:56 +01:00
|
|
|
IMU,
|
2013-12-29 18:50:44 +01:00
|
|
|
State,
|
2013-12-19 00:52:02 +01:00
|
|
|
Heartbeat,
|
|
|
|
Pong,
|
2014-01-14 19:57:54 +01:00
|
|
|
Counters,
|
2013-12-28 21:19:24 +01:00
|
|
|
Version,
|
2014-01-14 19:57:54 +01:00
|
|
|
|
|
|
|
Max,
|
2013-12-19 00:52:02 +01:00
|
|
|
};
|
|
|
|
|
2014-01-14 19:57:54 +01:00
|
|
|
static uint8_t demands_;
|
|
|
|
|
2013-12-29 21:08:31 +01:00
|
|
|
static void defer(Pending event) { pending_.set(static_cast<int>(event)); }
|
2013-12-29 21:14:19 +01:00
|
|
|
static bool tick_one(Timer* ptimer, int divisor);
|
2013-12-19 00:52:02 +01:00
|
|
|
|
2013-12-29 21:08:31 +01:00
|
|
|
static void poll_pwmin();
|
2013-12-30 19:03:04 +01:00
|
|
|
static void poll_link();
|
|
|
|
static void poll_ticks();
|
|
|
|
static void poll_pending();
|
2013-12-29 21:08:31 +01:00
|
|
|
|
2013-12-27 21:35:37 +01:00
|
|
|
static void fill_heartbeat(Protocol::Heartbeat* pmsg);
|
2013-12-29 18:50:44 +01:00
|
|
|
static void fill_pwmin(Protocol::Input* pmsg);
|
2014-02-21 22:46:56 +01:00
|
|
|
static bool fill_imu(Protocol::IMU* pmsg);
|
2013-12-29 18:50:44 +01:00
|
|
|
static void fill_state(Protocol::State* pmsg);
|
2013-12-27 21:35:37 +01:00
|
|
|
static void fill_pong(Protocol::Pong* pmsg);
|
2014-01-14 19:57:54 +01:00
|
|
|
static void fill_counters(Protocol::Counters* pmsg);
|
2013-12-28 21:19:24 +01:00
|
|
|
static void fill_version(Protocol::Version* pmsg);
|
2013-12-19 00:52:02 +01:00
|
|
|
|
2013-12-28 21:19:24 +01:00
|
|
|
static void handle_request(const Protocol::Request& msg);
|
2013-12-29 18:50:44 +01:00
|
|
|
static void handle_demand(const Protocol::Demand& msg);
|
2013-12-20 21:16:01 +01:00
|
|
|
|
2014-01-05 16:21:28 +01:00
|
|
|
static void update_servos(const int8_t* pdemands, bool from_pilot);
|
2013-12-30 19:03:04 +01:00
|
|
|
|
2013-12-17 20:48:07 +01:00
|
|
|
static uint8_t ticks_;
|
2013-12-30 19:03:04 +01:00
|
|
|
static uint8_t pwmin_cycles_;
|
2013-12-29 21:08:31 +01:00
|
|
|
static MinBitArray pending_;
|
2014-01-05 16:21:28 +01:00
|
|
|
static uint8_t pilot_supplied_;
|
2013-07-04 20:56:38 +02:00
|
|
|
};
|