Skip to content
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

Manif refactor #648

Merged
merged 69 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from 65 commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
bf56489
read messages from base station
rbridges12 Jul 12, 2023
1a68846
sending RTCMs over ros
rbridges12 Jul 13, 2023
8da0845
launch file with both GPSs, RTCMs successfully transmitted
rbridges12 Jul 13, 2023
a251f1c
port change
rbridges12 Jul 14, 2023
deb3724
output screen
rbridges12 Jul 30, 2023
315c03c
Merge branch 'master' into rtk
nehakankanala Oct 22, 2023
68f9730
added gps driver for rover gps and merged master into rtk
nehakankanala Oct 22, 2023
de9c114
edited rtk launch and esw.yaml
nehakankanala Oct 26, 2023
21f27c9
used pyubx reader instead of serial getline()
nehakankanala Oct 26, 2023
118ada5
added preliminary dual gnss file
pearlastrid Oct 27, 2023
e7be851
add notes
dllliu Oct 27, 2023
6087729
graph vectors for heading calculations
dllliu Oct 29, 2023
9602c61
calc heading and bearing
dllliu Oct 31, 2023
9ca084b
driver testing; not fully working :alien:
rahdal Oct 31, 2023
285d1b6
plots for heading calculations
dllliu Oct 31, 2023
4b84aed
added get_heading_vector function
pearlastrid Nov 2, 2023
325792d
add tests for vector heading method
dllliu Nov 3, 2023
42533ba
working as intended furing testing
rahdal Nov 9, 2023
280ef72
add tests to determine optimal amt of sig figs for gps coordinates
dllliu Nov 10, 2023
0803e8b
added more message parsing
rahdal Nov 12, 2023
ec73cc1
started adding gps to gazebo
pearlastrid Nov 14, 2023
89b8f75
finished adding new gps and links
pearlastrid Nov 14, 2023
b927d78
edited links
pearlastrid Nov 14, 2023
a271f7f
added links
pearlastrid Nov 15, 2023
a2b3a7b
try to debug plugins and make test subscriber file
dllliu Nov 17, 2023
9965be8
added left and right gps using groups
rahdal Nov 26, 2023
77c8f2b
gps creation and subscribers
dllliu Nov 28, 2023
1348cd6
add tests for moving gps and subscribed
dllliu Nov 29, 2023
1fa6b18
started editing gps linearization
rahdal Nov 30, 2023
819952f
gps now put in sim
pearlastrid Nov 30, 2023
473c1dd
edited test subscriber
pearlastrid Dec 1, 2023
fdc6561
Merge branch 'dualGnss' into rtk
rahdal Dec 1, 2023
5aa6dac
added pose calculation using heading
rahdal Dec 1, 2023
db998ea
tests for both gps distance
dllliu Dec 3, 2023
670261f
changes for testing with convert lat long to cartesian to see offset …
dllliu Dec 3, 2023
29e0748
tests for offset
dllliu Dec 6, 2023
090866c
offset is 10?
dllliu Dec 6, 2023
069a2cf
chanegd offset to 1 and modified testing code
nehakankanala Dec 7, 2023
10d328d
Add requirements
umroverPerception Dec 10, 2023
2659e84
updated linearlization
rahdal Jan 14, 2024
820ef7e
merged
rahdal Jan 14, 2024
a3eb9e7
debug linearization function and try to debug sim
dllliu Jan 17, 2024
6ac7f8d
fixed reference points and removed z component for better rviz experi…
rbridges12 Jan 19, 2024
46e4f77
made a temporary GPS sim
rbridges12 Jan 19, 2024
e7e62ca
fixed pose publishing offset temporarily
rbridges12 Jan 19, 2024
b7c97f8
Add starter work for gps
qhdwight Jan 20, 2024
aee2d8c
cartesian to geodetic conversion
rbridges12 Jan 20, 2024
12a9710
Finish off gps and add imu
qhdwight Jan 20, 2024
ba650e1
Merge remote-tracking branch 'origin/sim-gps-imu' into rtk
qhdwight Jan 20, 2024
ad25d42
Yo workingin the new sim
qhdwight Jan 20, 2024
39ec2cd
Submodule update for dawn
qhdwight Jan 20, 2024
594cffc
added rviz to launch file, misc cleanup
rbridges12 Jan 21, 2024
3f713e4
Merge branch 'rtk' of github.com:umrover/mrover-ros into rtk
rbridges12 Jan 21, 2024
9aabf03
refactored utils and tag detector, crashes when it sees a tag
rbridges12 Jan 21, 2024
95e0198
debugging
rbridges12 Feb 1, 2024
686d2e8
more factoring test
rbridges12 Feb 15, 2024
39ef5d2
refactored SE3 util functions back into lie library
rbridges12 Feb 15, 2024
77d3d15
refactored most of sim
rbridges12 Feb 15, 2024
8f540a6
more debugging
rbridges12 Feb 15, 2024
15065f2
Add manif as submodule, find out some disgustig things about transfor…
qhdwight Feb 15, 2024
dd19c55
refactored camera controls using tangent elements
rbridges12 Feb 15, 2024
77a03e5
merged in integration
rbridges12 Feb 15, 2024
3dd06d3
pr cleanup
rbridges12 Feb 16, 2024
a282a9e
more cleanup
rbridges12 Feb 16, 2024
ff5d48a
more cleanup
rbridges12 Feb 16, 2024
dab754f
Remove unrelated stuff, clean up some stuff, remove old lie stuff
qhdwight Feb 16, 2024
3fc5014
Rename to lie.hpp
qhdwight Feb 16, 2024
f65068c
Refactor look controls
qhdwight Feb 16, 2024
a45e9b9
Comments
qhdwight Feb 16, 2024
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
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@
url = https://dawn.googlesource.com/dawn
shallow = true
branch = chromium/6108
[submodule "deps/manif"]
path = deps/manif
url = https://github.com/artivis/manif.git
shallow = true
14 changes: 9 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,15 @@ if (MROVER_BUILD_SIM)
find_package(glfw3 REQUIRED)

include(cmake/webgpu.cmake)

add_subdirectory(deps/glfw3webgpu)
add_subdirectory(deps/glfw3webgpu SYSTEM)
find_package(Assimp REQUIRED)
find_package(Bullet REQUIRED)
find_package(glfw3 REQUIRED)
endif ()
find_package(OpenCV REQUIRED)
find_package(ZED QUIET)
find_package(Eigen3 REQUIRED)
add_subdirectory(deps/manif SYSTEM)
find_package(PkgConfig REQUIRED)
pkg_search_module(NetLink libnl-3.0)
pkg_search_module(NetLinkRoute libnl-route-3.0)
Expand Down Expand Up @@ -146,6 +149,7 @@ catkin_package()
## Libraries

mrover_add_library(lie src/util/lie/*.cpp src/util/lie)
target_link_libraries(lie PUBLIC manif)

## ESW

Expand Down Expand Up @@ -187,7 +191,7 @@ endif ()
## Perception

mrover_add_nodelet(tag_detector src/perception/tag_detector/*.cpp src/perception/tag_detector src/perception/tag_detector/pch.hpp)
mrover_nodelet_link_libraries(tag_detector opencv_core opencv_objdetect opencv_aruco opencv_imgproc opencv_highgui lie)
mrover_nodelet_link_libraries(tag_detector opencv_core opencv_objdetect opencv_aruco opencv_imgproc opencv_highgui lie manif)

if (CUDA_FOUND)
mrover_add_library(streaming src/esw/streaming/*.c* src/esw/streaming)
Expand All @@ -200,7 +204,7 @@ endif ()
if (ZED_FOUND)
mrover_add_nodelet(zed src/perception/zed_wrapper/*.c* src/perception/zed_wrapper src/perception/zed_wrapper/pch.hpp)
mrover_nodelet_include_directories(zed ${ZED_INCLUDE_DIRS} ${CUDA_INCLUDE_DIRS})
mrover_nodelet_link_libraries(zed ${ZED_LIBRARIES} ${SPECIAL_OS_LIBS} lie)
mrover_nodelet_link_libraries(zed ${ZED_LIBRARIES} ${SPECIAL_OS_LIBS} lie manif)
mrover_nodelet_defines(zed
ALLOW_BUILD_DEBUG # Ignore ZED warnings about Debug mode
__CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ # Eigen includes some files it should not, ignore
Expand All @@ -216,7 +220,7 @@ mrover_add_node(arm_controller src/teleoperation/arm_controller/*.cpp)
if (MROVER_BUILD_SIM)
mrover_add_nodelet(simulator src/simulator/*.cpp src/simulator src/simulator/pch.hpp)
mrover_nodelet_include_directories(simulator ${ASSIMP_INCLUDE_DIRS} ${BULLET_INCLUDE_DIRS} ${OPENCV_INCLUDE_DIRS} src/simulator/imgui)
mrover_nodelet_link_libraries(simulator ${ASSIMP_LIBRARIES} ${BULLET_LIBRARIES} glfw3webgpu webgpu glfw opencv_core opencv_imgcodecs opencv_imgproc lie)
mrover_nodelet_link_libraries(simulator ${ASSIMP_LIBRARIES} ${BULLET_LIBRARIES} glfw3webgpu webgpu glfw opencv_core opencv_imgcodecs opencv_imgproc lie manif)
mrover_nodelet_defines(simulator BOOST_THREAD_PROVIDES_FUTURE)
endif ()

Expand Down
1 change: 1 addition & 0 deletions deps/manif
Submodule manif added at c8a9fc
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
<!-- Localization -->
<depend>rviz_imu_plugin</depend>
<depend>robot_localization</depend>
<depend>rtcm_msgs</depend>
qhdwight marked this conversation as resolved.
Show resolved Hide resolved

<!-- Navigation -->

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ dependencies = [
"moteus==0.3.59",
"pymap3d==3.0.1",
"aenum==3.1.15",
"pyubx2==1.2.35",
qhdwight marked this conversation as resolved.
Show resolved Hide resolved
"daphne==4.0.0",
"channels==4.0.0",
]
Expand Down
1 change: 1 addition & 0 deletions src/perception/tag_detector/pch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@
#include <mrover/DetectorParamsConfig.h>

#include <loop_profiler.hpp>
#include <manif/manif.h>
#include <point.hpp>
#include <se3.hpp>
2 changes: 1 addition & 1 deletion src/perception/tag_detector/tag_detector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,5 @@ namespace mrover {
res.success = true;
return true;
}

} // namespace mrover
4 changes: 2 additions & 2 deletions src/perception/tag_detector/tag_detector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace mrover {
int id = -1;
int hitCount = 0;
cv::Point2f imageCenter{};
std::optional<SE3> tagInCam;
std::optional<SE3d> tagInCam;
};

class TagDetectorNodelet : public nodelet::Nodelet {
Expand Down Expand Up @@ -53,7 +53,7 @@ namespace mrover {

void publishThresholdedImage();

std::optional<SE3> getTagInCamFromPixel(sensor_msgs::PointCloud2ConstPtr const& cloudPtr, size_t u, size_t v);
std::optional<SE3d> getTagInCamFromPixel(sensor_msgs::PointCloud2ConstPtr const& cloudPtr, size_t u, size_t v);

public:
TagDetectorNodelet() = default;
Expand Down
10 changes: 5 additions & 5 deletions src/perception/tag_detector/tag_detector.processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace mrover {
* @param u X Pixel Position
* @param v Y Pixel Position
*/
std::optional<SE3> TagDetectorNodelet::getTagInCamFromPixel(sensor_msgs::PointCloud2ConstPtr const& cloudPtr, size_t u, size_t v) {
std::optional<SE3d> TagDetectorNodelet::getTagInCamFromPixel(sensor_msgs::PointCloud2ConstPtr const& cloudPtr, size_t u, size_t v) {
assert(cloudPtr);

if (u >= cloudPtr->width || v >= cloudPtr->height) {
Expand All @@ -23,7 +23,7 @@ namespace mrover {
return std::nullopt;
}

return std::make_optional<SE3>(R3{point.x, point.y, point.z}, SO3{});
return std::make_optional<SE3d>(R3{point.x, point.y, point.z}, SO3d::Identity());
}

/**
Expand Down Expand Up @@ -81,7 +81,7 @@ namespace mrover {
if (tag.tagInCam) {
// Publish tag to immediate
std::string immediateFrameId = "immediateFiducial" + std::to_string(tag.id);
SE3::pushToTfTree(mTfBroadcaster, immediateFrameId, mCameraFrameId, tag.tagInCam.value());
SE3Conversions::pushToTfTree(mTfBroadcaster, immediateFrameId, mCameraFrameId, tag.tagInCam.value());
}
}

Expand All @@ -108,8 +108,8 @@ namespace mrover {
std::string immediateFrameId = "immediateFiducial" + std::to_string(tag.id);
// Publish tag to odom
std::string const& parentFrameId = mUseOdom ? mOdomFrameId : mMapFrameId;
SE3 tagInParent = SE3::fromTfTree(mTfBuffer, parentFrameId, immediateFrameId);
SE3::pushToTfTree(mTfBroadcaster, "fiducial" + std::to_string(id), parentFrameId, tagInParent);
SE3d tagInParent = SE3Conversions::fromTfTree(mTfBuffer, parentFrameId, immediateFrameId);
SE3Conversions::pushToTfTree(mTfBroadcaster, "fiducial" + std::to_string(id), parentFrameId, tagInParent);
} catch (tf2::ExtrapolationException const&) {
NODELET_WARN("Old data for immediate tag");
} catch (tf2::LookupException const&) {
Expand Down
3 changes: 1 addition & 2 deletions src/perception/zed_wrapper/pch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,5 @@
#include <tf2_ros/transform_broadcaster.h>
#include <tf2_ros/transform_listener.h>

#include <se3.hpp>
#include <point.hpp>
#include <loop_profiler.hpp>
#include <point.hpp>
1 change: 0 additions & 1 deletion src/perception/zed_wrapper/zed_wrapper.bridge.cu
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Be careful what you include in this file, it is compiled with nvcc (NVIDIA CUDA compiler)
// For example OpenCV and lie includes cause problems

#include "zed_wrapper.hpp"

Expand Down
13 changes: 8 additions & 5 deletions src/perception/zed_wrapper/zed_wrapper.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "zed_wrapper.hpp"

#include <manif/manif.h>
#include <se3.hpp>

namespace mrover {

/**
Expand Down Expand Up @@ -252,11 +255,11 @@ namespace mrover {
sl::Translation const& translation = pose.getTranslation();
sl::Orientation const& orientation = pose.getOrientation();
try {
SE3 leftCameraInOdom{{translation.x, translation.y, translation.z},
Eigen::Quaterniond{orientation.w, orientation.x, orientation.y, orientation.z}.normalized()};
SE3 leftCameraInBaseLink = SE3::fromTfTree(mTfBuffer, "base_link", "zed2i_left_camera_frame");
SE3 baseLinkInOdom = leftCameraInBaseLink * leftCameraInOdom;
SE3::pushToTfTree(mTfBroadcaster, "base_link", "odom", baseLinkInOdom);
SE3d leftCameraInOdom{{translation.x, translation.y, translation.z},
Eigen::Quaterniond{orientation.w, orientation.x, orientation.y, orientation.z}.normalized()};
SE3d baseLinkToLeftCamera = SE3Conversions::fromTfTree(mTfBuffer, "base_link", "zed2i_left_camera_frame");
SE3d baseLinkInOdom = leftCameraInOdom * baseLinkToLeftCamera;
SE3Conversions::pushToTfTree(mTfBroadcaster, "base_link", "odom", baseLinkInOdom);
} catch (tf2::TransformException& e) {
NODELET_WARN_STREAM("Failed to get transform: " << e.what());
}
Expand Down
1 change: 1 addition & 0 deletions src/simulator/pch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@

#include <bimap.hpp>
#include <loop_profiler.hpp>
#include <manif/manif.h>
#include <params_utils.hpp>
#include <point.hpp>
#include <se3.hpp>
Expand Down
37 changes: 23 additions & 14 deletions src/simulator/simulator.controls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,32 @@ namespace mrover {

auto SimulatorNodelet::freeLook(Clock::duration dt) -> void {
float flySpeed = mFlySpeed * std::chrono::duration_cast<std::chrono::duration<float>>(dt).count();
if (glfwGetKey(mWindow.get(), mCamRightKey) == GLFW_PRESS) {
mCameraInWorld = SE3{R3{0, -flySpeed, 0}, SO3{}} * mCameraInWorld;
}
if (glfwGetKey(mWindow.get(), mCamLeftKey) == GLFW_PRESS) {
mCameraInWorld = SE3{R3{0, flySpeed, 0}, SO3{}} * mCameraInWorld;
}
SE3d::Tangent delta_x, delta_y, delta_z;
delta_x << Eigen::Vector3d::UnitX(), Eigen::Vector3d::Zero();
qhdwight marked this conversation as resolved.
Show resolved Hide resolved
delta_y << Eigen::Vector3d::UnitY(), Eigen::Vector3d::Zero();
delta_z << Eigen::Vector3d::UnitZ(), Eigen::Vector3d::Zero();

// TODO: turn this into a single rplus and lplus operation
// overloaded rplus for movement relative to camera frame
if (glfwGetKey(mWindow.get(), mCamForwardKey) == GLFW_PRESS) {
mCameraInWorld = SE3{R3{flySpeed, 0, 0}, SO3{}} * mCameraInWorld;
mCameraInWorld += delta_x * flySpeed;
}
if (glfwGetKey(mWindow.get(), mCamBackwardKey) == GLFW_PRESS) {
mCameraInWorld = SE3{R3{-flySpeed, 0, 0}, SO3{}} * mCameraInWorld;
mCameraInWorld += delta_x * -flySpeed;
}
if (glfwGetKey(mWindow.get(), mCamLeftKey) == GLFW_PRESS) {
mCameraInWorld += delta_y * flySpeed;
}
if (glfwGetKey(mWindow.get(), mCamRightKey) == GLFW_PRESS) {
mCameraInWorld += delta_y * -flySpeed;
}

// overloaded lplus for movement relative to world frame
if (glfwGetKey(mWindow.get(), mCamUpKey) == GLFW_PRESS) {
mCameraInWorld = mCameraInWorld * SE3{R3{0, 0, flySpeed}, SO3{}};
mCameraInWorld = delta_z * flySpeed + mCameraInWorld;
}
if (glfwGetKey(mWindow.get(), mCamDownKey) == GLFW_PRESS) {
mCameraInWorld = mCameraInWorld * SE3{R3{0, 0, -flySpeed}, SO3{}};
mCameraInWorld = delta_z * -flySpeed + mCameraInWorld;
}

Eigen::Vector2i size;
Expand All @@ -112,10 +121,10 @@ namespace mrover {

Eigen::Vector2d delta = (mouse - center) * mLookSense;

// TODO(quintin): use lie algebra more here? we have a perturbation in the tangent space
R3 p = mCameraInWorld.position();
SO3 q = SO3{delta.y(), R3::UnitY()} * mCameraInWorld.rotation() * SO3{-delta.x(), R3::UnitZ()};
mCameraInWorld = SE3{p, q};
// lplus for tilt in camera frame, rplus for pan in world frame
SO3d::Tangent delta_Ry = Eigen::Vector3d::UnitY() * delta.y();
SO3d::Tangent delta_Rz = Eigen::Vector3d::UnitZ() * -delta.x();
mCameraInWorld.asSO3() = delta_Rz + mCameraInWorld.asSO3() + delta_Ry;

centerCursor();
}
Expand Down
17 changes: 12 additions & 5 deletions src/simulator/simulator.gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ namespace mrover {
URDF const& rover = it->second;

{
SE3 baseLinkInMap = rover.linkInWorld("base_link");
R3 p = baseLinkInMap.position();
S3 q = baseLinkInMap.rotation().quaternion();
SE3d baseLinkInMap = rover.linkInWorld("base_link");
R3 p = baseLinkInMap.translation();
S3 q = baseLinkInMap.quat();
ImGui::Text("Rover Position: (%.2f, %.2f, %.2f)", p.x(), p.y(), p.z());
ImGui::Text("Rover Orientation: (%.2f, %.2f, %.2f, %.2f)", q.w(), q.x(), q.y(), q.z());
}
{
R3 p = mCameraInWorld.position();
S3 q = mCameraInWorld.rotation().quaternion();
R3 p = mCameraInWorld.translation();
S3 q = mCameraInWorld.quat();
ImGui::Text("Camera Position: (%.2f, %.2f, %.2f)", p.x(), p.y(), p.z());
ImGui::Text("Camera Orientation: (%.2f, %.2f, %.2f, %.2f)", q.w(), q.x(), q.y(), q.z());
}
Expand Down Expand Up @@ -134,6 +134,13 @@ namespace mrover {
}
}

{
qhdwight marked this conversation as resolved.
Show resolved Hide resolved
R3 rayStart = mCameraInWorld.translation();
R3 rayEnd = rayStart + mCameraInWorld.rotation().matrix().col(0);
// btMul
// mDynamicsWorld->rayTest(r3ToBtVector3(rayStart), r3ToBtVector3(rayEnd), [
}

for (Camera const& camera: mCameras) {
float aspect = static_cast<float>(camera.resolution.x()) / static_cast<float>(camera.resolution.y());
ImGui::Image(camera.colorTextureView, {320, 320 / aspect}, {0, 0}, {1, 1});
Expand Down
7 changes: 4 additions & 3 deletions src/simulator/simulator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "glfw_pointer.hpp"
#include "wgpu_objects.hpp"
#include "glfw_pointer.hpp"
qhdwight marked this conversation as resolved.
Show resolved Hide resolved

using namespace std::literals;

Expand Down Expand Up @@ -97,7 +98,7 @@ namespace mrover {

auto makeCameraForLink(SimulatorNodelet& simulator, btMultibodyLink const* link) -> Camera;

[[nodiscard]] auto linkInWorld(std::string const& linkName) const -> SE3;
[[nodiscard]] auto linkInWorld(std::string const& linkName) const -> SE3d;
};

struct PeriodicTask {
Expand Down Expand Up @@ -305,7 +306,7 @@ namespace mrover {

auto getUrdf(std::string const& name) -> std::optional<std::reference_wrapper<URDF>>;

SE3 mCameraInWorld{R3{-3.0, 0.0, 1.5}, SO3{}};
SE3d mCameraInWorld{R3{-3.0, 0.0, 1.5}, SO3d::Identity()};

std::vector<StereoCamera> mStereoCameras;
std::vector<Camera> mCameras;
Expand Down Expand Up @@ -432,7 +433,7 @@ namespace mrover {

auto urdfPoseToBtTransform(urdf::Pose const& pose) -> btTransform;

auto btTransformToSe3(btTransform const& transform) -> SE3;
auto btTransformToSe3(btTransform const& transform) -> SE3d;

auto computeCameraToClip(float fovY, float aspect, float zNear, float zFar) -> Eigen::Matrix4f;

Expand Down
20 changes: 11 additions & 9 deletions src/simulator/simulator.physics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

namespace mrover {

auto btTransformToSe3(btTransform const& transform) -> SE3 {
auto btTransformToSe3(btTransform const& transform) -> SE3d {
btVector3 const& p = transform.getOrigin();
btQuaternion const& q = transform.getRotation();
return SE3{R3{p.x(), p.y(), p.z()}, SO3{q.w(), q.x(), q.y(), q.z()}};
// Note: Must convert the Bullet quaternion (floats) to a normalized Eigen quaternion (doubles).
// Otherwise the normality check will fail in the SO3 constructor.
return SE3d{R3{p.x(), p.y(), p.z()}, Eigen::Quaterniond{q.w(), q.x(), q.y(), q.z()}.normalized()};
}

auto SimulatorNodelet::initPhysics() -> void {
Expand Down Expand Up @@ -76,9 +78,9 @@ namespace mrover {
int index = urdf.linkNameToMeta.at(link->name).index;
// TODO(quintin): figure out why we need to negate rvector
btTransform parentToChild{urdf.physics->getParentToLocalRot(index), -urdf.physics->getRVector(index)};
SE3 childInParent = btTransformToSe3(parentToChild.inverse());
SE3d childInParent = btTransformToSe3(parentToChild.inverse());

SE3::pushToTfTree(mTfBroadcaster, link->name, link->getParent()->name, childInParent);
SE3Conversions::pushToTfTree(mTfBroadcaster, link->name, link->getParent()->name, childInParent);
}

for (urdf::JointSharedPtr const& child_joint: link->child_joints) {
Expand All @@ -95,17 +97,17 @@ namespace mrover {
if (auto modelOpt = getUrdf(modelName)) {
URDF const& model = *modelOpt;

SE3 modelInMap = btTransformToSe3(model.physics->getBaseWorldTransform());
SE3 roverInMap = btTransformToSe3(rover.physics->getBaseWorldTransform());
SE3d modelInMap = btTransformToSe3(model.physics->getBaseWorldTransform());
SE3d roverInMap = btTransformToSe3(rover.physics->getBaseWorldTransform());

R3 roverToModel = modelInMap.position() - roverInMap.position();
R3 roverToModel = modelInMap.translation() - roverInMap.translation();
double roverDistanceToModel = roverToModel.norm();
roverToModel /= roverDistanceToModel;
R3 roverForward = roverInMap.rotation().matrix().col(0);
double roverDotModel = roverToModel.dot(roverForward);

if (roverDotModel > 0 && roverDistanceToModel < threshold) {
SE3::pushToTfTree(mTfBroadcaster, modelName, "map", modelInMap);
SE3Conversions::pushToTfTree(mTfBroadcaster, modelName, "map", modelInMap);
}
}
};
Expand All @@ -115,7 +117,7 @@ namespace mrover {
}
}

auto URDF::linkInWorld(std::string const& linkName) const -> SE3 {
auto URDF::linkInWorld(std::string const& linkName) const -> SE3d {
int index = linkNameToMeta.at(linkName).index;
return btTransformToSe3(index == -1 ? physics->getBaseWorldTransform() : physics->getLink(index).m_cachedWorldTransform);
}
Expand Down
Loading