A.R.G.U.S 2.1.0
Adaptive Real-Time Guardian for Unsafe Situations
Loading...
Searching...
No Matches
MotionController.hpp
Go to the documentation of this file.
1
6#pragma once
7
8#include <cstdint>
9
21
27 DISABLED,
28 ENABLED,
29 FAULT
30};
31
36 std::uint8_t base{0};
37 std::uint8_t lower{4};
38 std::uint8_t upper{8};
39 std::uint8_t gripper{12};
40};
41
46 std::uint16_t base_ticks{0};
47 std::uint16_t lower_ticks{0};
48 std::uint16_t upper_ticks{0};
49 std::uint16_t gripper_ticks{0};
50};
51
56public:
57 static constexpr std::uint8_t kServoCount = 4;
58 static constexpr std::uint8_t kPca9685ChannelCount = 16;
59 static constexpr std::uint16_t kMaxPulseTicks = 4095;
60
64 MotionController() noexcept;
65
69 ~MotionController() noexcept;
70
72 MotionController& operator=(const MotionController&) = delete;
74 MotionController& operator=(MotionController&&) = delete;
75
84 bool initialise(
85 const char* i2c_device_path = "/dev/i2c-1",
86 std::uint8_t device_address = 0x40,
87 float pwm_frequency_hz = 50.0f,
88 MotionChannelMap channel_map = {}) noexcept;
89
95 bool setTargets(const MeArmJointTargets& targets) noexcept;
96
100 void freeze() noexcept;
101
106 bool enable() noexcept;
107
111 void shutdown() noexcept;
112
117 bool isInitialised() const noexcept;
118
123 bool isEnabled() const noexcept;
124
129 bool isFrozen() const noexcept;
130
135 MotionOutputState outputState() const noexcept;
136
141 MotionControllerError lastError() const noexcept;
142
147 const char* lastErrorString() const noexcept;
148
149private:
150 bool configurePca9685(float pwm_frequency_hz) noexcept;
151 bool writeTargetsToHardware(const MeArmJointTargets& targets) noexcept;
152 bool writeChannelPulse(std::uint8_t channel, std::uint16_t pulse_ticks) noexcept;
153 bool writeRegister(std::uint8_t reg, std::uint8_t value) noexcept;
154 bool writeRegisters(std::uint8_t start_reg,
155 const std::uint8_t* values,
156 std::uint8_t value_count) noexcept;
157 bool setAllOutputsEnabled(bool enabled) noexcept;
158 bool hasValidChannelMap(const MotionChannelMap& channel_map) const noexcept;
159 void setFault(MotionControllerError error) noexcept;
160
161 int i2c_fd_;
162 MotionChannelMap channel_map_;
163 MeArmJointTargets cached_targets_;
164 MotionOutputState output_state_;
165 MotionControllerError last_error_;
166 bool frozen_;
167};
MotionControllerError
Error codes reported by MotionController operations.
@ NOT_INITIALISED
Controller is not initialised.
@ DEVICE_SELECT_FAILED
Failed to select I2C slave address.
@ DEVICE_IO_FAILED
I/O transaction failed.
@ DEVICE_OPEN_FAILED
Failed to open I2C device.
@ INVALID_ARGUMENT
Invalid input argument.
MotionOutputState
High-level state of motion output availability.
@ UNINITIALISED
Hardware not initialised.
@ DISABLED
Initialised but outputs disabled.
@ FAULT
Fault state; output path blocked until reset/re-init.
@ ENABLED
Outputs enabled and can accept target writes.
Low-level motion output driver for the PCA9685 servo board.
MotionControllerError lastError() const noexcept
Get last controller error code.
static constexpr std::uint8_t kServoCount
Number of logical servos controlled.
MotionController() noexcept
Construct motion controller in uninitialised state.
void freeze() noexcept
Freeze/disable motion output immediately.
bool isEnabled() const noexcept
Check whether motion output is currently enabled.
const char * lastErrorString() const noexcept
Get human-readable last error string.
bool initialise(const char *i2c_device_path="/dev/i2c-1", std::uint8_t device_address=0x40, float pwm_frequency_hz=50.0f, MotionChannelMap channel_map={}) noexcept
Initialise PCA9685 output path.
bool isFrozen() const noexcept
Check whether output is currently frozen.
static constexpr std::uint8_t kPca9685ChannelCount
PCA9685 total channels.
bool isInitialised() const noexcept
Check whether controller was successfully initialised.
bool setTargets(const MeArmJointTargets &targets) noexcept
Write joint targets to hardware when motion is enabled.
void shutdown() noexcept
Disable outputs and close hardware resources.
static constexpr std::uint16_t kMaxPulseTicks
Maximum 12-bit pulse value.
MotionOutputState outputState() const noexcept
Get current output state.
bool enable() noexcept
Enable motion output after successful initialisation.
Raw PWM tick targets for each MeArm joint.
std::uint16_t upper_ticks
Upper target pulse ticks.
std::uint16_t lower_ticks
Lower target pulse ticks.
std::uint16_t base_ticks
Base target pulse ticks.
std::uint16_t gripper_ticks
Gripper target pulse ticks.
Mapping of logical MeArm joints to PCA9685 channels.
std::uint8_t upper
Upper joint PWM channel.
std::uint8_t gripper
Gripper joint PWM channel.
std::uint8_t lower
Lower joint PWM channel.
std::uint8_t base
Base joint PWM channel.