Fang-Robotics-MCB
Fang Robotics Team Codebase
Loading...
Searching...
No Matches
dji_motor.hpp
Go to the documentation of this file.
1/*****************************************************************************/
2/********** !!! WARNING: CODE GENERATED BY TAPROOT. DO NOT EDIT !!! **********/
3/*****************************************************************************/
4
5/*
6 * Copyright (c) 2020-2021 Advanced Robotics at the University of Washington <robomstr@uw.edu>
7 *
8 * This file is part of Taproot.
9 *
10 * Taproot is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * Taproot is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with Taproot. If not, see <https://www.gnu.org/licenses/>.
22 */
23
24#ifndef TAPROOT_DJI_MOTOR_HPP_
25#define TAPROOT_DJI_MOTOR_HPP_
26
27#include <string>
28
32
33#include "modm/math/geometry/angle.hpp"
34
35#include "dji_motor_encoder.hpp"
36#include "dji_motor_ids.hpp"
37#include "motor_interface.hpp"
38
39#if defined(PLATFORM_HOSTED) && defined(ENV_UNIT_TESTS)
40#include <gmock/gmock.h>
41
42#include "tap/mock/dji_motor_encoder_mock.hpp"
43#endif
44
45namespace tap::motor
46{
47#if defined(PLATFORM_HOSTED) && defined(ENV_UNIT_TESTS)
48using Encoder = tap::mock::DjiMotorEncoderMock;
49#else
51#endif
52
71{
72public:
73 // Maximum values for following motors
74 // Controller for the M2006, in mA output
75 static constexpr uint16_t MAX_OUTPUT_C610 = 10000;
76 // Controller for the M3508, in mA output (Mapped to a 20A range though, not 1:1)
77 static constexpr uint16_t MAX_OUTPUT_C620 = 16384;
78 // Controller for the M3510, in mA output (Not known if mapped to 20A range)
79 static constexpr uint16_t MAX_OUTPUT_820R = 32767;
80
81 // Output is in mV
82 static constexpr uint16_t MAX_OUTPUT_GM6020 = 25000;
83 // Output is in mV
84 static constexpr uint16_t MAX_OUTPUT_GM3510 = 29000;
85
99 Drivers* drivers,
100 MotorId desMotorIdentifier,
101 tap::can::CanBus motorCanBus,
102 bool isInverted,
103 const char* name,
104 bool currentControl = false,
105 float gearRatio = 1,
106 uint32_t encoderHomePosition = 0,
107 tap::encoder::EncoderInterface* externalEncoder = nullptr);
108
110
111 void initialize() override;
112
114 {
115 return const_cast<tap::encoder::MultiEncoder<2>*>(&this->encoder);
116 }
117
121 mockable const Encoder& getInternalEncoder() const { return this->internalEncoder; }
122
124
125
132 void processMessage(const modm::can::Message& message) override;
133
144 void setDesiredOutput(int32_t desiredOutput) override;
145
150 bool isMotorOnline() const override;
151
155 mockable void serializeCanSendData(modm::can::Message* txMessage) const;
156
161 int16_t getOutputDesired() const override;
162
163 mockable uint32_t getMotorIdentifier() const;
164
168 int8_t getTemperature() const override;
169
170 int16_t getTorque() const override;
171
172 mockable bool isMotorInverted() const;
173
175
176 mockable const char* getName() const;
177
178 mockable bool isInCurrentControl() const;
179
180private:
181 // wait time before the motor is considered disconnected, in milliseconds
182 static const uint32_t MOTOR_DISCONNECT_TIME = 100;
183
184 const char* motorName;
185
186 Drivers* drivers;
187
188 uint32_t motorIdentifier;
189
190 tap::can::CanBus motorCanBus;
191
192 int16_t desiredOutput;
193
194 int8_t temperature;
195
196 int16_t torque;
197
203 bool motorInverted;
204
205 bool currentControl;
206
207#if defined(PLATFORM_HOSTED) && defined(ENV_UNIT_TESTS)
208 testing::NiceMock<Encoder> internalEncoder;
209#else
210 Encoder internalEncoder;
211#endif
212
214
215 tap::arch::MilliTimeout motorDisconnectTimeout;
216};
217
218} // namespace tap::motor
219
220#endif // TAPROOT_DJI_MOTOR_HPP_
Definition drivers.hpp:70
Definition timeout.hpp:44
Definition can_rx_listener.hpp:91
Definition encoder_interface.hpp:32
Definition multi_encoder.hpp:49
Definition dji_motor_encoder.hpp:55
Definition dji_motor.hpp:71
mockable const char * getName() const
Definition dji_motor.cpp:138
mockable bool isMotorInverted() const
Definition dji_motor.cpp:134
static constexpr uint16_t MAX_OUTPUT_820R
Definition dji_motor.hpp:79
mockable uint32_t getMotorIdentifier() const
Definition dji_motor.cpp:128
mockable ~DjiMotor()
Definition dji_motor.cpp:42
int8_t getTemperature() const override
Definition dji_motor.cpp:130
mockable const Encoder & getInternalEncoder() const
Definition dji_motor.hpp:121
mockable tap::can::CanBus getCanBus() const
Definition dji_motor.cpp:136
mockable void serializeCanSendData(modm::can::Message *txMessage) const
Definition dji_motor.cpp:114
bool isMotorOnline() const override
Definition dji_motor.cpp:104
static constexpr uint16_t MAX_OUTPUT_GM6020
Definition dji_motor.hpp:82
tap::encoder::EncoderInterface * getEncoder() const override
Definition dji_motor.hpp:113
mockable bool isInCurrentControl() const
Definition dji_motor.cpp:140
void initialize() override
Definition dji_motor.cpp:74
int16_t getOutputDesired() const override
Definition dji_motor.cpp:126
void processMessage(const modm::can::Message &message) override
Definition dji_motor.cpp:81
static constexpr uint16_t MAX_OUTPUT_C610
Definition dji_motor.hpp:75
static constexpr uint16_t MAX_OUTPUT_C620
Definition dji_motor.hpp:77
void setDesiredOutput(int32_t desiredOutput) override
Definition dji_motor.cpp:97
int16_t getTorque() const override
Definition dji_motor.cpp:132
static constexpr uint16_t MAX_OUTPUT_GM3510
Definition dji_motor.hpp:84
Definition motor_interface.hpp:34
CanBus
Definition can_bus.hpp:30
Definition dji_motor.cpp:41
MotorId
Definition dji_motor_ids.hpp:38
DjiMotorEncoder Encoder
Definition dji_motor.hpp:50
#define mockable
Wrap class functions that are not already virtual in this function if you wish to mock them.
Definition util_macros.hpp:38
#define DISALLOW_COPY_AND_ASSIGN(Typename)
Definition util_macros.hpp:27