Skip to content
This repository was archived by the owner on Dec 1, 2020. It is now read-only.

Commit 5d2918c

Browse files
Merge pull request #266 from project-march/feature/PM-422-add-motor-voltage
Feature: add motor voltage
2 parents c2e3e2e + 5f57dd7 commit 5d2918c

File tree

9 files changed

+27
-5
lines changed

9 files changed

+27
-5
lines changed

march_hardware/include/march_hardware/IMotionCube.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class IMotionCube : public Slave
6262

6363
virtual float getMotorCurrent();
6464
virtual float getIMCVoltage();
65+
virtual float getMotorVoltage();
6566

6667
void setControlWord(uint16_t control_word);
6768

march_hardware/include/march_hardware/IMotionCubeState.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ struct IMotionCubeState
132132
std::string motionErrorDescription;
133133
float motorCurrent;
134134
float IMCVoltage;
135+
float motorVoltage;
135136
int absoluteEncoderValue;
136137
int incrementalEncoderValue;
137138
double absoluteVelocity;

march_hardware/include/march_hardware/Joint.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ class Joint
127127
bool allow_actuation_ = false;
128128
float previous_imc_volt_ = 0.0;
129129
float previous_motor_current_ = 0.0;
130+
float previous_motor_volt_ = 0.0;
130131
double previous_absolute_position_ = 0.0;
131132
double previous_incremental_position_ = 0.0;
132133
double previous_absolute_velocity_ = 0.0;

march_hardware/include/march_hardware/PDOmap.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ enum class IMCObjectName
5757
TargetPosition,
5858
TargetTorque,
5959
QuickStopDeceleration,
60-
QuickStopOption
60+
QuickStopOption,
61+
MotorVoltage
6162
};
6263

6364
class PDOmap

march_hardware/src/IMotionCube.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ void IMotionCube::mapMisoPDOs(SdoSlaveInterface& sdo)
6262
map_miso.addObject(IMCObjectName::MotionErrorRegister);
6363
map_miso.addObject(IMCObjectName::DetailedErrorRegister);
6464
map_miso.addObject(IMCObjectName::DCLinkVoltage);
65+
map_miso.addObject(IMCObjectName::MotorVoltage);
6566
map_miso.addObject(IMCObjectName::MotorPosition);
6667
map_miso.addObject(IMCObjectName::MotorVelocity);
6768
map_miso.addObject(IMCObjectName::ActualVelocity);
@@ -128,7 +129,12 @@ bool IMotionCube::writeInitialSettings(SdoSlaveInterface& sdo, int cycle_time)
128129
int rate_ec_x = sdo.write<uint8_t>(0x60C2, 1, cycle_time);
129130
int rate_ec_y = sdo.write<int8_t>(0x60C2, 2, -3);
130131

131-
if (!(mode_of_op && max_pos_lim && min_pos_lim && stop_opt && stop_decl && abort_con && rate_ec_x && rate_ec_y))
132+
// use filter object to read motor voltage
133+
int volt_address = sdo.write<int16_t>(0x2108, 1, 0x0232);
134+
int volt_filter = sdo.write<int16_t>(0x2108, 2, 32767);
135+
136+
if (!(mode_of_op && max_pos_lim && min_pos_lim && stop_opt && stop_decl && abort_con && rate_ec_x && rate_ec_y &&
137+
volt_address && volt_filter))
132138
{
133139
throw error::HardwareException(error::ErrorType::WRITING_INITIAL_SETTINGS_FAILED,
134140
"Failed writing initial settings to IMC of slave %d", this->getSlaveIndex());
@@ -296,6 +302,11 @@ float IMotionCube::getIMCVoltage()
296302
static_cast<float>(imc_voltage_iu); // Conversion to Volt, see Technosoft CoE programming manual
297303
}
298304

305+
float IMotionCube::getMotorVoltage()
306+
{
307+
return this->read16(this->miso_byte_offsets_.at(IMCObjectName::MotorVoltage)).ui;
308+
}
309+
299310
void IMotionCube::setControlWord(uint16_t control_word)
300311
{
301312
bit16 control_word_ui = { .ui = control_word };

march_hardware/src/Joint.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ IMotionCubeState Joint::getIMotionCubeState()
228228

229229
states.motorCurrent = this->imc_->getMotorCurrent();
230230
states.IMCVoltage = this->imc_->getIMCVoltage();
231+
states.motorVoltage = this->imc_->getMotorVoltage();
231232

232233
states.absoluteEncoderValue = this->imc_->getAngleIUAbsolute();
233234
states.incrementalEncoderValue = this->imc_->getAngleIUIncremental();
@@ -294,19 +295,21 @@ bool Joint::receivedDataUpdate()
294295
// If imc voltage, motor current, and both encoders positions and velocities did not change,
295296
// we probably did not receive an update for this joint.
296297
float new_imc_volt = this->imc_->getIMCVoltage();
298+
float new_motor_volt = this->imc_->getMotorVoltage();
297299
float new_motor_current = this->imc_->getMotorCurrent();
298300
double new_absolute_position = this->imc_->getAngleRadAbsolute();
299301
double new_incremental_position = this->imc_->getAngleRadIncremental();
300302
double new_absolute_velocity = this->imc_->getVelocityRadAbsolute();
301303
double new_incremental_velocity = this->imc_->getVelocityRadIncremental();
302-
303-
bool data_updated = (new_imc_volt != this->previous_imc_volt_ || new_motor_current != this->previous_motor_current_ ||
304+
bool data_updated = (new_imc_volt != this->previous_imc_volt_ || new_motor_volt != this->previous_motor_volt_ ||
305+
new_motor_current != this->previous_motor_current_ ||
304306
new_absolute_position != this->previous_absolute_position_ ||
305307
new_incremental_position != this->previous_incremental_position_ ||
306308
new_absolute_velocity != this->previous_absolute_velocity_ ||
307309
new_incremental_velocity != this->previous_incremental_velocity_);
308310

309311
this->previous_imc_volt_ = new_imc_volt;
312+
this->previous_motor_volt_ = new_motor_volt;
310313
this->previous_motor_current_ = new_motor_current;
311314
this->previous_absolute_position_ = new_absolute_position;
312315
this->previous_incremental_position_ = new_incremental_position;

march_hardware/src/PDOmap.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ std::unordered_map<IMCObjectName, IMCObject> PDOmap::all_objects = {
2525
{ IMCObjectName::TargetPosition, IMCObject(0x607A, 0, 32) },
2626
{ IMCObjectName::TargetTorque, IMCObject(0x6071, 0, 16) },
2727
{ IMCObjectName::QuickStopDeceleration, IMCObject(0x6085, 0, 32) },
28-
{ IMCObjectName::QuickStopOption, IMCObject(0x605A, 0, 16) }
28+
{ IMCObjectName::QuickStopOption, IMCObject(0x605A, 0, 16) },
29+
{ IMCObjectName::MotorVoltage, IMCObject(0x2108, 3, 16) }
2930
};
3031

3132
void PDOmap::addObject(IMCObjectName object_name)

march_hardware/test/mocks/MockIMotionCube.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class MockIMotionCube : public march::IMotionCube
2828
MOCK_METHOD0(getVelocityRadAbsolute, double());
2929

3030
MOCK_METHOD0(getIMCVoltage, float());
31+
MOCK_METHOD0(getMotorVoltage, float());
3132
MOCK_METHOD0(getMotorCurrent, float());
3233

3334
MOCK_METHOD1(actuateRad, void(double));

march_hardware_interface/src/march_hardware_interface.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ void MarchHardwareInterface::reserveMemory()
312312
imc_state_pub_->msg_.motion_error_description.resize(num_joints_);
313313
imc_state_pub_->msg_.motor_current.resize(num_joints_);
314314
imc_state_pub_->msg_.imc_voltage.resize(num_joints_);
315+
imc_state_pub_->msg_.motor_voltage.resize(num_joints_);
315316
imc_state_pub_->msg_.absolute_encoder_value.resize(num_joints_);
316317
imc_state_pub_->msg_.incremental_encoder_value.resize(num_joints_);
317318
imc_state_pub_->msg_.absolute_velocity.resize(num_joints_);
@@ -432,6 +433,7 @@ void MarchHardwareInterface::updateIMotionCubeState()
432433
imc_state_pub_->msg_.motion_error_description[i] = imc_state.motionErrorDescription;
433434
imc_state_pub_->msg_.motor_current[i] = imc_state.motorCurrent;
434435
imc_state_pub_->msg_.imc_voltage[i] = imc_state.IMCVoltage;
436+
imc_state_pub_->msg_.motor_voltage[i] = imc_state.motorVoltage;
435437
imc_state_pub_->msg_.absolute_encoder_value[i] = imc_state.absoluteEncoderValue;
436438
imc_state_pub_->msg_.incremental_encoder_value[i] = imc_state.incrementalEncoderValue;
437439
imc_state_pub_->msg_.absolute_velocity[i] = imc_state.absoluteVelocity;

0 commit comments

Comments
 (0)