Skip to content

Commit fa6e766

Browse files
authored
Merge pull request #26 from mleegwt/sensors
Sensors
2 parents dbcb57c + a4d61cc commit fa6e766

File tree

8 files changed

+122
-67
lines changed

8 files changed

+122
-67
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#python 3
2+
import time
3+
import math
4+
import rclpy
5+
from rclpy.node import Node
6+
from geometry_msgs.msg import Twist
7+
from std_msgs.msg import Float64
8+
9+
class SimControlNode(Node):
10+
11+
def __init__(self):
12+
super().__init__('sim_control_node')
13+
self.cmd_sub = self.create_subscription(Twist, '/cmd_vel', self.props_callback, 10)
14+
self.left_pub = self.create_publisher(Float64, '/left', 10)
15+
self.right_pub = self.create_publisher(Float64, '/right', 10)
16+
17+
# Controls the propellors for the boat via duty cycle control.
18+
def props_callback(self, cmd_vel):
19+
# Converting twist message to differntial drive control, includes clipping
20+
# This is an electronic speed controller
21+
v = cmd_vel.linear.x # (m/s)
22+
w = cmd_vel.angular.z # (rad/s)
23+
24+
B = 0.3 # (m)
25+
K = 1 # To be determined!
26+
left = (v - w*B/2) / K
27+
right = (v + w*B/2) / K
28+
29+
self.left_pub.publish(Float64(data = left))
30+
self.right_pub.publish(Float64(data = right))
31+
32+
def main():
33+
rclpy.init()
34+
node = SimControlNode()
35+
rclpy.spin(node)
36+
node.destroy_node()
37+
rclpy.shutdown()
38+
39+
if __name__ == '__main__':
40+
main()
41+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from launch import LaunchDescription
2+
from launch_ros.actions import Node
3+
import launch_testing.actions
4+
5+
def generate_launch_description():
6+
nodes = [
7+
Node(
8+
package='boatcontrol',
9+
executable='simcontrol_node',
10+
name='simcontrol_node',
11+
output='screen',
12+
)
13+
]
14+
15+
return LaunchDescription(nodes + [
16+
launch_testing.actions.ReadyToTest()
17+
])

ros_ws/src/boatcontrol/setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
data_files=[
1010
('share/ament_index/resource_index/packages', ['resource/' + package_name]),
1111
('share/' + package_name + '/launch', ['launch/boatcontrol.launch.py']),
12+
('share/' + package_name + '/launch', ['launch/simcontrol.launch.py']),
1213
('share/' + package_name, ['package.xml']),
1314
],
1415
install_requires=['setuptools'],
@@ -20,7 +21,8 @@
2021
tests_require=['pytest'],
2122
entry_points={
2223
'console_scripts': [
23-
'boatcontrol_node = boatcontrol.boatcontrolnode:main'
24+
'boatcontrol_node = boatcontrol.boatcontrolnode:main',
25+
'simcontrol_node = boatcontrol.simcontrolnode:main'
2426
],
2527
},
2628
)

ros_ws/src/navigation/config/karaburan.xacro

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,6 @@
5353
<origin xyz="0 0 0" rpy="0 0 0" />
5454
<material name="black" />
5555
</visual>
56-
57-
<sensor name="imu_sensor" type="imu">
58-
<always_on>1</always_on>
59-
<update_rate>1</update_rate>
60-
<visualize>true</visualize>
61-
<topic>imu</topic>
62-
</sensor>
6356
</link>
6457

6558
<link name="gps_link">
@@ -72,7 +65,7 @@
7265
</visual>
7366
</link>
7467

75-
<link name="lidar">
68+
<link name="lidar_link">
7669
<visual>
7770
<geometry>
7871
<cylinder radius="0.05" length="0.05" />
@@ -87,34 +80,6 @@
8780
<origin xyz="0 0 0" rpy="0 0 0" />
8881
<material name="black" />
8982
</collision>
90-
91-
<sensor name="lidar" type="gpu_lidar">
92-
<always_on>true</always_on>
93-
<visualize>true</visualize>
94-
<update_rate>5</update_rate>
95-
<topic>scan</topic>
96-
<gz_frame_id>lidar_link</gz_frame_id>
97-
<lidar>
98-
<scan>
99-
<horizontal>
100-
<samples>360</samples>
101-
<resolution>1.000000</resolution>
102-
<min_angle>0.000000</min_angle>
103-
<max_angle>6.280000</max_angle>
104-
</horizontal>
105-
</scan>
106-
<range>
107-
<min>0.120000</min>
108-
<max>3.5</max>
109-
<resolution>0.015000</resolution>
110-
</range>
111-
<noise>
112-
<type>gaussian</type>
113-
<mean>0.0</mean>
114-
<stddev>0.01</stddev>
115-
</noise>
116-
</lidar>
117-
</sensor>
11883
</link>
11984

12085
<joint name="base_imu_joint" type="fixed">
@@ -147,7 +112,7 @@
147112

148113
<joint name="base_lidar_joint" type="fixed">
149114
<parent link="base_link" />
150-
<child link="lidar" />
115+
<child link="lidar_link" />
151116
<origin xyz="0 0 0.155" rpy="0 0 0" />
152117
</joint>
153118

ros_ws/src/navigation/config/karaburan_boat.sdf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
<gz_frame_id>lidar_link</gz_frame_id>
4949
<topic>/scan</topic>
5050
<update_rate>10</update_rate>
51-
<ray>
51+
<lidar>
5252
<scan>
5353
<horizontal>
5454
<samples>720</samples>
@@ -68,7 +68,7 @@
6868
<max>50.0</max>
6969
<resolution>0.01</resolution>
7070
</range>
71-
</ray>
71+
</lidar>
7272
<always_on>1</always_on>
7373
<visualize>true</visualize>
7474
</sensor>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
slam_toolbox:
2+
ros__parameters:
3+
use_sim_time: true
4+
5+
# Frames — laat SLAM de TF map->odom publiceren
6+
odom_frame: "odom"
7+
map_frame: "map"
8+
base_frame: "base_link"
9+
publish_tf: true
10+
tf_buffer_duration: 10.0
11+
12+
# Sensor
13+
scan_topic: "/scan" # <-- zet jouw topic hier
14+
use_imu_data: true # IMU yaw helpt bij water/reflecties
15+
imu_data_topic: "/imu/data" # als je een ander pad hebt, aanpassen
16+
17+
# Matcher / update-trigger (beetje ruim voor eerste test)
18+
minimum_travel_distance: 0.10
19+
minimum_travel_heading: 0.10 # rad ~ 6°
20+
transform_publish_period: 0.02 # 50 Hz TF is prima
21+
22+
# Kaart
23+
resolution: 0.05 # m/cel
24+
map_update_interval: 2.0 # s
25+
enable_interactive_mode: false
26+

ros_ws/src/navigation/launch/nav2_stack.launch.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from launch import LaunchDescription
2-
from launch.actions import DeclareLaunchArgument
2+
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription
3+
from launch.launch_description_sources import PythonLaunchDescriptionSource
34
from launch.substitutions import Command, PathJoinSubstitution, FindExecutable, LaunchConfiguration
45
from launch_ros.substitutions import FindPackageShare
56
from launch_ros.actions import Node, LifecycleNode
@@ -50,11 +51,18 @@ def generate_launch_description():
5051
'bt_navigator.yaml'
5152
)
5253
use_sim_time = LaunchConfiguration('use_sim_time')
54+
slam_file = os.path.join(
55+
get_package_share_directory('navigation'),
56+
'config',
57+
'slam_params_file.yaml'
58+
)
59+
60+
5361
nodes = [
5462
Node(
5563
package='robot_state_publisher',
5664
executable='robot_state_publisher',
57-
name='robot_state_publisher',
65+
name='karaburan_robot_state_publisher',
5866
parameters=[{'robot_description': robot_description,
5967
'publish_frequency': 1.0,
6068
'use_sim_time': use_sim_time }],
@@ -174,7 +182,17 @@ def generate_launch_description():
174182
]
175183

176184
return LaunchDescription(
177-
[ DeclareLaunchArgument('use_sim_time', default_value='true', description='Gebruik /clock (true) of systeemklok (false)') ] +
185+
[ DeclareLaunchArgument('use_sim_time', default_value='true', description='Gebruik /clock (true) of systeemklok (false)'),
186+
IncludeLaunchDescription(
187+
PythonLaunchDescriptionSource(PathJoinSubstitution([
188+
FindPackageShare("slam_toolbox"), "launch", "online_async_launch.py"
189+
])),
190+
launch_arguments={
191+
'use_sim_time': use_sim_time,
192+
'slam_params_file': slam_file
193+
}.items()
194+
)
195+
] +
178196
nodes + [
179197
launch_testing.actions.ReadyToTest()
180198
])

ros_ws/src/navigation/launch/sim.launch.py

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@
1818
import os
1919

2020
def generate_launch_description():
21+
boatcontrol_dir = get_package_share_directory('boatcontrol')
22+
boatcontrol = IncludeLaunchDescription(
23+
PythonLaunchDescriptionSource(
24+
os.path.join(boatcontrol_dir, 'launch', 'simcontrol.launch.py')
25+
)
26+
)
27+
2128
# --- Launch arguments ---
2229
xacro_file = LaunchConfiguration("xacro_file")
2330
world_sdf = LaunchConfiguration("world_sdf")
@@ -53,11 +60,6 @@ def generate_launch_description():
5360

5461
return LaunchDescription([
5562
# Paths / args
56-
DeclareLaunchArgument(
57-
"xacro_file",
58-
default_value="navigation/config/karaburan.xacro",
59-
description="Path to .urdf.xacro file"
60-
),
6163
DeclareLaunchArgument(
6264
"world_sdf",
6365
default_value="navigation/config/world.sdf",
@@ -76,9 +78,6 @@ def generate_launch_description():
7678
DeclareLaunchArgument("R", default_value="0.0"),
7779
DeclareLaunchArgument("P", default_value="0.0"),
7880
DeclareLaunchArgument("Y", default_value="0.0"),
79-
DeclareLaunchArgument(
80-
"xacro_args", default_value="",
81-
),
8281
# Launch args for the GZ - ROS2 bridge
8382
DeclareLaunchArgument('ns', default_value='', description='ROS namespace for the bridge'),
8483
DeclareLaunchArgument('imu_topic', default_value='/imu/data', description='GZ/ROS topic for IMU'),
@@ -99,21 +98,8 @@ def generate_launch_description():
9998
}.items()
10099
),
101100

102-
Node(
103-
package="robot_state_publisher",
104-
executable="robot_state_publisher",
105-
name="robot_state_publisher",
106-
output="screen",
107-
parameters=[{
108-
"use_sim_time": True,
109-
"robot_description": Command([
110-
FindExecutable(name="xacro"), " ",
111-
xacro_file, " ",
112-
xacro_args
113-
])
114-
}]
115-
),
116101
nav_launch,
102+
boatcontrol,
117103

118104
TimerAction(
119105
period=2.0,
@@ -140,8 +126,8 @@ def generate_launch_description():
140126
PythonExpression(['"', imu_topic, '" + \'@sensor_msgs/msg/Imu[gz.msgs.IMU\'']),
141127
PythonExpression(['"', gps_topic, '" + \'@sensor_msgs/msg/NavSatFix[gz.msgs.NavSat\'']),
142128
PythonExpression(['"', lidar_topic, '" + \'@sensor_msgs/msg/LaserScan[gz.msgs.LaserScan\'']),
143-
PythonExpression(['"', left_topic, '" + \'@std_msgs/msg/Float[gz.msgs.Float\'']),
144-
PythonExpression(['"', right_topic, '" + \'@std_msgs/msg/Float[gz.msgs.Float\'']),
129+
PythonExpression(['"', left_topic, '" + \'@std_msgs/msg/Float64[gz.msgs.Double\'']),
130+
PythonExpression(['"', right_topic, '" + \'@std_msgs/msg/Float64[gz.msgs.Double\'']),
145131
'/tf@tf2_msgs/msg/TFMessage@gz.msgs.Pose_V',
146132
'/clock@rosgraph_msgs/msg/Clock[gz.msgs.Clock'
147133
],

0 commit comments

Comments
 (0)