30 , direction{ direction }
31 , nodeRx{ bus.createRx(static_cast<uint32_t>(0x200 +
Constrain((int)motorId, 1, 8)), 8) }
34 nodeTx = bus.
createTx(
static_cast<uint32_t
>(0x1FF), 8);
36 nodeTx = bus.
createTx(
static_cast<uint32_t
>(0x200), 8);
51 , motorId{ other.motorId }
52 , direction{ other.direction }
53 , nodeTx{ other.nodeTx }
54 , nodeRx{ other.nodeRx }
65 return (angle + offsetAngle) * 2 *
Udon::Pi / ppr * directionSign();
74 return angle * 2 *
Udon::Pi / ppr * directionSign();
82 const auto velocity = (nodeRx->
data[2] << 8 | nodeRx->
data[3]) * directionSign();
83 return static_cast<int16_t
>(velocity);
91 const int current = (nodeRx->
data[4] << 8 | nodeRx->
data[5]) * directionSign();
92 return static_cast<int16_t
>(current);
100 return nodeRx->
data[6];
108 current = current * directionSign();
110 const auto transmitCurrent =
static_cast<int16_t
>(current * 16384 / 20000);
114 const auto motorIndex = (motorId - 4 - 1) * 2;
115 nodeTx->
data[motorIndex + 0] = transmitCurrent >> 8 & 0xff;
116 nodeTx->
data[motorIndex + 1] = transmitCurrent >> 0 & 0xff;
120 const auto motorIndex = (motorId - 1) * 2;
121 nodeTx->
data[motorIndex + 0] = transmitCurrent >> 8 & 0xff;
122 nodeTx->
data[motorIndex + 1] = transmitCurrent >> 0 & 0xff;
145 int64_t offsetAngle = 0;
150 static constexpr int32_t ppr = 8192;
152 int16_t directionSign()
const
154 return direction ? 1 : -1;
157 static void onReceive(
void* p)
162 const auto currentAngle = self->nodeRx->
data[0] << 8 | self->nodeRx->data[1];
163 const auto dTheta = self->angle - currentAngle;
164 self->angle = currentAngle;
167 if (dTheta > ppr / 2)
169 self->offsetAngle += ppr;
171 else if (dTheta < -ppr / 2)
173 self->offsetAngle -= ppr;
191 using RoboMasterBase::RoboMasterBase;
218 using RoboMasterBase::RoboMasterBase;
CANバス管理クラス インターフェース
Definition ICanBus.hpp:49
virtual CanTxNode * createTx(uint32_t id, size_t length)=0
送信ノードを作成
RoboMaster 基底クラス
Definition RoboMasterMotor.hpp:21
int16_t getTorqueCurrent() const
モーターのトルク電流を取得
Definition RoboMasterMotor.hpp:89
int16_t getVelocity() const
モーターの速度を取得
Definition RoboMasterMotor.hpp:80
double getAngle() const
モーターの角度を取得
Definition RoboMasterMotor.hpp:63
RoboMasterBase(const RoboMasterBase &)=delete
コピーコンストラクタ
RoboMasterBase(RoboMasterBase &&other)
ムーブコンストラクタ
Definition RoboMasterMotor.hpp:49
double getRawAngle() const
モーターの角度を取得
Definition RoboMasterMotor.hpp:72
RoboMasterBase(Udon::ICanBus &bus, uint8_t motorId, bool direction=true)
コンストラクタ
Definition RoboMasterMotor.hpp:27
void setCurrent(int16_t current)
モーターの電流を設定
Definition RoboMasterMotor.hpp:106
uint8_t getTemperature() const
モーターの温度を取得
Definition RoboMasterMotor.hpp:98
RoboMasterC610クラス
Definition RoboMasterMotor.hpp:185
void setCurrent(int16_t current)
モーターの電流を設定
Definition RoboMasterMotor.hpp:201
static constexpr int16_t CurrentMin
指定可能電流最小値
Definition RoboMasterMotor.hpp:194
static constexpr int16_t CurrentMax
指定可能電流最大値
Definition RoboMasterMotor.hpp:197
RoboMasterC620クラス
Definition RoboMasterMotor.hpp:212
void setCurrent(int16_t current)
モーターの電流を設定
Definition RoboMasterMotor.hpp:228
static constexpr int16_t CurrentMin
指定可能電流最小値
Definition RoboMasterMotor.hpp:221
static constexpr int16_t CurrentMax
指定可能電流最大値
Definition RoboMasterMotor.hpp:224
constexpr double Pi
π
Definition Math.hpp:26
constexpr A Constrain(const A &amt, const B &low, const C &high)
値を指定された範囲内に収める (std::clamp)
Definition Math.hpp:68
CAN受信ノード
Definition ICanBus.hpp:28
std::vector< uint8_t > data
Definition ICanBus.hpp:31
void * param
Definition ICanBus.hpp:34
void(* onReceive)(void *)
Definition ICanBus.hpp:33
CAN送信ノード
Definition ICanBus.hpp:17
std::vector< uint8_t > data
Definition ICanBus.hpp:20