Resurgence (PY2022)
Codebase for the Husky Robotics 2021-2022 rover Resurgence
Loading...
Searching...
No Matches
CANMotor.h
1#pragma once
2
3#include "../world_interface/data.h"
4#include "CAN.h"
5#include "CANUtils.h"
6
7#include <chrono>
8#include <optional>
9
16namespace can::motor {
17
19enum class motormode_t { pwm = MOTOR_UNIT_MODE_PWM, pid = MOTOR_UNIT_MODE_PID };
20
22struct sensor_t {
23 enum { encoder = 0, potentiometer = 1 };
24};
25
32
40void initMotor(deviceserial_t serial);
41
57void initEncoder(deviceserial_t serial, bool invertEncoder, bool zeroEncoder,
58 int32_t pulsesPerJointRev,
59 std::optional<std::chrono::milliseconds> telemetryPeriod);
60
72
85void initPotentiometer(deviceserial_t serial, int32_t posLo, int32_t posHi, uint16_t adcLo,
86 uint16_t adcHi,
87 std::optional<std::chrono::milliseconds> telemetryPeriod);
88
101
108void setMotorMode(deviceserial_t serial, motormode_t mode);
109
116void setMotorPower(deviceserial_t serial, double power);
117
126void setMotorPower(deviceserial_t serial, int16_t power);
127
137void setMotorPIDTarget(deviceserial_t serial, int32_t target);
138
146void setServoPos(deviceserial_t serial, uint8_t servoNum, int32_t angle);
147
158
167
179 deviceserial_t serial,
180 const std::function<void(
181 deviceserial_t serial,
183
191} // namespace can::motor
Represents data measured using a sensor at a given time.
Definition data.h:136
Utilities for interacting with motor boards over a CAN interface.
Definition CANMotor.cpp:20
void pullMotorPosition(deviceserial_t serial)
Poll the position data from a motor board.
Definition CANMotor.cpp:134
void setMotorPower(deviceserial_t serial, double power)
Set the power output of a motor board.
Definition CANMotor.cpp:103
DataPoint< int32_t > getMotorPosition(deviceserial_t serial)
Get the last reported position of a motor.
Definition CANMotor.cpp:129
void initEncoder(deviceserial_t serial, bool invertEncoder, bool zeroEncoder, int32_t pulsesPerJointRev, std::optional< std::chrono::milliseconds > telemetryPeriod)
Initialize an encoder attached to the given motor.
Definition CANMotor.cpp:22
motormode_t
The possible motor modes.
Definition CANMotor.h:19
callbackid_t addLimitSwitchCallback(deviceserial_t serial, const std::function< void(deviceserial_t serial, DataPoint< LimitSwitchData > limitSwitchData)> &callback)
Add a callback that is invoked when the limit switch is triggered for a motor board.
Definition CANMotor.cpp:138
void setMotorPIDTarget(deviceserial_t serial, int32_t target)
Set the position PID target of a motor board.
Definition CANMotor.cpp:116
void initPotentiometer(deviceserial_t serial, int32_t posLo, int32_t posHi, uint16_t adcLo, uint16_t adcHi, std::optional< std::chrono::milliseconds > telemetryPeriod)
Initialize a potentiometer attached to the given motor.
Definition CANMotor.cpp:40
void removeLimitSwitchCallback(callbackid_t id)
Remove a previously registered limit switch callback.
Definition CANMotor.cpp:156
void setMotorMode(deviceserial_t serial, motormode_t mode)
Set the mode of a motor board.
Definition CANMotor.cpp:95
void setLimitSwitchLimits(deviceserial_t serial, int32_t lo, int32_t hi)
Set the limits of the limit switch on a motor board.
Definition CANMotor.cpp:69
void emergencyStopMotors()
Emergency stop all motors on the CAN bus.
Definition CANMotor.cpp:56
void initMotor(deviceserial_t serial)
Initialize a motor.
Definition CANMotor.cpp:64
void setServoPos(deviceserial_t serial, uint8_t servoNum, int32_t angle)
Set the angle of the PCA servo.
Definition CANMotor.cpp:122
void setMotorPIDConstants(deviceserial_t serial, int32_t kP, int32_t kI, int32_t kD)
Set the PID constants for a motor board.
Definition CANMotor.cpp:81
std::tuple< deviceid_t, telemtype_t, uint32_t > callbackid_t
An ID for a telemetry callback.
Definition CAN.h:25
uint8_t deviceserial_t
The type of the device serial number.
Definition CANUtils.h:64
::uint8_t uint8_t
::uint16_t uint16_t
::int32_t int32_t
::int16_t int16_t
The supported motor position sensors.
Definition CANMotor.h:22