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

Feature/gazebo-sim-fixes #27

Merged
merged 51 commits into from
Feb 1, 2024
Merged

Feature/gazebo-sim-fixes #27

merged 51 commits into from
Feb 1, 2024

Conversation

MaxxWilson
Copy link
Collaborator

@MaxxWilson MaxxWilson commented Sep 9, 2023

PR Summary

PR Link: develop...feature/gazebo-sim-fixes
Issue Link: #6

Description

Develop a Plugin which mocks the V5SensorUpdate and V5ActuatorCommand ROS topics in Gazebo

Reviewers

Tag reviewers.


Changelog

  • Adds a diff drive gazebo model so that we could split testing the autonomy, controls, and estimation stack from developing the swerve model.
  • Adds EKF from robot_localization pkg. Somewhat tuned. Need to handle increase of estimated covariance over time.

Reviewer Guide

Most changes are in the ghost_sim pkg.

Field walls were removed since it caused a not-obvious bug: when given a cmd_vel, the robot collided with the walls and continued to attempt to achieve a cmd_vel, causing the wheels to slip, changing the odometry readings. Ultimately, the odometry encoder and the imu messages disagreed, causing the EKF to diverge.

Note that the EKF in this PR uses 3 "sensors": gazebo IMU plugin, actual truth model data as "odometry" data, and gazebo diff drive plugin odometry configured as "WORLD" instead of "ENCODER". Therefore, the data given to the EKF is very ideal data. Performance should be monitored with more noisy data.

Testing

Automatic

  • N/A

Manual

  • launch the plotjuggler, diff drive, robot_localization stack using:
    ros2 launch ghost_sim test_tank_sim.launch.py
    in a separate terminal launch
    ros2 topic pub --once /cmd_vel geometry_msgs/msg/Twist "{linear: {x: 5.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 0.0}}"
    or
    ros2 topic pub --once /cmd_vel geometry_msgs/msg/Twist "{linear: {x: 0.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 1.0}}"
    for sinsusoid motion.
    If subscribed to the odometry/filtered topic, the pose and twist should update with slight deviation from the gz/model_states pose and twist.

Documentation

  • Here is there package used for robot localization

Checklist

  • Confirmed all tests pass on a clean build
  • Added reviewers in Github
  • Posted PR Summary to Discord PR's Channel
  • Ran uncrustify on any modified C++ files
  • Ran Colcon Lint for any modified CMakeLists.txt or Package.xml

Here's a video of the diff drive EKF

sensor updates publishing across topic
Untested since gz motor command interface not defined
Adds encoder to joints and
motor to joint cmd interface
@melissajcruz
Copy link
Collaborator

This branch has V5Actuator update interface that lacks rigorous testing framework to validate.

In an attempt to overcome this, a test differential drive model was implemented without the V5actuator update interface using a differential drive gazebo plugin with the intention of combining the urdf model with the V5actuator update interface. However, development deviated from testing the V5actuator update interface to implementing the test diff drive model for developing an autonomy, estimation, control stack.

So, this branch has a diff drive with a robot localization stack implemented via a somewhat tuned EKF. I think the main purpose of this branch has deviated from the original purpose and should be merged back into dev.

I'm not sure what the status is of the sensor and actuator interfaces. We should discuss this!

.gitmodules Outdated Show resolved Hide resolved
install(TARGETS
foxglove_diagnostics_node
DESTINATION lib/${PROJECT_NAME})
# add_executable(foxglove_diagnostics_node
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was planning to delete this FYI, bc Foxglove seems sorta unsupported. Will handle in separate PR.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's been commented out in the CMake.

@@ -35,9 +36,13 @@ class V5RobotPlugin : public gazebo::ModelPlugin {

protected:
void jointToEncoderTransform();
ghost_msgs::msg::V5EncoderState wrapEncoderMsg(const int col_index);
ghost_msgs::msg::V5SensorUpdate populateSensorMsg();
Eigen::VectorXd motorToJointTransform(Eigen::VectorXd motor_data);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Header file methods need comment blocks. Autofills on my VSCode by doing /** and then enter

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed.

ghost_msgs::msg::V5EncoderState wrapEncoderMsg(const int col_index);
ghost_msgs::msg::V5SensorUpdate populateSensorMsg();
Eigen::VectorXd motorToJointTransform(Eigen::VectorXd motor_data);
Eigen::VectorXd jointToMotorTransform(Eigen::VectorXd joint_data);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should pass these by const ref if they aren't changing, and ref if they are changing. Try to avoid copying non-trivial types.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to const ref.

03_ROS/ghost_sim/src/v5_robot_plugin.cpp Show resolved Hide resolved
ghost_msgs::msg::V5Joystick joystick_msg_;

// Constants
float DEG_TO_RAD = M_PI / 180;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can these be 1) either const or constexpr, and 2) moved to ghost_util into a "types.hpp" header. Might want to use somewhere else.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already defined in 01_Libraries/ghost_common/include/ghost_common/util/angle_util.hpp so I just replaced the constants with the constants that already exist.

03_ROS/ghost_sim/src/v5_robot_plugin.cpp Show resolved Hide resolved
03_ROS/ghost_sim/src/v5_robot_plugin.cpp Show resolved Hide resolved
}

// Preserves order of joints listed in xacro
void V5RobotPlugin::getJointStates(){
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could this be updateJointStates(), since it isn't returning anything?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed!

@MaxxWilson
Copy link
Collaborator Author

MaxxWilson commented Jan 5, 2024

Looks very solid! And we have diff drive actually working in sim, which is dope.

There may be a lot of small interface changes on upcoming robot_interface overhaul PR, but those will be on my end lol.

Is there a way to add unit testing so we know we can load the plugin and it can load a default config file? I think there is a GazeboTestFixture example somewhere.

Can we also add videos to this PR of the working thing for documentation sake?

@melissajcruz
Copy link
Collaborator

melissajcruz commented Jan 24, 2024

Final Update:
Added working EKF video to PR description.
After speaking with Maxx, determined Gazebo Test Fixture used seems to be doing some dirty deallocation at the end of the test scripts. So, if your output looks something like this:

xacro: in-order processing became default in ROS Melodic. You can drop the option.
Allow generated test description files to be moved to temp testing folder
Killing gazebo processes
gzserver: no process found
UpdateCTestConfiguration  from :/home/melcruz/VEXU_GHOST/build/ghost_sim/CTestConfiguration.ini
Parse Config file:/home/melcruz/VEXU_GHOST/build/ghost_sim/CTestConfiguration.ini
 Add coverage exclude regular expressions.
UpdateCTestConfiguration  from :/home/melcruz/VEXU_GHOST/build/ghost_sim/CTestConfiguration.ini
Parse Config file:/home/melcruz/VEXU_GHOST/build/ghost_sim/CTestConfiguration.ini
Test project /home/melcruz/VEXU_GHOST/build/ghost_sim
Constructing a list of tests
Done constructing a list of tests
Updating test list for fixtures
Added 0 tests to meet fixture requirements
Checking test dependency graph...
Checking test dependency graph end
test 1
    Start 1: test_diff_drive

1: Test command: /usr/bin/python3.10 "-u" "/opt/ros/humble/share/ament_cmake_test/cmake/run_test.py" "/home/melcruz/VEXU_GHOST/build/ghost_sim/test_results/ghost_sim/test_diff_drive.gtest.xml" "--package-name" "ghost_sim" "--output-file" "/home/melcruz/VEXU_GHOST/build/ghost_sim/ament_cmake_gtest/test_diff_drive.txt" "--command" "/home/melcruz/VEXU_GHOST/build/ghost_sim/test_diff_drive" "--gtest_output=xml:/home/melcruz/VEXU_GHOST/build/ghost_sim/test_results/ghost_sim/test_diff_drive.gtest.xml"
1: Test timeout computed to be: 120
1: -- run_test.py: invoking following command in '/home/melcruz/VEXU_GHOST/build/ghost_sim':
1:  - /home/melcruz/VEXU_GHOST/build/ghost_sim/test_diff_drive --gtest_output=xml:/home/melcruz/VEXU_GHOST/build/ghost_sim/test_results/ghost_sim/test_diff_drive.gtest.xml
1: [==========] Running 1 test from 1 test suite.
1: [----------] Global test environment set-up.
1: [----------] 1 test from GazeboRosDiffDriveTest
1: [ RUN      ] GazeboRosDiffDriveTest.testBringUp
1: [Msg] Waiting for master.
1: [Msg] Connected to gazebo master @ http://127.0.0.1:11345
1: [Msg] Publicized address: 172.25.171.127
1: [Msg] Loading world file [/home/melcruz/VEXU_GHOST/install/ghost_sim/share/ghost_sim/urdf/spin_up.world]
1: [Wrn] [Event.cc:61] Warning: Deleting a connection right after creation. Make sure to save the ConnectionPtr from a Connect call
1: [Dbg] [ServerFixture.cc:211] ServerFixture load in 2.9 seconds, timeout after 600 seconds
1: /home/melcruz/VEXU_GHOST/install/ghost_sim/share/ghost_sim
1: ===Loading diff drive model===
1: [INFO] [1706057065.861770653] [gazebo_ros_state]: Publishing states of gazebo models at [/model_states]
1: [INFO] [1706057065.862330012] [gazebo_ros_state]: Publishing states of gazebo links at [/link_states]
1: [INFO] [1706057066.114238301] [gazebo_ros_diff_drive]: Wheel pair 1 separation set to [0.300000m]
1: [INFO] [1706057066.114302665] [gazebo_ros_diff_drive]: Wheel pair 1 diameter set to [0.200000m]
1: [INFO] [1706057066.115204849] [gazebo_ros_diff_drive]: Subscribed to [/cmd_vel]
1: [INFO] [1706057066.116717739] [gazebo_ros_diff_drive]: Advertise odometry on [/odom]
1: [INFO] [1706057066.120285924] [gazebo_ros_diff_drive]: Publishing odom transforms between [odom] and [base_link]
1: [INFO] [1706057066.120324185] [gazebo_ros_diff_drive]: Publishing wheel transforms between [base_link], [left_wheel_hinge] and [right_wheel_hinge]
1: [Dbg] [ServerFixture.cc:130] ServerFixture::Unload
1: -- run_test.py: return code -11
1: -- run_test.py: generate result file '/home/melcruz/VEXU_GHOST/build/ghost_sim/test_results/ghost_sim/test_diff_drive.gtest.xml' with failed test
1: -- run_test.py: verify result file '/home/melcruz/VEXU_GHOST/build/ghost_sim/test_results/ghost_sim/test_diff_drive.gtest.xml'
1/1 Test #1: test_diff_drive ..................***Failed    5.30 sec

0% tests passed, 1 tests failed out of 1

Label Time Summary:
gtest    =   5.30 sec*proc (1 test)

Total Test time (real) =   5.31 sec

The following tests FAILED:
          1 - test_diff_drive (Failed)
Errors while running CTest
Output from these tests are in: /home/melcruz/VEXU_GHOST/build/ghost_sim/Testing/Temporary/LastTest.log
Use "--rerun-failed --output-on-failure" to re-run the failed cases verbosely.

The diff drive test passed! Since there's no fix for now, we will just use a ros2 launch command to launch the sim and visually inspect that everything works.

@MaxxWilson
Copy link
Collaborator Author

2/1 Test Failures:
image

Copy link
Collaborator Author

@MaxxWilson MaxxWilson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good with this once submodules are fixed

03_ROS/deprecated/ghost_ros/CMakeLists.txt Outdated Show resolved Hide resolved
.gitmodules Outdated Show resolved Hide resolved
Copy link
Collaborator

@melissajcruz melissajcruz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@MaxxWilson MaxxWilson merged commit 04d091e into develop Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants