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

Create a demo that uses transmissions #226

Merged
merged 27 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ad7928c
add copy for transmission demo and set in the urdf
Noel215 Jan 18, 2023
75b7d9b
Renamed to rrbot_transmissions
jordan-palacios Jan 19, 2023
d92c9a0
Changed reduction value of transmission2
jordan-palacios Jan 19, 2023
305f287
Added the rrbot_transmissions_system_position_only
jordan-palacios Jan 19, 2023
e6a795e
Moved logger into its own variable
jordan-palacios Jan 19, 2023
e0b3c4d
Uncrustify
jordan-palacios Jan 19, 2023
73ed52e
Renamed hw interface to joint. Added actuator interfaces
jordan-palacios Jan 19, 2023
d2f0048
Formatting. Remove comments
jordan-palacios Jan 19, 2023
1296d2c
Using transmissions for joint and actuator interfaces
jordan-palacios Jan 20, 2023
6b30b7e
Propagating data between all the interfaces
jordan-palacios Jan 20, 2023
2d7fe62
Cleanup. Added some consts
jordan-palacios Jan 20, 2023
311f60d
Simulate motor motion
jordan-palacios Jan 23, 2023
70d74d8
Added logging to periodically show interface data
jordan-palacios Jan 24, 2023
2f095cb
Refactored the parameters a bit. Removed unused ones
jordan-palacios Jan 24, 2023
42cfca8
Added try/catches where needed
jordan-palacios Jan 24, 2023
1cd2fb0
Added transmission demo to README
jordan-palacios Jan 24, 2023
3c469c7
Use clang-format instead
jordan-palacios Jan 25, 2023
648fd09
rename transmissions ros2_control macro
Noel215 Jan 25, 2023
9bd8017
Remove unnecessary actuator parameters
jordan-palacios Jan 26, 2023
8afa076
Typo
jordan-palacios Feb 2, 2023
90fec58
Removed gazebo, mock hardware and fake sensors from the transmission
jordan-palacios Feb 2, 2023
af5d961
Missing 'explicit' from constructor
jordan-palacios Feb 2, 2023
727b079
Further cleanup of gazebo, mock hardware and fake sensors from the tr…
jordan-palacios Feb 3, 2023
e769649
branding fix
bmagyar Feb 15, 2023
79b8272
Remove pointer definitions
jordan-palacios Feb 15, 2023
0b00f35
Fixed comment about reserve
jordan-palacios Feb 15, 2023
4e98b53
Renamed member variable and added description
jordan-palacios Feb 15, 2023
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
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,30 @@ Available controllers:
Commanding the robot: see the commands below.


### Example 6: "Industrial Robots with an exposed transmission interface"

Files:
- Launch file: [rrbot_transmissions_system_position_only.launch.py](ros2_control_demo_bringup/launch/rrbot_transmissions_system_position_only.launch.py)
- Controllers yaml: [rrbot_controllers.yaml](ros2_control_demo_bringup/config/rrbot_controllers.yaml)
- URDF: [rrbot_transmissions_system_position_only.urdf.xacro](ros2_control_demo_description/rrbot_description/urdf/rrbot_transmissions_system_position_only.urdf.xacro)
- `ros2_control` URDF tag: [rrbot_transmissions_system_position_only.ros2_control.xacro](ros2_control_demo_description/rrbot_description/ros2_control/rrbot_transmissions_system_position_only.ros2_control.xacro)

Interfaces:
- Command interfaces:
- joint1/position
- joint2/position
- State interfaces:
- joint1/position
- joint2/position

Available controllers:
- `joint_state_broadcaster[joint_state_broadcaster/JointStateBroadcaster]`
- `forward_position_controller[forward_command_controller/ForwardCommandController]` (position)

Moving the robot:
- see below description of `forward_position_controller`
jordan-palacios marked this conversation as resolved.
Show resolved Hide resolved


## Controllers and moving hardware

To move the robot you should load and start controllers.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Copyright 2021 Stogl Robotics Consulting UG (haftungsbeschränkt)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import LaunchConfiguration, ThisLaunchFileDir


def generate_launch_description():
# Declare arguments
declared_arguments = []
declared_arguments.append(
DeclareLaunchArgument(
"prefix",
default_value='""',
description="Prefix of the joint names, useful for \
multi-robot setup. If changed than also joint names in the controllers' configuration \
have to be updated.",
)
)
declared_arguments.append(
DeclareLaunchArgument(
"slowdown", default_value="50.0", description="Slowdown factor of the RRbot."
)
)
declared_arguments.append(
DeclareLaunchArgument(
"robot_controller",
default_value="forward_position_controller",
description="Robot controller to start.",
)
)
declared_arguments.append(
DeclareLaunchArgument(
"start_rviz",
default_value="true",
description="Start RViz2 automatically with this launch file.",
)
)

# Initialize Arguments
prefix = LaunchConfiguration("prefix")
slowdown = LaunchConfiguration("slowdown")
robot_controller = LaunchConfiguration("robot_controller")
start_rviz = LaunchConfiguration("start_rviz")

base_launch = IncludeLaunchDescription(
PythonLaunchDescriptionSource([ThisLaunchFileDir(), "/rrbot_base.launch.py"]),
launch_arguments={
"description_file": "rrbot_transmissions_system_position_only.urdf.xacro",
"prefix": prefix,
"slowdown": slowdown,
"robot_controller": robot_controller,
"start_rviz": start_rviz,
}.items(),
)

return LaunchDescription(declared_arguments + [base_launch])
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0"?>
<robot xmlns:xacro="http://www.ros.org/wiki/xacro">

<xacro:macro name="rrbot_transmissions_system_position_only" params="name prefix use_gazebo:=^|false use_fake_hardware:=^|true mock_sensor_commands:=^|false slowdown:=2.0">
Copy link
Contributor

Choose a reason for hiding this comment

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

we can further simplify this by deleting use_gazebo, use_fake_hardware, mock_sensor_comands here

Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately this breaks the launch, since we use rrbot_base.launch.py as base. Maybe something that could be addressed in #231.

Copy link
Contributor

Choose a reason for hiding this comment

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

does it? removing them here and lines 34+35 in rrbot_transmissions_system_position_only.urdf.xacro works for me.

Copy link
Member

Choose a reason for hiding this comment

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

in the interest of merging this prior to the restructure, I'll open a general cleanup issue for xacro parameters

#240


<ros2_control name="${name}" type="system">

<hardware>
<plugin>ros2_control_demo_hardware/RRBotTransmissionsSystemPositionOnlyHardware</plugin>
<param name="actuator_slowdown">${slowdown}</param>
</hardware>

<joint name="${prefix}joint1">
<command_interface name="position">
<param name="min">-1</param>
<param name="max">1</param>
</command_interface>
<state_interface name="position"/>
</joint>

<joint name="${prefix}joint2">
<command_interface name="position">
<param name="min">-1</param>
<param name="max">1</param>
</command_interface>
<state_interface name="position"/>
</joint>

<transmission name="transmission1">
<plugin>transmission_interface/SimpleTransmission</plugin>
<actuator name="actuator1" role="actuator1"/>
<joint name="joint1" role="joint1">
<mechanical_reduction>2.0</mechanical_reduction>
<offset>0.0</offset>
</joint>
</transmission>

<transmission name="transmission2">
<plugin>transmission_interface/SimpleTransmission</plugin>
<actuator name="actuator2" role="actuator2"/>
<joint name="joint2" role="joint2">
<mechanical_reduction>4.0</mechanical_reduction>
<offset>0.0</offset>
</joint>
</transmission>
</ros2_control>

</xacro:macro>

</robot>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0"?>
<!-- Revolute-Revolute Manipulator -->
<!--
Copied and modified from ROS1 example -
https://github.com/ros-simulation/gazebo_ros_demos/blob/kinetic-devel/rrbot_description/urdf/rrbot.xacro
-->
<robot xmlns:xacro="http://www.ros.org/wiki/xacro" name="2dof_robot">

<!-- Enable setting arguments from the launch file -->
<xacro:arg name="prefix" default="" />
<xacro:arg name="slowdown" default="100.0" />

<!-- Import RRBot macro -->
<xacro:include filename="$(find rrbot_description)/urdf/rrbot_description.urdf.xacro" />

<!-- Import Rviz colors -->
<xacro:include filename="$(find rrbot_description)/gazebo/rrbot.materials.xacro" />

<!-- Import RRBot ros2_control description -->
<xacro:include filename="$(find rrbot_description)/ros2_control/rrbot_transmissions_system_position_only.ros2_control.xacro" />

<!-- Used for fixing robot -->
<link name="world"/>
<gazebo reference="world">
<static>true</static>
</gazebo>

<xacro:rrbot parent="world" prefix="$(arg prefix)">
<origin xyz="0 0 0" rpy="0 0 0" />
</xacro:rrbot>

<xacro:rrbot_transmissions_system_position_only
name="RRBotTransmissionsSystemPositionOnly" prefix="$(arg prefix)"
use_fake_hardware="$(arg use_fake_hardware)"
mock_sensor_commands="$(arg mock_sensor_commands)"
slowdown="$(arg slowdown)" />

</robot>
6 changes: 5 additions & 1 deletion ros2_control_demo_hardware/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ find_package(hardware_interface REQUIRED)
find_package(pluginlib REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_lifecycle REQUIRED)
find_package(transmission_interface REQUIRED)


## COMPILE
Expand All @@ -26,6 +27,7 @@ add_library(
src/rrbot_system_position_only.cpp
src/rrbot_system_multi_interface.cpp
src/rrbot_system_with_sensor.cpp
src/rrbot_transmissions_system_position_only.cpp
src/rrbot_actuator.cpp
src/external_rrbot_force_torque_sensor.cpp
)
Expand All @@ -40,13 +42,14 @@ ament_target_dependencies(
pluginlib
rclcpp
rclcpp_lifecycle
transmission_interface
)

# Causes the visibility macros to use dllexport rather than dllimport,
# which is appropriate when building the dll but not consuming it.
target_compile_definitions(${PROJECT_NAME} PRIVATE "ROS2_CONTROL_DEMO_HARDWARE_BUILDING_DLL")

# Export hardware pligins
# Export hardware plugins
pluginlib_export_plugin_description_file(hardware_interface ros2_control_demo_hardware.xml)

# INSTALL
Expand Down Expand Up @@ -75,5 +78,6 @@ ament_export_dependencies(
pluginlib
rclcpp
rclcpp_lifecycle
transmission_interface
)
ament_package()
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// Copyright 2020 ros2_control Development Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef ROS2_CONTROL_DEMO_HARDWARE__RRBOT_TRANSMISSIONS_SYSTEM_POSITION_ONLY_HPP_
#define ROS2_CONTROL_DEMO_HARDWARE__RRBOT_TRANSMISSIONS_SYSTEM_POSITION_ONLY_HPP_

#include <map>
#include <memory>
#include <string>
#include <vector>

#include "hardware_interface/handle.hpp"
#include "hardware_interface/hardware_info.hpp"
#include "hardware_interface/system_interface.hpp"
#include "hardware_interface/types/hardware_interface_return_values.hpp"
#include "rclcpp/clock.hpp"
#include "rclcpp/logger.hpp"
#include "rclcpp/macros.hpp"
#include "rclcpp_lifecycle/state.hpp"
#include "ros2_control_demo_hardware/visibility_control.h"
#include "transmission_interface/transmission.hpp"

namespace ros2_control_demo_hardware
{
class RRBotTransmissionsSystemPositionOnlyHardware : public hardware_interface::SystemInterface
{
public:
RCLCPP_SHARED_PTR_DEFINITIONS(RRBotTransmissionsSystemPositionOnlyHardware);
jordan-palacios marked this conversation as resolved.
Show resolved Hide resolved

ROS2_CONTROL_DEMO_HARDWARE_PUBLIC
hardware_interface::CallbackReturn on_init(
const hardware_interface::HardwareInfo & info) override;

ROS2_CONTROL_DEMO_HARDWARE_PUBLIC
hardware_interface::CallbackReturn on_configure(
const rclcpp_lifecycle::State & previous_state) override;

ROS2_CONTROL_DEMO_HARDWARE_PUBLIC
std::vector<hardware_interface::StateInterface> export_state_interfaces() override;

ROS2_CONTROL_DEMO_HARDWARE_PUBLIC
std::vector<hardware_interface::CommandInterface> export_command_interfaces() override;

ROS2_CONTROL_DEMO_HARDWARE_PUBLIC
hardware_interface::CallbackReturn on_activate(
const rclcpp_lifecycle::State & previous_state) override;

ROS2_CONTROL_DEMO_HARDWARE_PUBLIC
hardware_interface::CallbackReturn on_deactivate(
const rclcpp_lifecycle::State & previous_state) override;

ROS2_CONTROL_DEMO_HARDWARE_PUBLIC
hardware_interface::return_type read(
const rclcpp::Time & time, const rclcpp::Duration & period) override;

ROS2_CONTROL_DEMO_HARDWARE_PUBLIC
hardware_interface::return_type write(
const rclcpp::Time & time, const rclcpp::Duration & period) override;

private:
std::unique_ptr<rclcpp::Logger> logger_;
std::unique_ptr<rclcpp::Clock> clock_;

// parameters for the RRBot simulation
double actuator_slowdown_;

// transmissions
std::vector<std::shared_ptr<transmission_interface::Transmission>> transmissions_;

struct InterfaceData
{
explicit InterfaceData(const std::string & name);

std::string name_;
double command_;
double state_;
double transmission_;
Copy link
Member

Choose a reason for hiding this comment

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

This name is quite confusing. Could you rename this variable please to clarify it's meaning/content?
What does it mean in the joint and in the actuator context?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's the sink of the Joint/Actuator handle that lives inside the transmission. transmission_passthrough_ maybe?

Copy link
Member

Choose a reason for hiding this comment

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

If you rename plus add this comment about the sink we are done ;)

};
std::vector<InterfaceData> joint_interfaces_;
std::vector<InterfaceData> actuator_interfaces_;
};

} // namespace ros2_control_demo_hardware

#endif // ROS2_CONTROL_DEMO_HARDWARE__RRBOT_TRANSMISSIONS_SYSTEM_POSITION_ONLY_HPP_
1 change: 1 addition & 0 deletions ros2_control_demo_hardware/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<depend>pluginlib</depend>
<depend>rclcpp</depend>
<depend>rclcpp_lifecycle</depend>
<depend>transmission_interface</depend>

<test_depend>ament_cmake_gtest</test_depend>

Expand Down
7 changes: 7 additions & 0 deletions ros2_control_demo_hardware/ros2_control_demo_hardware.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,11 @@
The ros2_control RRBot example using external Force Torque Sensor where it is separate from the RRBot.
</description>
</class>
<class name="ros2_control_demo_hardware/RRBotTransmissionsSystemPositionOnlyHardware"
type="ros2_control_demo_hardware::RRBotTransmissionsSystemPositionOnlyHardware"
base_class_type="hardware_interface::SystemInterface">
<description>
The ROS2 Control minimal robot protocol with transmissions.
bmagyar marked this conversation as resolved.
Show resolved Hide resolved
</description>
</class>
</library>
Loading