28 , direction{ direction }
33 nodeTx = bus.createTx(
static_cast<uint32_t
>(0x1FF), 8);
35 nodeTx = bus.createTx(
static_cast<uint32_t
>(0x200), 8);
38 const uint32_t rxId =
static_cast<uint32_t
>(0x200 +
Constrain(motorId, 1, 8));
39 nodeRx = bus.createRx(rxId, 8);
40 nodeRx->onReceive = onReceive;
53 , motorId{ other.motorId }
54 , direction{ other.direction }
55 , nodeTx{ other.nodeTx }
56 , nodeRx{ other.nodeRx }
85 return static_cast<int16_t
>(velocity);
94 return static_cast<int16_t
>(current);
102 return nodeRx->data[6];
116 const auto transmitCurrent =
static_cast<int16_t
>(rawCurrent *
Udon::DirectionToSign(direction) * 16384 / 20000);
120 const auto motorIndex = (motorId - 4 - 1) * 2;
121 nodeTx->data[motorIndex + 0] = transmitCurrent >> 8 & 0xff;
122 nodeTx->data[motorIndex + 1] = transmitCurrent >> 0 & 0xff;
126 const auto motorIndex = (motorId - 1) * 2;
127 nodeTx->data[motorIndex + 0] = transmitCurrent >> 8 & 0xff;
128 nodeTx->data[motorIndex + 1] = transmitCurrent >> 0 & 0xff;
151 int64_t offsetAngle = 0;
156 static constexpr int32_t ppr = 8192;
158 static void onReceive(
void* p)
163 const auto currentAngle =
self->nodeRx->data[0] << 8 |
self->nodeRx->data[1];
164 const auto dTheta =
self->angle - currentAngle;
165 self->angle = currentAngle;
168 if (dTheta > ppr / 2)
170 self->offsetAngle += ppr;
172 else if (dTheta < -ppr / 2)
174 self->offsetAngle -= ppr;
194 return { -10000, 10000 };
221 return { -20000, 20000 };
CANバス管理クラス インターフェース
Definition ICanBus.hpp:49
RoboMaster 基底クラス
Definition RoboMasterMotor.hpp:19
double getRawAngle() const
モーターの角度を取得
Definition RoboMasterMotor.hpp:74
void setRawCurrent(int16_t rawCurrent)
Definition RoboMasterMotor.hpp:114
virtual void setCurrent(int16_t current)=0
モーターの電流を設定
RoboMasterBase(const RoboMasterBase &)=delete
コピーコンストラクタ
double getAngle() const
モーターの角度を取得
Definition RoboMasterMotor.hpp:65
RoboMasterBase(Udon::ICanBus &bus, int motorId, Udon::Direction direction=Udon::Direction::Forward)
コンストラクタ
Definition RoboMasterMotor.hpp:25
int16_t getTorqueCurrent() const
モーターのトルク電流を取得
Definition RoboMasterMotor.hpp:91
int16_t getVelocity() const
モーターの速度を取得
Definition RoboMasterMotor.hpp:82
uint8_t getTemperature() const
モーターの温度を取得
Definition RoboMasterMotor.hpp:100
RoboMasterBase(RoboMasterBase &&other)
ムーブコンストラクタ
Definition RoboMasterMotor.hpp:51
virtual Udon::Range< int16_t > getCurrentRange() const =0
指定可能電流範囲
RoboMasterC610クラス
Definition RoboMasterMotor.hpp:183
void setCurrent(int16_t current) override
モーターの電流を設定
Definition RoboMasterMotor.hpp:199
RoboMasterBase(Udon::ICanBus &bus, int motorId, Udon::Direction direction=Udon::Direction::Forward)
コンストラクタ
Definition RoboMasterMotor.hpp:25
Udon::Range< int16_t > getCurrentRange() const override
指定可能電流範囲
Definition RoboMasterMotor.hpp:192
RoboMasterC620クラス
Definition RoboMasterMotor.hpp:210
void setCurrent(int16_t current) override
モーターの電流を設定
Definition RoboMasterMotor.hpp:226
Udon::Range< int16_t > getCurrentRange() const override
指定可能電流範囲
Definition RoboMasterMotor.hpp:219
RoboMasterBase(Udon::ICanBus &bus, int motorId, Udon::Direction direction=Udon::Direction::Forward)
コンストラクタ
Definition RoboMasterMotor.hpp:25
constexpr double Pi
π
Definition Math.hpp:27
int DirectionToSign(Direction direction)
Definition Direction.hpp:14
Direction
方向
Definition Direction.hpp:9
@ Forward
Definition Direction.hpp:10
constexpr A Constrain(const A &amt, const B &low, const C &high)
値を指定された範囲内に収める (std::clamp)
Definition Math.hpp:69
CanBusTeensy< Bus > * CanBusTeensy< Bus >::self
Definition CanBusTeensy.hpp:275
CAN受信ノード
Definition ICanBus.hpp:28
CAN送信ノード
Definition ICanBus.hpp:17
範囲を表す型
Definition Range.hpp:8