Simple ros2-controll mock setup

This commit is contained in:
2024-09-25 01:43:15 +02:00
commit 98108f9e70
6 changed files with 200 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
.vscode/
build/
install/
log/

View File

@ -0,0 +1,31 @@
cmake_minimum_required(VERSION 3.8)
project(mg_wheel_interface)
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()
# find dependencies
find_package(ament_cmake REQUIRED)
# uncomment the following section in order to fill in
# further dependencies manually.
# find_package(<dependency> REQUIRED)
if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights
# comment the line when a copyright and license is added to all source files
set(ament_cmake_copyright_FOUND TRUE)
# the following line skips cpplint (only works in a git repo)
# comment the line when this package is in a git repo and when
# a copyright and license is added to all source files
set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
endif()
install(DIRECTORY
launch assets
DESTINATION share/${PROJECT_NAME}/
)
ament_package()

View File

@ -0,0 +1,70 @@
<?xml version="1.0"?>
<robot name="mg-robot">
<material name="red">
<color rgba="1 0 0 1" />
</material>
<material name="gray">
<color rgba="0.5 0.5 0.5 1" />
</material>
<link name="base-link">
<visual>
<geometry>
<box size="0.5 0.5 0.2" color="yellow"/>
</geometry>
<origin xyz="0 0 0.12" rpy="0 0 0" />
<material name="red" />
</visual>
</link>
<link name="left-wheel">
<visual>
<geometry>
<cylinder radius="0.1" length="0.05"/>
</geometry>
<origin xyz="0 0 0" rpy="1.57 0 0" />
<material name="gray" />
</visual>
</link>
<link name="right-wheel">
<visual>
<geometry>
<cylinder radius="0.1" length="0.05"/>
</geometry>
<origin xyz="0 0 0" rpy="1.57 0 0" />
<material name="gray" />
</visual>
</link>
<joint name="right_motor" type="continuous">
<parent link="base-link"/>
<child link="right-wheel"/>
<origin xyz="0 -0.25 0.1" rpy="0 0 3.141592" />
</joint>
<joint name="left_motor" type="continuous">
<parent link="base-link"/>
<child link="left-wheel"/>
<origin xyz="0 0.25 0.1" rpy="0 0 0" />
</joint>
<ros2_control name="mg-base" type="system">
<hardware>
<plugin>mock_components/GenericSystem</plugin>
<param name="calculate_dynamics">true</param>
</hardware>
<joint name="left_motor">
<command_interface name="velocity"/>
<state_interface name="position"/>
</joint>
<joint name="right_motor">
<command_interface name="velocity"/>
<state_interface name="position"/>
</joint>
</ros2_control>
</robot>

View File

@ -0,0 +1,20 @@
controller_manager:
ros__parameters:
update_rate: 100
diffdrive_controller:
type: diff_drive_controller/DiffDriveController
joint_state_publisher:
type: joint_state_broadcaster/JointStateBroadcaster
diffdrive_controller:
ros__parameters:
left_wheel_names: ["left_motor"]
right_wheel_names: ["right_motor"]
enable_odom_tf: true
odom_frame_id: odom
base_frame_id: base-link
wheel_separation: 0.5
wheel_radius: 0.1

View File

@ -0,0 +1,47 @@
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, RegisterEventHandler, TimerAction
from launch.event_handlers import OnProcessStart
from launch.substitutions import Command, FindExecutable, LaunchConfiguration, PathJoinSubstitution
from launch_ros.actions import Node
from launch_ros.substitutions import FindPackageShare
from pathlib import Path
def generate_launch_description():
basedir = FindPackageShare("mg_wheel_interface")
urdfDescription = PathJoinSubstitution([basedir, "assets/mg_base.urdf"])
yamlControllers = PathJoinSubstitution([basedir, "assets/mg_base_controllers.yaml"])
urdfDescription = Command([
"cat ",
urdfDescription
])
return LaunchDescription([
Node(
package='robot_state_publisher',
executable='robot_state_publisher',
output="screen",
parameters=[{"robot_description": urdfDescription}]
),
Node(
package="controller_manager",
executable="ros2_control_node",
parameters=[yamlControllers],
output="screen"
),
Node(
package='controller_manager',
executable='spawner',
output="screen",
arguments=["joint_state_publisher"]
),
Node(
package="controller_manager",
executable="spawner",
arguments=["diffdrive_controller", "--param-file", yamlControllers],
)
])

View File

@ -0,0 +1,28 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>mg_wheel_interface</name>
<version>0.0.1</version>
<description>Interacts with the wheels</description>
<maintainer email="pimpest@pimpest.com">pimpest</maintainer>
<license>Apache-2.0</license>
<buildtool_depend>ament_cmake</buildtool_depend>
<depend>pluginlib </depend>
<depend>hardware_interface</depend>
<depend>ros2launch</depend>
<depend>controller_manager</depend>
<depend>ros2_control</depend>
<depend>diff_drive_controller</depend>
<depend>robot_state_publisher</depend>
<depend>joint_state_broadcaster</depend>
<depend>rsl</depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
<export>
<build_type>ament_cmake</build_type>
</export>
</package>