Store the API keys in ./scripts/onshape_api_key.sh
On every new terminal opened, run
Set up the ROS2 workspace
This procedure only needs to be performed when initially setting up a new workspace and package.
Create the package
Create additional folders
Test build
If the package is built without error, try the following command.
colcon_cd should navigate to our package directory ~/Desktop/humanoid-urdf/src/humanoid_v1
Create Config Files
We need to create these files in the ROS package.
humanoid_v1.launch.py:
rviz
urdf
Change Files
Change package.xml by adding these lines:
Change CMakeLists.txt by adding these lines:
Test Build
colcon build
source install/setup.sh
ros2 launch humanoid_v1 humanoid_v1.launch.py
If the following error is raised, we need to install the gui package separately, suggested here.
might also need
if running into this error:
highly possible that this is a VSCode terminal issue. Do
Onshape Modeling Considerations
When making mate connections, always click child component first, and then parent. (bind child to parent).
By doing so, the order of the mate connectors should look like the one shown in the following diagram.
Export Onshape robot
This command will dump the urdf and related asset files in ./onshape/humanoid_v1 directory, and automatically copy the necessary files to the ROS2 package.
To clear the previous build, run
Change the exported urdf
For exported urdf, we need to make several changes
# Author: Addison Sears-Collins
# Date: September 14, 2021
# Description: Launch a robot URDF file using Rviz.
# https://automaticaddison.com
import os
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.conditions import IfCondition, UnlessCondition
from launch.substitutions import Command, LaunchConfiguration
from launch_ros.actions import Node
from launch_ros.substitutions import FindPackageShare
def generate_launch_description():
# Set the path to this package.
pkg_share = FindPackageShare(package="humanoid_v1").find("humanoid_v1")
# Set the path to the RViz configuration settings
default_rviz_config_path = os.path.join(pkg_share, "rviz/rviz_basic_settings.rviz")
# Set the path to the URDF file
default_urdf_model_path = os.path.join(pkg_share, "urdf/robot.urdf.xacro")
########### YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE ##############
# Launch configuration variables specific to simulation
gui = LaunchConfiguration("gui")
urdf_model = LaunchConfiguration("urdf_model")
rviz_config_file = LaunchConfiguration("rviz_config_file")
use_robot_state_pub = LaunchConfiguration("use_robot_state_pub")
use_rviz = LaunchConfiguration("use_rviz")
use_sim_time = LaunchConfiguration("use_sim_time")
# Declare the launch arguments
declare_urdf_model_path_cmd = DeclareLaunchArgument(
name="urdf_model",
default_value=default_urdf_model_path,
description="Absolute path to robot urdf file")
declare_rviz_config_file_cmd = DeclareLaunchArgument(
name="rviz_config_file",
default_value=default_rviz_config_path,
description="Full path to the RVIZ config file to use")
declare_use_joint_state_publisher_cmd = DeclareLaunchArgument(
name="gui",
default_value="True",
description="Flag to enable joint_state_publisher_gui")
declare_use_robot_state_pub_cmd = DeclareLaunchArgument(
name="use_robot_state_pub",
default_value="True",
description="Whether to start the robot state publisher")
declare_use_rviz_cmd = DeclareLaunchArgument(
name="use_rviz",
default_value="True",
description="Whether to start RVIZ")
declare_use_sim_time_cmd = DeclareLaunchArgument(
name="use_sim_time",
default_value="True",
description="Use simulation (Gazebo) clock if true")
# Specify the actions
# Publish the joint state values for the non-fixed joints in the URDF file.
start_joint_state_publisher_cmd = Node(
condition=UnlessCondition(gui),
package="joint_state_publisher",
executable="joint_state_publisher",
name="joint_state_publisher")
# A GUI to manipulate the joint state values
start_joint_state_publisher_gui_node = Node(
condition=IfCondition(gui),
package="joint_state_publisher_gui",
executable="joint_state_publisher_gui",
name="joint_state_publisher_gui")
# Subscribe to the joint states of the robot, and publish the 3D pose of each link.
start_robot_state_publisher_cmd = Node(
condition=IfCondition(use_robot_state_pub),
package="robot_state_publisher",
executable="robot_state_publisher",
parameters=[{"use_sim_time": use_sim_time,
"robot_description": Command(["xacro ", urdf_model])}],
arguments=[default_urdf_model_path])
# Launch RViz
start_rviz_cmd = Node(
condition=IfCondition(use_rviz),
package="rviz2",
executable="rviz2",
name="rviz2",
output="screen",
arguments=["-d", rviz_config_file])
# Create the launch description and populate
ld = LaunchDescription()
# Declare the launch options
ld.add_action(declare_urdf_model_path_cmd)
ld.add_action(declare_rviz_config_file_cmd)
ld.add_action(declare_use_joint_state_publisher_cmd)
ld.add_action(declare_use_robot_state_pub_cmd)
ld.add_action(declare_use_rviz_cmd)
ld.add_action(declare_use_sim_time_cmd)
# Add any actions
ld.add_action(start_joint_state_publisher_cmd)
ld.add_action(start_joint_state_publisher_gui_node)
ld.add_action(start_robot_state_publisher_cmd)
ld.add_action(start_rviz_cmd)
return ld
<buildtool_depend>ament_cmake</buildtool_depend>
<!-- insert the following lines -->
<exec_depend>joint_state_publisher</exec_depend>
<exec_depend>robot_state_publisher</exec_depend>
<exec_depend>rviz</exec_depend>
<exec_depend>xacro</exec_depend>
<!-- end of insertion -->
<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
# find_package(<dependency> REQUIRED)
# insert the following lines
install(
DIRECTORY config launch maps meshes models params rviz src urdf worlds
DESTINATION share/${PROJECT_NAME}
)
# end of insertion
if(BUILD_TESTING)
make ros-build
[ERROR] [launch]: Caught exception in launch (see debug for traceback): "package 'joint_state_publisher_gui' not found, searching: ['/home/tk/Desktop/humanoid-urdf/install/humanoid_v1', '/opt/ros/humble']"