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

Commit 5f41967

Browse files
authored
Merge pull request #279 from project-march/feature/PM-523-adding-DER2
Feature: add der2
2 parents 5c40399 + 5e19a7f commit 5f41967

File tree

10 files changed

+105
-35
lines changed

10 files changed

+105
-35
lines changed

march_hardware/include/march_hardware/error/motion_error.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,23 @@ namespace march
99
{
1010
namespace error
1111
{
12+
enum class ErrorRegisters
13+
{
14+
MOTION_ERROR,
15+
DETAILED_ERROR,
16+
SECOND_DETAILED_ERROR
17+
};
18+
1219
const size_t MOTION_ERRORS_SIZE = 16;
1320
extern const char* MOTION_ERRORS[MOTION_ERRORS_SIZE];
1421

1522
const size_t DETAILED_MOTION_ERRORS_SIZE = 9;
1623
extern const char* DETAILED_MOTION_ERRORS[DETAILED_MOTION_ERRORS_SIZE];
1724

18-
std::string parseMotionError(uint16_t motion_error);
25+
const size_t SECOND_DETAILED_MOTION_ERROR_SIZE = 7;
26+
extern const char* SECOND_DETAILED_MOTION_ERRORS[SECOND_DETAILED_MOTION_ERROR_SIZE];
1927

20-
std::string parseDetailedError(uint16_t detailed_error);
28+
std::string parseError(uint16_t error, ErrorRegisters);
2129

2230
} // namespace error
2331
} // namespace march

march_hardware/include/march_hardware/ethercat/pdo_map.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ enum class IMCObjectName
4747
ActualVelocity,
4848
MotionErrorRegister,
4949
DetailedErrorRegister,
50+
SecondDetailedErrorRegister,
5051
DCLinkVoltage,
5152
DriveTemperature,
5253
ActualTorque,

march_hardware/include/march_hardware/imotioncube/imotioncube.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class IMotionCube : public Slave
5757
uint16_t getStatusWord();
5858
uint16_t getMotionError();
5959
uint16_t getDetailedError();
60+
uint16_t getSecondDetailedError();
6061

6162
ActuationMode getActuationMode() const;
6263

march_hardware/include/march_hardware/imotioncube/imotioncube_state.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,14 @@ struct IMotionCubeState
125125
IMotionCubeState() = default;
126126

127127
std::string statusWord;
128-
std::string detailedError;
129128
std::string motionError;
129+
std::string detailedError;
130+
std::string secondDetailedError;
130131
IMCState state;
131132
std::string detailedErrorDescription;
132133
std::string motionErrorDescription;
134+
std::string secondDetailedErrorDescription;
135+
133136
float motorCurrent;
134137
float IMCVoltage;
135138
float motorVoltage;

march_hardware/src/error/motion_error.cpp

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,29 +36,39 @@ const char* DETAILED_MOTION_ERRORS[DETAILED_MOTION_ERRORS_SIZE] = {
3636
"Invalid S-curve profile. ",
3737
};
3838

39-
std::string parseMotionError(uint16_t motion_error)
40-
{
41-
std::string description;
42-
const std::bitset<16> bitset(motion_error);
43-
for (size_t i = 0; i < MOTION_ERRORS_SIZE; i++)
44-
{
45-
if (bitset.test(i))
46-
{
47-
description += MOTION_ERRORS[i];
48-
}
49-
}
50-
return description;
51-
}
39+
const char* SECOND_DETAILED_MOTION_ERRORS[SECOND_DETAILED_MOTION_ERROR_SIZE] = {
40+
"BiSS data CRC error. ",
41+
"BiSS data warning bit is set. ",
42+
"BiSS data error bit is set. ",
43+
"BiSS sensor missing. ",
44+
"Absolute Encoder Interface (AEI) interface error. ",
45+
"Hall sensor missing. ",
46+
"Position wraparound. The position 2^31 was exceeded. ",
47+
};
5248

53-
std::string parseDetailedError(uint16_t detailed_error)
49+
std::string parseError(uint16_t error, ErrorRegisters error_register)
5450
{
5551
std::string description;
56-
const std::bitset<16> bitset(detailed_error);
57-
for (size_t i = 0; i < DETAILED_MOTION_ERRORS_SIZE; i++)
52+
const std::bitset<16> bitset(error);
53+
54+
for (size_t i = 0; i < 16; i++)
5855
{
5956
if (bitset.test(i))
6057
{
61-
description += DETAILED_MOTION_ERRORS[i];
58+
switch (error_register)
59+
{
60+
case ErrorRegisters::MOTION_ERROR:
61+
description += MOTION_ERRORS[i];
62+
break;
63+
case ErrorRegisters::DETAILED_ERROR:
64+
description += DETAILED_MOTION_ERRORS[i];
65+
break;
66+
case ErrorRegisters::SECOND_DETAILED_ERROR:
67+
description += SECOND_DETAILED_MOTION_ERRORS[i];
68+
break;
69+
default:
70+
break;
71+
}
6272
}
6373
}
6474
return description;

march_hardware/src/ethercat/pdo_map.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ std::unordered_map<IMCObjectName, IMCObject> PDOmap::all_objects = {
1515
{ IMCObjectName::ActualVelocity, IMCObject(0x6069, 0, 32) },
1616
{ IMCObjectName::MotionErrorRegister, IMCObject(0x2000, 0, 16) },
1717
{ IMCObjectName::DetailedErrorRegister, IMCObject(0x2002, 0, 16) },
18+
{ IMCObjectName::SecondDetailedErrorRegister, IMCObject(0x2009, 0, 16) },
1819
{ IMCObjectName::DCLinkVoltage, IMCObject(0x2055, 0, 16) },
1920
{ IMCObjectName::DriveTemperature, IMCObject(0x2058, 0, 16) },
2021
{ IMCObjectName::ActualTorque, IMCObject(0x6077, 0, 16) },

march_hardware/src/imotioncube/imotioncube.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ void IMotionCube::mapMisoPDOs(SdoSlaveInterface& sdo)
6161
map_miso.addObject(IMCObjectName::ActualTorque); // Compulsory!
6262
map_miso.addObject(IMCObjectName::MotionErrorRegister);
6363
map_miso.addObject(IMCObjectName::DetailedErrorRegister);
64+
map_miso.addObject(IMCObjectName::SecondDetailedErrorRegister);
6465
map_miso.addObject(IMCObjectName::DCLinkVoltage);
6566
map_miso.addObject(IMCObjectName::MotorVoltage);
6667
map_miso.addObject(IMCObjectName::MotorPosition);
@@ -280,6 +281,11 @@ uint16_t IMotionCube::getDetailedError()
280281
return this->read16(this->miso_byte_offsets_.at(IMCObjectName::DetailedErrorRegister)).ui;
281282
}
282283

284+
uint16_t IMotionCube::getSecondDetailedError()
285+
{
286+
return this->read16(this->miso_byte_offsets_.at(IMCObjectName::SecondDetailedErrorRegister)).ui;
287+
}
288+
283289
float IMotionCube::getMotorCurrent()
284290
{
285291
const float PEAK_CURRENT = 40.0; // Peak current of iMC drive
@@ -326,8 +332,14 @@ void IMotionCube::goToTargetState(IMotionCubeTargetState target_state)
326332
{
327333
ROS_FATAL("IMotionCube went to fault state while attempting to go to '%s'. Shutting down.",
328334
target_state.getDescription().c_str());
329-
ROS_FATAL("Detailed Error: %s", error::parseDetailedError(this->getDetailedError()).c_str());
330-
ROS_FATAL("Motion Error: %s", error::parseMotionError(this->getMotionError()).c_str());
335+
ROS_FATAL("Motion Error (MER): %s",
336+
error::parseError(this->getMotionError(), error::ErrorRegisters::MOTION_ERROR).c_str());
337+
ROS_FATAL("Detailed Error (DER): %s",
338+
error::parseError(this->getDetailedError(), error::ErrorRegisters::DETAILED_ERROR).c_str());
339+
ROS_FATAL(
340+
"Detailed Error 2 (DER2): %s",
341+
error::parseError(this->getSecondDetailedError(), error::ErrorRegisters::SECOND_DETAILED_ERROR).c_str());
342+
331343
throw std::domain_error("IMC to fault state");
332344
}
333345
}

march_hardware/src/joint.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,20 @@ IMotionCubeState Joint::getIMotionCubeState()
229229

230230
std::bitset<16> statusWordBits = this->imc_->getStatusWord();
231231
states.statusWord = statusWordBits.to_string();
232-
std::bitset<16> detailedErrorBits = this->imc_->getDetailedError();
233-
states.detailedError = detailedErrorBits.to_string();
234232
std::bitset<16> motionErrorBits = this->imc_->getMotionError();
235233
states.motionError = motionErrorBits.to_string();
234+
std::bitset<16> detailedErrorBits = this->imc_->getDetailedError();
235+
states.detailedError = detailedErrorBits.to_string();
236+
std::bitset<16> secondDetailedErrorBits = this->imc_->getSecondDetailedError();
237+
states.secondDetailedError = secondDetailedErrorBits.to_string();
236238

237239
states.state = IMCState(this->imc_->getStatusWord());
238-
states.detailedErrorDescription = error::parseDetailedError(this->imc_->getDetailedError());
239-
states.motionErrorDescription = error::parseMotionError(this->imc_->getMotionError());
240+
241+
states.motionErrorDescription = error::parseError(this->imc_->getMotionError(), error::ErrorRegisters::MOTION_ERROR);
242+
states.detailedErrorDescription =
243+
error::parseError(this->imc_->getDetailedError(), error::ErrorRegisters::DETAILED_ERROR);
244+
states.secondDetailedErrorDescription =
245+
error::parseError(this->imc_->getSecondDetailedError(), error::ErrorRegisters::SECOND_DETAILED_ERROR);
240246

241247
states.motorCurrent = this->imc_->getMotorCurrent();
242248
states.IMCVoltage = this->imc_->getIMCVoltage();

march_hardware/test/error/motion_error_test.cpp

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55

66
TEST(MotionErrorTest, ParseNoMotionError)
77
{
8-
ASSERT_EQ(march::error::parseMotionError(0), "");
8+
ASSERT_EQ(march::error::parseError(0, march::error::ErrorRegisters::MOTION_ERROR), "");
99
}
1010

1111
TEST(MotionErrorTest, ParseCorrectMotionError)
1212
{
1313
const uint16_t error = 1;
14-
ASSERT_EQ(march::error::parseMotionError(error), march::error::MOTION_ERRORS[0]);
14+
ASSERT_EQ(march::error::parseError(error, march::error::ErrorRegisters::MOTION_ERROR),
15+
march::error::MOTION_ERRORS[0]);
1516
}
1617

1718
TEST(MotionErrorTest, ParseMultipleErrors)
@@ -21,18 +22,19 @@ TEST(MotionErrorTest, ParseMultipleErrors)
2122
expected += march::error::MOTION_ERRORS[2];
2223
expected += march::error::MOTION_ERRORS[3];
2324
expected += march::error::MOTION_ERRORS[15];
24-
ASSERT_EQ(march::error::parseMotionError(error), expected);
25+
ASSERT_EQ(march::error::parseError(error, march::error::ErrorRegisters::MOTION_ERROR), expected);
2526
}
2627

2728
TEST(TestDetailedMotionError, ParseNoDetailedMotionError)
2829
{
29-
ASSERT_EQ(march::error::parseDetailedError(0), "");
30+
ASSERT_EQ(march::error::parseError(0, march::error::ErrorRegisters::DETAILED_ERROR), "");
3031
}
3132

3233
TEST(TestDetailedMotionError, ParseCorrectDetailedMotionError)
3334
{
3435
const uint16_t error = 1;
35-
ASSERT_EQ(march::error::parseDetailedError(error), march::error::DETAILED_MOTION_ERRORS[0]);
36+
ASSERT_EQ(march::error::parseError(error, march::error::ErrorRegisters::DETAILED_ERROR),
37+
march::error::DETAILED_MOTION_ERRORS[0]);
3638
}
3739

3840
TEST(TestDetailedMotionError, ParseMultipleDetailedErrors)
@@ -42,5 +44,26 @@ TEST(TestDetailedMotionError, ParseMultipleDetailedErrors)
4244
expected += march::error::DETAILED_MOTION_ERRORS[2];
4345
expected += march::error::DETAILED_MOTION_ERRORS[3];
4446
expected += march::error::DETAILED_MOTION_ERRORS[8];
45-
ASSERT_EQ(march::error::parseDetailedError(error), expected);
47+
ASSERT_EQ(march::error::parseError(error, march::error::ErrorRegisters::DETAILED_ERROR), expected);
4648
}
49+
50+
TEST(TestSecondDetailedMotionError, ParseNoSecondDetailedMotionError)
51+
{
52+
ASSERT_EQ(march::error::parseError(0, march::error::ErrorRegisters::SECOND_DETAILED_ERROR), "");
53+
}
54+
55+
TEST(TestSecondDetailedMotionError, ParseCorrectSecondDetailedMotionError)
56+
{
57+
const uint16_t error = 1;
58+
ASSERT_EQ(march::error::parseError(error, march::error::ErrorRegisters::SECOND_DETAILED_ERROR),
59+
march::error::SECOND_DETAILED_MOTION_ERRORS[0]);
60+
}
61+
62+
TEST(TestSecondDetailedMotionError, ParseMultipleSecondDetailedErrors)
63+
{
64+
const uint16_t error = 0b0001100;
65+
std::string expected;
66+
expected += march::error::SECOND_DETAILED_MOTION_ERRORS[2];
67+
expected += march::error::SECOND_DETAILED_MOTION_ERRORS[3];
68+
ASSERT_EQ(march::error::parseError(error, march::error::ErrorRegisters::SECOND_DETAILED_ERROR), expected);
69+
}

march_hardware_interface/src/march_hardware_interface.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,9 +459,14 @@ bool MarchHardwareInterface::iMotionCubeStateCheck(size_t joint_index)
459459
march::IMotionCubeState imc_state = joint.getIMotionCubeState();
460460
if (imc_state.state == march::IMCState::FAULT)
461461
{
462-
ROS_ERROR("IMotionCube of joint %s is in fault state %s\nDetailed Error: %s (%s)\nMotion Error: %s (%s)",
463-
joint.getName().c_str(), imc_state.state.getString().c_str(), imc_state.detailedErrorDescription.c_str(),
464-
imc_state.detailedError.c_str(), imc_state.motionErrorDescription.c_str(), imc_state.motionError.c_str());
462+
ROS_ERROR("IMotionCube of joint %s is in fault state %s"
463+
"\nMotion Error: %s (%s)"
464+
"\nDetailed Error: %s (%s)"
465+
"\nSecond Detailed Error: %s (%s)",
466+
joint.getName().c_str(), imc_state.state.getString().c_str(), imc_state.motionErrorDescription.c_str(),
467+
imc_state.motionError.c_str(), imc_state.detailedErrorDescription.c_str(),
468+
imc_state.detailedError.c_str(), imc_state.secondDetailedErrorDescription.c_str(),
469+
imc_state.secondDetailedError.c_str());
465470
return false;
466471
}
467472
return true;

0 commit comments

Comments
 (0)