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

Feature: add incremental encoder #225

Merged
merged 21 commits into from
Mar 5, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion march_hardware/include/march_hardware/Joint.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ class Joint

void setName(const std::string& name);
void setAllowActuation(bool allowActuation);
void setIMotionCube(const IMotionCube& iMotionCube);
void setTemperatureGes(const TemperatureGES& temperatureGes);
void setNetNumber(int netNumber);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace march
class IncrementalEncoder : public Encoder
{
public:
explicit IncrementalEncoder(size_t number_of_bits);
IncrementalEncoder(size_t number_of_bits, double transmission);

double getAngleRad(uint8_t byte_offset);

Expand All @@ -28,6 +28,9 @@ class IncrementalEncoder : public Encoder
return os << "slaveIndex: " << encoder.getSlaveIndex() << ", "
<< "totalPositions: " << encoder.getTotalPositions();
}

private:
const double transmission_;
};
} // namespace march

Expand Down
5 changes: 1 addition & 4 deletions march_hardware/src/Joint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,7 @@ void Joint::setAllowActuation(bool allowActuation)
{
Joint::allowActuation = allowActuation;
}
void Joint::setIMotionCube(const IMotionCube& iMotionCube)
{
Joint::iMotionCube = iMotionCube;
}

void Joint::setTemperatureGes(const TemperatureGES& temperatureGes)
{
temperatureGES = temperatureGes;
Expand Down
5 changes: 3 additions & 2 deletions march_hardware/src/encoder/IncrementalEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

namespace march
{
IncrementalEncoder::IncrementalEncoder(size_t number_of_bits) : Encoder(number_of_bits)
IncrementalEncoder::IncrementalEncoder(size_t number_of_bits, double transmission)
: Encoder(number_of_bits), transmission_(transmission)
{
}

Expand All @@ -16,6 +17,6 @@ double IncrementalEncoder::getAngleRad(uint8_t byte_offset)

double IncrementalEncoder::toRad(int32_t iu)
{
return iu * 2 * M_PI / Encoder::getTotalPositions();
return iu * this->transmission_ * 2 * M_PI / Encoder::getTotalPositions();
}
} // namespace march
5 changes: 3 additions & 2 deletions march_hardware/test/encoder/TestIncrementalEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class TestIncrementalEncoder : public testing::Test
{
protected:
const size_t resolution = 12;
march::IncrementalEncoder encoder = march::IncrementalEncoder(this->resolution);
const double transmission = 100;
march::IncrementalEncoder encoder = march::IncrementalEncoder(this->resolution, this->transmission);
};

TEST_F(TestIncrementalEncoder, ZeroIUToRad)
Expand All @@ -20,6 +21,6 @@ TEST_F(TestIncrementalEncoder, ZeroIUToRad)
TEST_F(TestIncrementalEncoder, CorrectToRad)
{
const int32_t iu = 1000;
const double expected = iu * 2.0 * M_PI / std::pow(2, this->resolution);
const double expected = iu * this->transmission * 2.0 * M_PI / std::pow(2, this->resolution);
ASSERT_EQ(expected, this->encoder.toRad(iu));
}
2 changes: 1 addition & 1 deletion march_hardware/test/mocks/MockIncrementalEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class MockIncrementalEncoder : public march::IncrementalEncoder
{
public:
MockIncrementalEncoder() : IncrementalEncoder(10)
MockIncrementalEncoder() : IncrementalEncoder(10, 100.0)
{
}

Expand Down
8 changes: 8 additions & 0 deletions march_hardware_builder/robots/march4.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ march4:
maxPositionIU: 4091
incrementalEncoder:
resolution: 13
transmission: 200

- left_hip_aa:
actuationMode: torque
Expand All @@ -29,6 +30,7 @@ march4:
maxPositionIU: 1426
incrementalEncoder:
resolution: 13
transmission: 200

- right_hip_fe:
actuationMode: torque
Expand All @@ -43,6 +45,7 @@ march4:
maxPositionIU: 45617
incrementalEncoder:
resolution: 12
transmission: 101

- left_hip_fe:
actuationMode: torque
Expand All @@ -57,6 +60,7 @@ march4:
maxPositionIU: 40270
incrementalEncoder:
resolution: 12
transmission: 101

- right_knee:
actuationMode: torque
Expand All @@ -71,6 +75,7 @@ march4:
maxPositionIU: 68874
incrementalEncoder:
resolution: 12
transmission: 101

- left_knee:
actuationMode: torque
Expand All @@ -85,6 +90,7 @@ march4:
maxPositionIU: 63543
incrementalEncoder:
resolution: 12
transmission: 101

- right_ankle:
actuationMode: torque
Expand All @@ -99,6 +105,7 @@ march4:
maxPositionIU: 1210
incrementalEncoder:
resolution: 13
transmission: 200

- left_ankle:
actuationMode: torque
Expand All @@ -113,3 +120,4 @@ march4:
maxPositionIU: 4082
incrementalEncoder:
resolution: 13
transmission: 200
1 change: 1 addition & 0 deletions march_hardware_builder/robots/test_joint_linear.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ testjoint_linear:
maxPositionIU: 445
incrementalEncoder:
resolution: 13
transmission: 200
1 change: 1 addition & 0 deletions march_hardware_builder/robots/test_joint_rotational.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ testsetup:
maxPositionIU: 102499
incrementalEncoder:
resolution: 12
transmission: 101
5 changes: 3 additions & 2 deletions march_hardware_builder/src/hardware_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const std::vector<std::string> HardwareBuilder::ABSOLUTE_ENCODER_REQUIRED_KEYS =
{
"resolution", "minPositionIU", "maxPositionIU"
};
const std::vector<std::string> HardwareBuilder::INCREMENTAL_ENCODER_REQUIRED_KEYS = { "resolution" };
const std::vector<std::string> HardwareBuilder::INCREMENTAL_ENCODER_REQUIRED_KEYS = { "resolution", "transmission" };
const std::vector<std::string> HardwareBuilder::IMOTIONCUBE_REQUIRED_KEYS =
{
"slaveIndex", "incrementalEncoder", "absoluteEncoder"
Expand Down Expand Up @@ -168,7 +168,8 @@ march::IncrementalEncoder HardwareBuilder::createIncrementalEncoder(const YAML::
HardwareBuilder::INCREMENTAL_ENCODER_REQUIRED_KEYS, "incrementalEncoder");

auto resolution = incremental_encoder_config["resolution"].as<size_t>();
return march::IncrementalEncoder(resolution);
auto transmission = incremental_encoder_config["transmission"].as<double>();
return { resolution, transmission };
}

march::TemperatureGES HardwareBuilder::createTemperatureGES(const YAML::Node& temperature_ges_config)
Expand Down
2 changes: 1 addition & 1 deletion march_hardware_builder/test/imc_builder_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ TEST_F(IMotionCubeTest, ValidIMotionCubeHip)
march::AbsoluteEncoder absolute_encoder =
march::AbsoluteEncoder(16, 22134, 43436, this->joint->limits->lower, this->joint->limits->upper,
this->joint->safety->soft_lower_limit, this->joint->safety->soft_upper_limit);
march::IncrementalEncoder incremental_encoder = march::IncrementalEncoder(12);
march::IncrementalEncoder incremental_encoder = march::IncrementalEncoder(12, 101.0);
march::IMotionCube expected =
march::IMotionCube(2, absolute_encoder, incremental_encoder, march::ActuationMode::unknown);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,21 @@ TEST_F(TestIncrementalEncoderBuilder, ValidIncrementalEncoder)
{
YAML::Node config = this->loadTestYaml("/incremental_encoder_correct.yaml");

march::IncrementalEncoder expected = march::IncrementalEncoder(12);
march::IncrementalEncoder expected = march::IncrementalEncoder(12, 45.5);
march::IncrementalEncoder created = HardwareBuilder::createIncrementalEncoder(config);
ASSERT_EQ(expected, created);
}

TEST_F(TestIncrementalEncoderBuilder, NoResolution)
{
YAML::Node config;
YAML::Node config = this->loadTestYaml("/incremental_encoder_no_resolution.yaml");

ASSERT_THROW(HardwareBuilder::createIncrementalEncoder(config), MissingKeyException);
}

TEST_F(TestIncrementalEncoderBuilder, NoTransmission)
{
YAML::Node config = this->loadTestYaml("/incremental_encoder_no_transmission.yaml");

ASSERT_THROW(HardwareBuilder::createIncrementalEncoder(config), MissingKeyException);
}
6 changes: 3 additions & 3 deletions march_hardware_builder/test/joint_builder_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ TEST_F(JointTest, ValidJointHip)
march::AbsoluteEncoder absolute_encoder =
march::AbsoluteEncoder(16, 22134, 43436, this->joint->limits->lower, this->joint->limits->upper,
this->joint->safety->soft_lower_limit, this->joint->safety->soft_upper_limit);
march::IncrementalEncoder incremental_encoder = march::IncrementalEncoder(12);
march::IncrementalEncoder incremental_encoder = march::IncrementalEncoder(12, 50.0);
march::IMotionCube imc = march::IMotionCube(2, absolute_encoder, incremental_encoder, march::ActuationMode::unknown);
march::TemperatureGES ges = march::TemperatureGES(1, 2);
march::Joint expected(imc);
Expand All @@ -70,7 +70,7 @@ TEST_F(JointTest, ValidNotActuated)
march::AbsoluteEncoder absolute_encoder =
march::AbsoluteEncoder(16, 22134, 43436, this->joint->limits->lower, this->joint->limits->upper,
this->joint->safety->soft_lower_limit, this->joint->safety->soft_upper_limit);
march::IncrementalEncoder incremental_encoder = march::IncrementalEncoder(12);
march::IncrementalEncoder incremental_encoder = march::IncrementalEncoder(12, 50.0);
march::IMotionCube imc = march::IMotionCube(2, absolute_encoder, incremental_encoder, march::ActuationMode::unknown);
march::TemperatureGES ges = march::TemperatureGES(1, 2);
march::Joint expected(imc);
Expand Down Expand Up @@ -122,7 +122,7 @@ TEST_F(JointTest, ValidActuationMode)
1,
march::AbsoluteEncoder(16, 22134, 43436, this->joint->limits->lower, this->joint->limits->upper,
this->joint->safety->soft_lower_limit, this->joint->safety->soft_upper_limit),
march::IncrementalEncoder(12), march::ActuationMode::position));
march::IncrementalEncoder(12, 50.0), march::ActuationMode::position));
expected.setName("test_joint_hip");

ASSERT_EQ("test_joint_hip", expected.getName());
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
resolution: 12
resolution: 12
transmission: 45.5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
transmission: 45.5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
resolution: 13
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ absoluteEncoder:
safetyMarginRad: 0.05
incrementalEncoder:
resolution: 12
transmission: 101
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
slaveIndex: 2
incrementalEncoder:
resolution: 12
transmission: 100
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ absoluteEncoder:
maxPositionIU: 43436
incrementalEncoder:
resolution: 12
transmission: 75.1
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ imotioncube:
maxPositionIU: 43436
incrementalEncoder:
resolution: 12
transmission: 50.0
temperatureges:
slaveIndex: 1
byteOffset: 2
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ imotioncube:
maxPositionIU: 43436
incrementalEncoder:
resolution: 12
transmission: 50.0
temperatureges:
slaveIndex: 1
byteOffset: 2
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ imotioncube:
maxPositionIU: 43436
incrementalEncoder:
resolution: 12
transmission: 50.0
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ imotioncube:
maxPositionIU: 43436
incrementalEncoder:
resolution: 12
transmission: 14.0
temperatureges:
slaveIndex: 1
byteOffset: 2
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ imotioncube:
maxPositionIU: 40000
incrementalEncoder:
resolution: 12
transmission: 45.0