mirror of
https://github.com/westonrobot/ugv_sdk
synced 2023-04-08 06:32:14 +08:00
used const var to represent motor number
This commit is contained in:
@@ -33,7 +33,8 @@ struct HunterState
|
||||
uint8_t set_zero_steering = 0;
|
||||
|
||||
// motor state
|
||||
MotorState motor_states[3];
|
||||
static constexpr uint8_t motor_num = 3;
|
||||
MotorState motor_states[motor_num];
|
||||
|
||||
// motion state
|
||||
double linear_velocity = 0;
|
||||
|
||||
@@ -229,7 +229,7 @@ void HunterBase::UpdateHunterState(const HunterMessage &status_msg,
|
||||
// std::cout << "motor 1 driver feedback received" << std::endl;
|
||||
const MotorDriverStatusMessage &msg =
|
||||
status_msg.body.motor_driver_status_msg;
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
for (int i = 0; i < HunterState::motor_num; ++i) {
|
||||
state.motor_states[status_msg.body.motor_driver_status_msg.motor_id]
|
||||
.current =
|
||||
(static_cast<uint16_t>(msg.data.status.current.low_byte) |
|
||||
|
||||
@@ -45,7 +45,8 @@ struct ScoutState
|
||||
double battery_voltage = 0.0;
|
||||
|
||||
// motor state
|
||||
MotorState motor_states[4];
|
||||
static constexpr uint8_t motor_num = 4;
|
||||
MotorState motor_states[motor_num];
|
||||
|
||||
// light state
|
||||
bool light_control_enabled = false;
|
||||
|
||||
@@ -325,7 +325,7 @@ void ScoutBase::UpdateScoutState(const ScoutMessage &status_msg, ScoutState &sta
|
||||
{
|
||||
// std::cout << "motor 1 driver feedback received" << std::endl;
|
||||
const MotorDriverStatusMessage &msg = status_msg.body.motor_driver_status_msg;
|
||||
for (int i = 0; i < 4; ++i)
|
||||
for (int i = 0; i < ScoutState::motor_num; ++i)
|
||||
{
|
||||
state.motor_states[status_msg.body.motor_driver_status_msg.motor_id].current = (static_cast<uint16_t>(msg.data.status.current.low_byte) | static_cast<uint16_t>(msg.data.status.current.high_byte) << 8) / 10.0;
|
||||
state.motor_states[status_msg.body.motor_driver_status_msg.motor_id].rpm = static_cast<int16_t>(static_cast<uint16_t>(msg.data.status.rpm.low_byte) | static_cast<uint16_t>(msg.data.status.rpm.high_byte) << 8);
|
||||
|
||||
Reference in New Issue
Block a user