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
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
a094d71
Compiles and runs sim with gz joint to encoder
melissajcruz Aug 31, 2023
df54c24
Does not compile
melissajcruz Sep 9, 2023
f57772c
Merge branch 'develop' into feature/gazebo-sim-fixes
melissajcruz Sep 9, 2023
898d8de
Merge branch 'develop' into feature/gazebo-sim-fixes
melissajcruz Sep 9, 2023
2bf19d1
Sim runs. Robot control unstable b/c
melissajcruz Sep 10, 2023
50ad98b
cleans std::cout
melissajcruz Sep 10, 2023
f348572
v5actuatorcmd test pubs v5 mtr cmd
melissajcruz Sep 18, 2023
e3e05bc
sim rotates wheel module
melissajcruz Sep 18, 2023
ca31c0b
Swerve moves in sim with pseudo turret. Must
melissajcruz Oct 1, 2023
ce89eca
Adds swerve kinematics and joystick msg
melissajcruz Oct 15, 2023
f53d6a8
joystick publishes, sim torques dont work
JakeWendling Oct 15, 2023
ce74e6e
joystick devel pt 2
melissajcruz Oct 15, 2023
e7c7cf0
adds symlink-install option to build script
MaxxWilson Oct 17, 2023
f7266e7
modifes joystick channel to be configurable from launch file
MaxxWilson Oct 17, 2023
b532fe3
attempts to fix bugs
MaxxWilson Oct 17, 2023
a452f41
uncomment swerve jacobian
MaxxWilson Oct 17, 2023
8670ac8
Merge pull request #34 from VEXU-GHOST/bug-fix/sim-node-debugging
JakeWendling Oct 17, 2023
6effd71
test diff drive model in gz.
melissajcruz Nov 8, 2023
736f7ef
Test diff drive spawns in gz
melissajcruz Dec 11, 2023
d6c8dfc
Adds plotjuggler to
melissajcruz Dec 14, 2023
459135d
imu topic not being published to for robot_localization pkg
melissajcruz Dec 27, 2023
f47efc8
robot localization node launches
melissajcruz Dec 28, 2023
a8fe4bf
robot localization EKF node launches
melissajcruz Dec 28, 2023
fee13b2
Merge branch 'feature/gazebo-sim-fixes' of github.com:VEXU-GHOST/VEXU…
melissajcruz Jan 2, 2024
933e6f5
Merge pull request #38 from VEXU-GHOST/develop
melissajcruz Jan 2, 2024
30b8449
EKF works with test diff drive if given cmd_vel. Need to test EKF whe…
melissajcruz Jan 3, 2024
b795ecf
Cleaning not needed files
melissajcruz Jan 4, 2024
9b474ea
Added dependencies for package,.xmls
melissajcruz Jan 4, 2024
3b53311
Adds changes from PR comments
melissajcruz Jan 5, 2024
0391de2
Addresses PR comments and adds gz tests
melissajcruz Jan 7, 2024
772d3c4
update git ignore
melissajcruz Jan 7, 2024
9f43781
Testing script runs, fails some assertions.
melissajcruz Jan 11, 2024
34a612f
Fixed weird x angular velocty:
melissajcruz Jan 15, 2024
e5c7b67
Changes diff drive tests and adds test script
melissajcruz Jan 25, 2024
5afc0cc
Merge branch 'develop' of github.com:VEXU-GHOST/VEXU_GHOST into featu…
melissajcruz Jan 28, 2024
1ae2a9a
Refactors sim stack after hardware refactor
melissajcruz Jan 31, 2024
52f0c0a
Merge branch 'develop' into feature/gazebo-sim-fixes
melissajcruz Jan 31, 2024
2b1e79f
Cleaning
melissajcruz Jan 31, 2024
4ce8984
moves world files to world folder
MaxxWilson Feb 1, 2024
bf10964
fixes last world file move ref
MaxxWilson Feb 1, 2024
4d9f1dc
change world path to worlds
MaxxWilson Feb 1, 2024
5108bac
moves test files to /tmp/
MaxxWilson Feb 1, 2024
27ebb98
removes boilerplate testing from ghost_tank
MaxxWilson Feb 1, 2024
cf04081
test fixing merge issues
MaxxWilson Feb 1, 2024
fe2ad1b
more reverting merge changes
MaxxWilson Feb 1, 2024
4674e42
merge fixes v3
MaxxWilson Feb 1, 2024
5bd6656
final merge fixes?
MaxxWilson Feb 1, 2024
aecba23
revert swerve changes
MaxxWilson Feb 1, 2024
cf22447
Changes dep to add pj and pjros
melissajcruz Feb 1, 2024
8c3b84a
Merge branch 'feature/gazebo-sim-fixes' of github.com:VEXU-GHOST/VEXU…
melissajcruz Feb 1, 2024
2027038
Cleaning
melissajcruz Feb 1, 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
225 changes: 225 additions & 0 deletions 03_ROS/ghost_ros_interfaces/config/robot_localization_config.yaml

Large diffs are not rendered by default.

48 changes: 34 additions & 14 deletions 03_ROS/ghost_sim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ add_compile_options(-Wno-dev)
########################
set(DEPENDENCIES
ament_cmake
ament_cmake_gtest
Eigen3
yaml-cpp
rclcpp
Expand Down Expand Up @@ -50,13 +51,15 @@ ${PYTHON_INCLUDE_DIRS}
include_directories(${INCLUDE})
ament_export_include_directories(${INCLUDE})

link_directories(${gazebo_dev_LIBRARY_DIRS})
include_directories(${GTEST_INCLUDE_DIRS})

link_directories(${gazebo_dev_LIBRARY_DIRS})

###################
##### TARGETS #####
###################
# Gazebo Motor Plugin

# add_library(gazebo_motor_plugin SHARED src/gazebo_motor_plugin.cpp)
# ament_target_dependencies(gazebo_motor_plugin
# ${DEPENDENCIES}
Expand All @@ -69,6 +72,7 @@ link_directories(${gazebo_dev_LIBRARY_DIRS})
# $<INSTALL_INTERFACE:include>)
# ament_export_libraries(gazebo_motor_plugin)


# Gazebo Joint PID Plugin
# add_library(gazebo_joint_pid_plugin SHARED src/gazebo_joint_pid_plugin.cpp)
# ament_target_dependencies(gazebo_joint_pid_plugin
Expand All @@ -90,6 +94,26 @@ link_directories(${gazebo_dev_LIBRARY_DIRS})
# $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
# $<INSTALL_INTERFACE:include>)
# ament_export_libraries(gazebo_joint_pid_plugin)
enable_testing()
ament_add_gtest(test_diff_drive test/test_diff_drive.cpp
# Long timeout because has to run gazebo several times
TIMEOUT
120)

target_link_libraries(test_diff_drive
gazebo_test_fixture
)

ament_target_dependencies(test_diff_drive
"builtin_interfaces"
"gazebo_dev"
"gazebo_msgs"
"geometry_msgs"
"rclcpp"
"sensor_msgs"
"std_msgs"
"nav_msgs"
)

# Gazebo V5 Robot Plugin
# add_library(v5_robot_plugin SHARED src/v5_robot_plugin.cpp)
Expand All @@ -112,29 +136,25 @@ link_directories(${gazebo_dev_LIBRARY_DIRS})
# ground_truth_pose_publisher
# DESTINATION lib/${PROJECT_NAME})

# Node to test new V5ActuactorCommand communication
# add_executable(test_publisher_v5_actuator_cmd
# test/test_publisher_v5_actuator_cmd.cpp
# )
# ament_target_dependencies(test_publisher_v5_actuator_cmd
# ${DEPENDENCIES}
################
### Install ####
################
# install(
# PROGRAMS launch/test_tank_sim.launch.py
# DESTINATION lib/${PROJECT_NAME}
# )
# install(TARGETS
# test_publisher_v5_actuator_cmd
# DESTINATION lib/${PROJECT_NAME})

# ################
# ### Install ####
# ################
install(
DIRECTORY include/
DIRECTORY include
DESTINATION include
)

install(DIRECTORY
launch
urdf
worlds
config
DESTINATION share/${PROJECT_NAME})


ament_package()
14 changes: 8 additions & 6 deletions 03_ROS/ghost_sim/config/v5_sim_config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
motor_names:
- "DRIVE_LEFT_FRONT_MOTOR"
- "DRIVE_LEFT_BACK_MOTOR"
- "DRIVE_RIGHT_FRONT_MOTOR"
- "DRIVE_RIGHT_BACK_MOTOR"
- "DRIVE_BACK_LEFT_1_MOTOR"
- "DRIVE_BACK_RIGHT_1_MOTOR"
- "DRIVE_LEFT_FRONT_LEFT_MOTOR"
- "DRIVE_LEFT_FRONT_RIGHT_MOTOR"
- "DRIVE_LEFT_BACK_LEFT_MOTOR"
- "DRIVE_LEFT_BACK_RIGHT_MOTOR"
- "DRIVE_RIGHT_FRONT_LEFT_MOTOR"
- "DRIVE_RIGHT_FRONT_RIGHT_MOTOR"
- "DRIVE_RIGHT_BACK_LEFT_MOTOR"
- "DRIVE_RIGHT_BACK_RIGHT_MOTOR"
- "TURRET_MOTOR"
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ class testPublisherV5ActuatorCmd : public rclcpp::Node {

void publishData();
rclcpp::Publisher<ghost_msgs::msg::V5ActuatorCommand>::SharedPtr output_pub_;
std::array<std::string, 8> motors_{"DRIVE_LEFT_FRONT_LEFT_MOTOR",
MaxxWilson marked this conversation as resolved.
Show resolved Hide resolved
"DRIVE_LEFT_FRONT_RIGHT_MOTOR", "DRIVE_LEFT_BACK_LEFT_MOTOR", "DRIVE_LEFT_BACK_RIGHT_MOTOR",
"DRIVE_RIGHT_FRONT_LEFT_MOTOR", "DRIVE_RIGHT_FRONT_RIGHT_MOTOR", "DRIVE_RIGHT_BACK_LEFT_MOTOR",
"DRIVE_RIGHT_BACK_RIGHT_MOTOR"};
ghost_msgs::msg::V5MotorCommand populateMotorCmd(const int loop_index);

// private:
Expand Down
46 changes: 42 additions & 4 deletions 03_ROS/ghost_sim/include/ghost_sim/v5_robot_plugin.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <algorithm>
#include <Eigen/QR>
#include <memory>
#include <random>
#include <vector>
Expand Down Expand Up @@ -34,12 +35,49 @@ class V5RobotPlugin : public gazebo::ModelPlugin {
void Load(gazebo::physics::ModelPtr model, sdf::ElementPtr sdf) override;

protected:
/**
* Converts joint data from Gazebo to encoder data using sensor jacobian matrix
*/
void jointToEncoderTransform();
ghost_msgs::msg::V5EncoderState wrapEncoderMsg(const int col_index);
ghost_msgs::msg::V5SensorUpdate populateSensorMsg();
void getJointStates();

/// Optional callback to be called at every simulation iteration.
/**
* Transforms motor data (motor pos, or vel, or accel), to the location of the corresponding joint in swerve model
*/
Eigen::VectorXd motorToJointTransform(const Eigen::VectorXd& motor_data);

/**
* Transforms joint data (joint pos, or vel, or accel), to the location of the corresponding motor in swerve model
*/
Eigen::VectorXd jointToMotorTransform(const Eigen::VectorXd& joint_data);

/**
* Updates joint commands given motor actuator input command
*/
void updateMotorController();

/**
* Wraps encoder matrix into V5Encoder state msg[]
*/
void wrapEncoderMsg();

/**
* Populates sensor msg using current encoder msg
*/
void populateSensorMsg();

/**
* Updates joint angles and velocities from gazebo
*/
void updateJointStates();

/**
* Applies command joint torques to gazebo links
*/
void applySimJointTorques();

/**
* Optional callback to be called by Gazebo at every simulation iteration.
*/
void OnUpdate();

private:
Expand Down
23 changes: 18 additions & 5 deletions 03_ROS/ghost_sim/launch/joystick.launch.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, OpaqueFunction
from launch.substitutions import LaunchConfiguration

from launch_ros.actions import Node

def generate_launch_description():
return LaunchDescription([
Node(
def launch_setup(context, *args, **kwargs):

channel_id = context.perform_substitution(LaunchConfiguration('channel_id'))
joy_linux_node = Node(
package = 'joy_linux',
executable = 'joy_linux_node',
name = 'joystick_node',
parameters= [{
"dev": "/dev/input/js0"
"dev": "/dev/input/js" + channel_id
}]
),
)

return [joy_linux_node]

def generate_launch_description():


return LaunchDescription([
DeclareLaunchArgument(name='channel_id', default_value='1'),
OpaqueFunction(function = launch_setup),
Node(
package = 'teleop_twist_joy',
executable = 'teleop_node',
Expand Down
6 changes: 3 additions & 3 deletions 03_ROS/ghost_sim/launch/new_v5_msg_config_test.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ def launch_setup(context, *args, **kwargs):
def generate_launch_description():
# Load relevant filepaths
gazebo_ros_share_dir = get_package_share_directory('gazebo_ros')
ghost_ros_share_dir = get_package_share_directory('ghost_ros')
ghost_ros_share_dir = get_package_share_directory('ghost_ros_interfaces')
ghost_sim_share_dir = get_package_share_directory('ghost_sim')

home_dir = os.path.expanduser('~')
ghost_ros_base_dir = os.path.join(home_dir, "VEXU_GHOST", "ghost_ros")
ghost_ros_base_dir = os.path.join(home_dir, "VEXU_GHOST", "ghost_ros_interfaces")

world_file = os.path.join(ghost_sim_share_dir, "urdf", "spin_up.world")
world_file = os.path.join(ghost_sim_share_dir, "worlds", "default.world")
rviz_config_path = os.path.join(ghost_ros_share_dir, 'rviz/urdf_config.rviz')

# Simulator (Doesn't launch Simulator GUI by default, use CLI Arg "sim_gui" for debugging)
Expand Down
74 changes: 42 additions & 32 deletions 03_ROS/ghost_sim/launch/start_sim.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,22 @@ def launch_setup(context, *args, **kwargs):
output='screen',
parameters=[{'use_sim_time': False}, {"robot_description": doc}])

return [gazebo_ros, robot_state_publisher]
# Joystick (Only launched if joystick CLI arg is set to True)
joy_launch_description = IncludeLaunchDescription(
PythonLaunchDescriptionSource(
os.path.join(
ghost_sim_share_dir,
"launch",
"joystick.launch.py"
)
),
condition=launch.conditions.IfCondition(LaunchConfiguration("use_joy")),
launch_arguments={
'channel_id': LaunchConfiguration("channel_id"),
}.items()
)

return [gazebo_ros, robot_state_publisher, joy_launch_description]


def generate_launch_description():
Expand All @@ -45,9 +60,9 @@ def generate_launch_description():
ghost_sim_share_dir = get_package_share_directory('ghost_sim')

home_dir = os.path.expanduser('~')
ghost_ros_base_dir = os.path.join(home_dir, "VEXU_GHOST", "ghost_ros")
ghost_ros_base_dir = os.path.join(home_dir, "VEXU_GHOST", "03_ROS", "ghost_ros")

world_file = os.path.join(ghost_sim_share_dir, "urdf", "spin_up.world")
world_file = os.path.join(ghost_sim_share_dir, "world", "default.world")
rviz_config_path = os.path.join(ghost_ros_share_dir, 'rviz/urdf_config.rviz')

# Simulator (Doesn't launch Simulator GUI by default, use CLI Arg "sim_gui" for debugging)
Expand All @@ -69,6 +84,12 @@ def generate_launch_description():
name='ground_truth_pose_publisher',
)

v5_actuator_cmd_publisher = Node(
package='ghost_sim',
executable = 'test_publisher_v5_actuator_cmd',
name = 'test_publisher_v5_actuator_cmd',
)

# Launch RVIZ Display as primary GUI interface
rviz_node = Node(
package='rviz2',
Expand All @@ -77,43 +98,32 @@ def generate_launch_description():
arguments=['-d', rviz_config_path],
)

# Joystick (Only launched if joystick CLI arg is set to True)
joy_launch_description = IncludeLaunchDescription(
PythonLaunchDescriptionSource(
os.path.join(
ghost_sim_share_dir,
"launch",
"joystick.launch.py"
)
),
condition=launch.conditions.IfCondition(LaunchConfiguration("joystick"))
estimator_node = Node(
package='ghost_ros',
executable='ghost_estimator_node',
name='ghost_estimator_node',
output='screen',
parameters=[ghost_ros_base_dir + "/config/ghost_estimator_config.yaml"]
)

# estimator_node = Node(
# package='ghost_ros',
# executable='ghost_estimator_node',
# name='ghost_estimator_node',
# output='screen',
# parameters=[ghost_ros_base_dir + "/config/ghost_estimator_config.yaml"]
# )

# state_machine_node = Node(
# package='ghost_ros',
# executable='robot_state_machine_node',
# name='ghost_state_machine_node',
# output='screen',
# parameters=[ghost_ros_base_dir + "/config/ghost_state_machine_config.yaml"]
# )
state_machine_node = Node(
package='ghost_ros',
executable='robot_state_machine_node',
name='ghost_state_machine',
output='screen',
parameters=[ghost_ros_base_dir + "/config/ghost_state_machine_config.yaml"]
)

return LaunchDescription([
DeclareLaunchArgument(name='joystick', default_value='false'),
DeclareLaunchArgument(name='use_joy', default_value='true'),
DeclareLaunchArgument(name='channel_id', default_value='1'),
DeclareLaunchArgument('sim_gui', default_value='true'),
DeclareLaunchArgument('verbose', default_value='true'),
simulation,
# ground_truth_publisher,
# rviz_node,
joy_launch_description,
rviz_node,
# estimator_node,
# state_machine_node,
state_machine_node,
# v5_actuator_cmd_publisher,
OpaqueFunction(function = launch_setup)
])
Loading