-
Notifications
You must be signed in to change notification settings - Fork 87
IMU sensor API to get world ref frame and heading offset #186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 18 commits
17ca1ac
d4aa659
c479887
1fdc240
eaa94cd
59d0b08
d09f508
324ed90
7bdfb0b
e16ab67
2e5e910
df783de
3ead9f2
0f99a51
368a24f
00e9c7c
18b3645
33a79c6
8f03ce1
654ceb8
90f6917
3f42ba6
735a61f
744d0d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -436,6 +436,8 @@ TEST(ImuSensor_TEST, OrientationReference) | |
| // Create an ImuSensor | ||
| auto sensor = mgr.CreateSensor<ignition::sensors::ImuSensor>( | ||
| imuSDF); | ||
| sensor->SetWorldFrameOrientation(math::Quaterniond(0, 0, 0), | ||
| sensors::WorldFrameEnumType::ENU); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this necessary?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently, |
||
|
|
||
| // Make sure the above dynamic cast worked. | ||
| ASSERT_NE(nullptr, sensor); | ||
|
|
@@ -496,6 +498,9 @@ TEST(ImuSensor_TEST, CustomRpyParentFrame) | |
| auto sensor = mgr.CreateSensor<ignition::sensors::ImuSensor>( | ||
| imuSDF); | ||
|
|
||
| sensor->SetWorldFrameOrientation(math::Quaterniond(0, 0, 0), | ||
| sensors::WorldFrameEnumType::ENU); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this necessary?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same reason above. |
||
|
|
||
| // Make sure the above dynamic cast worked. | ||
| ASSERT_NE(nullptr, sensor); | ||
|
|
||
|
|
@@ -511,6 +516,174 @@ TEST(ImuSensor_TEST, CustomRpyParentFrame) | |
| EXPECT_EQ(defultOrientValue, sensor->Orientation()); | ||
| } | ||
|
|
||
| sdf::ElementPtr generateSensor(std::string namedFrame) | ||
adityapande-1995 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| std::ostringstream stream; | ||
| stream | ||
| << "<?xml version='1.0'?>" | ||
| << "<sdf version='1.6'>" | ||
| << " <model name='m1'>" | ||
| << " <link name='link1'>" | ||
| << " <sensor name='imu_sensor' type='imu'>" | ||
| << " <topic>imu_test</topic>" | ||
| << " <update_rate>1</update_rate>" | ||
| << " <imu>" | ||
| << " <orientation_reference_frame>" | ||
| << " <localization>"+namedFrame+"</localization>" | ||
| << " </orientation_reference_frame>" | ||
| << " </imu>" | ||
| << " <always_on>1</always_on>" | ||
| << " <visualize>true</visualize>" | ||
| << " </sensor>" | ||
| << " </link>" | ||
| << " </model>" | ||
| << "</sdf>"; | ||
|
|
||
| sdf::SDFPtr sdfParsed(new sdf::SDF()); | ||
| sdf::init(sdfParsed); | ||
| if (!sdf::readString(stream.str(), sdfParsed)) | ||
| { | ||
| return sdf::ElementPtr(); | ||
| } | ||
| else | ||
| { | ||
| return sdfParsed->Root()->GetElement("model")->GetElement("link") | ||
| ->GetElement("sensor"); | ||
| } | ||
| } | ||
|
|
||
| ////////////////////////////////////////////////// | ||
| TEST(ImuSensor_TEST, NamedFrameOrientationReference) | ||
| { | ||
| // Create a sensor manager | ||
| ignition::sensors::Manager mgr; | ||
|
|
||
| math::Quaterniond orientValue; | ||
|
|
||
| // A. Localization tag is set to ENU | ||
| // --------------------------------- | ||
| auto sensorENU = mgr.CreateSensor<ignition::sensors::ImuSensor>( | ||
| generateSensor("ENU")); | ||
| ASSERT_NE(nullptr, sensorENU); | ||
|
|
||
| // Case A.1 : Localization ref: ENU, World : ENU | ||
| // Sensor aligns with ENU, we're measuring wrt ENU | ||
| sensorENU->SetWorldFrameOrientation(math::Quaterniond(0, 0, 0), | ||
| sensors::WorldFrameEnumType::ENU); | ||
| sensorENU->Update(std::chrono::steady_clock::duration( | ||
| std::chrono::nanoseconds(10000000))); | ||
| orientValue = math::Quaterniond(math::Vector3d(0, 0, 0)); | ||
| EXPECT_EQ(orientValue, sensorENU->Orientation()); | ||
adityapande-1995 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // Case A.2 Localization ref: ENU, World : ENU + rotation offset | ||
| sensorENU->SetWorldFrameOrientation(math::Quaterniond(0, 0, IGN_PI/4), | ||
| sensors::WorldFrameEnumType::ENU); | ||
| sensorENU->Update(std::chrono::steady_clock::duration( | ||
| std::chrono::nanoseconds(10000000))); | ||
| orientValue = math::Quaterniond(math::Vector3d(0, 0, -IGN_PI/4)); | ||
| EXPECT_EQ(orientValue, sensorENU->Orientation()); | ||
|
|
||
| // Case A.3 Localization ref: ENU, World : NWU | ||
| // Sensor aligns with NWU, we're measuring wrt ENU | ||
| sensorENU->SetWorldFrameOrientation(math::Quaterniond(0, 0, 0), | ||
| sensors::WorldFrameEnumType::NWU); | ||
| sensorENU->Update(std::chrono::steady_clock::duration( | ||
| std::chrono::nanoseconds(10000000))); | ||
| orientValue = math::Quaterniond(math::Vector3d(0, 0, IGN_PI/2)); | ||
| EXPECT_EQ(orientValue, sensorENU->Orientation()); | ||
|
|
||
| // Case A.4 Localization ref: ENU, World : NED | ||
| // Sensor aligns with NED, we're measuring wrt ENU | ||
| sensorENU->SetWorldFrameOrientation(math::Quaterniond(0, 0, 0), | ||
| sensors::WorldFrameEnumType::NED); | ||
| sensorENU->Update(std::chrono::steady_clock::duration( | ||
| std::chrono::nanoseconds(10000000))); | ||
| orientValue = math::Quaterniond(math::Vector3d(IGN_PI, 0, IGN_PI/2)); | ||
| EXPECT_EQ(orientValue, sensorENU->Orientation()); | ||
|
|
||
| // B. Localization tag is set to NWU | ||
| // --------------------------------- | ||
| auto sensorNWU = mgr.CreateSensor<ignition::sensors::ImuSensor>( | ||
| generateSensor("NWU")); | ||
| ASSERT_NE(nullptr, sensorNWU); | ||
|
|
||
| // Case B.1 : Localization ref: NWU, World : NWU | ||
| // Sensor aligns with NWU, we're measuring wrt NWU | ||
| sensorNWU->SetWorldFrameOrientation(math::Quaterniond(0, 0, 0), | ||
| sensors::WorldFrameEnumType::NWU); | ||
| sensorNWU->Update(std::chrono::steady_clock::duration( | ||
| std::chrono::nanoseconds(10000000))); | ||
| orientValue = math::Quaterniond(math::Vector3d(0, 0, 0)); | ||
| EXPECT_EQ(orientValue, sensorNWU->Orientation()); | ||
|
|
||
| // Case B.2 : Localization ref: NWU, World : NWU + rotation offset | ||
| sensorNWU->SetWorldFrameOrientation(math::Quaterniond(0, 0, IGN_PI/4), | ||
| sensors::WorldFrameEnumType::NWU); | ||
| sensorNWU->Update(std::chrono::steady_clock::duration( | ||
| std::chrono::nanoseconds(10000000))); | ||
| orientValue = math::Quaterniond(math::Vector3d(0, 0, -IGN_PI/4)); | ||
| EXPECT_EQ(orientValue, sensorNWU->Orientation()); | ||
|
|
||
| // Case B.3 : Localization ref: NWU, World : ENU | ||
| // Sensor aligns with ENU, we're measuring wrt NWU | ||
| sensorNWU->SetWorldFrameOrientation(math::Quaterniond(0, 0, 0), | ||
| sensors::WorldFrameEnumType::ENU); | ||
| sensorNWU->Update(std::chrono::steady_clock::duration( | ||
| std::chrono::nanoseconds(10000000))); | ||
| orientValue = math::Quaterniond(math::Vector3d(0, 0, -IGN_PI/2)); | ||
| EXPECT_EQ(orientValue, sensorNWU->Orientation()); | ||
|
|
||
| // Case B.4 : Localization ref: NWU, World : NED | ||
| // Sensor aligns with NED, we're measuring wrt NWU | ||
| sensorNWU->SetWorldFrameOrientation(math::Quaterniond(0, 0, 0), | ||
| sensors::WorldFrameEnumType::NED); | ||
| sensorNWU->Update(std::chrono::steady_clock::duration( | ||
| std::chrono::nanoseconds(10000000))); | ||
| orientValue = math::Quaterniond(math::Vector3d(IGN_PI, 0, 0)); | ||
| EXPECT_EQ(orientValue, sensorNWU->Orientation()); | ||
|
|
||
| // C. Localization tag is set to NED | ||
| // --------------------------------- | ||
| auto sensorNED = mgr.CreateSensor<ignition::sensors::ImuSensor>( | ||
| generateSensor("NED")); | ||
| ASSERT_NE(nullptr, sensorNED); | ||
|
|
||
| // Case C.1 : Localization ref: NED, World : NED | ||
| // Sensor aligns with NED, we're measuring wrt NED | ||
| sensorNED->SetWorldFrameOrientation(math::Quaterniond(0, 0, 0), | ||
| sensors::WorldFrameEnumType::NED); | ||
| sensorNED->Update(std::chrono::steady_clock::duration( | ||
| std::chrono::nanoseconds(10000000))); | ||
| orientValue = math::Quaterniond(math::Vector3d(0, 0, 0)); | ||
| EXPECT_EQ(orientValue, sensorNED->Orientation()); | ||
|
|
||
| // Case C.2 : Localization ref: NED, World : NED + rotation offset | ||
| sensorNED->SetWorldFrameOrientation(math::Quaterniond(0, 0, IGN_PI/4), | ||
| sensors::WorldFrameEnumType::NED); | ||
| sensorNED->Update(std::chrono::steady_clock::duration( | ||
| std::chrono::nanoseconds(10000000))); | ||
| orientValue = math::Quaterniond(math::Vector3d(0, 0, -IGN_PI/4)); | ||
| EXPECT_EQ(orientValue, sensorNED->Orientation()); | ||
|
|
||
| // Case C.3 : Localization ref: NED, World : NWU | ||
| // Sensor aligns with NWU, we're measuring wrt NED | ||
| sensorNED->SetWorldFrameOrientation(math::Quaterniond(0, 0, 0), | ||
| sensors::WorldFrameEnumType::NWU); | ||
| sensorNED->Update(std::chrono::steady_clock::duration( | ||
| std::chrono::nanoseconds(10000000))); | ||
| orientValue = math::Quaterniond(math::Vector3d(-IGN_PI, 0, 0)); | ||
| EXPECT_EQ(orientValue, sensorNED->Orientation()); | ||
|
|
||
| // Case C.4 : Localization ref: NED, World : ENU | ||
| // Sensor aligns with ENU, we're measuring wrt NED | ||
| sensorNED->SetWorldFrameOrientation(math::Quaterniond(0, 0, 0), | ||
| sensors::WorldFrameEnumType::ENU); | ||
| sensorNED->Update(std::chrono::steady_clock::duration( | ||
| std::chrono::nanoseconds(10000000))); | ||
| orientValue = math::Quaterniond(math::Vector3d(-IGN_PI, 0, IGN_PI/2)); | ||
| EXPECT_EQ(orientValue, sensorNED->Orientation()); | ||
| } | ||
|
|
||
| ////////////////////////////////////////////////// | ||
| int main(int argc, char **argv) | ||
| { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.