Skip to content

Commit 8942e94

Browse files
committed
added 180 filter
1 parent a87179a commit 8942e94

File tree

10 files changed

+204
-31
lines changed

10 files changed

+204
-31
lines changed

go2_robot_sdk/config/mapper_params_online_async.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@ slam_toolbox:
1313
odom_frame: odom
1414
map_frame: map
1515
base_frame: base_link
16-
scan_topic: /scan
16+
scan_topic: /scan_filtered
1717
use_map_saver: true
1818
mode: mapping
1919

2020
# if you'd like to immediately start continuing a map at a given pose
2121
# or at the dock, but they are mutually exclusive, if pose is given
2222
# will use pose
23-
map_start_pose: [0.0, 0.0, 0.0]
24-
#map_start_at_dock: true
23+
#map_start_pose: [0.0, 0.0, 0.0]
24+
map_start_at_dock: true
2525

2626
debug_logging: false
2727
throttle_scans: 1
2828
transform_publish_period: 0.02 # if 0 never publishes odometry
2929
map_update_interval: 1.0
30-
resolution: 0.05
31-
max_laser_range: 5.0
30+
resolution: 0.07
31+
max_laser_range: 7.0
3232
minimum_time_interval: 0.5
3333
transform_timeout: 0.2
3434
tf_buffer_duration: 30.0

go2_robot_sdk/config/nav2_params_navigation.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ amcl:
1919
laser_model_type: "likelihood_field"
2020
max_beams: 90
2121
max_particles: 800
22-
min_particles: 200
22+
min_particles: 300
2323
odom_frame_id: "odom"
2424
pf_err: 0.05
2525
pf_z: 0.99
@@ -38,7 +38,7 @@ amcl:
3838
z_max: 0.05
3939
z_rand: 0.03
4040
z_short: 0.05
41-
scan_topic: "scan"
41+
scan_topic: "scan_filtered"
4242
# set_initial_pose: false
4343

4444
bt_navigator:
@@ -100,7 +100,7 @@ controller_server:
100100
# DWB parameters
101101
FollowPath:
102102
plugin: "dwb_core::DWBLocalPlanner"
103-
debug_trajectory_details: True
103+
#debug_trajectory_details: True
104104
min_vel_x: 0.0
105105
min_vel_y: 0.0
106106
max_vel_x: 2.0 #changed
@@ -168,7 +168,7 @@ local_costmap:
168168
mark_threshold: 1
169169
observation_sources: scan
170170
scan:
171-
topic: /scan
171+
topic: /scan_filtered
172172
max_obstacle_height: 2.0
173173
clearing: True
174174
marking: True
@@ -201,7 +201,7 @@ global_costmap:
201201
enabled: True
202202
observation_sources: scan
203203
scan:
204-
topic: /scan
204+
topic: /scan_filtered
205205
max_obstacle_height: 2.0
206206
clearing: True
207207
marking: True
@@ -333,7 +333,7 @@ collision_monitor:
333333
observation_sources: ["scan"]
334334
scan:
335335
type: "scan"
336-
topic: "scan"
336+
topic: "scan_filtered"
337337
min_height: 0.15
338338
max_height: 2.0
339339
enabled: True
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import rclpy
2+
from rclpy.node import Node
3+
from sensor_msgs.msg import LaserScan
4+
import math
5+
6+
7+
class ScanAngleFilter(Node):
8+
9+
def __init__(self):
10+
super().__init__('scan_angle_filter')
11+
12+
# keep rear 180° -> outside [-pi/2, +pi/2]
13+
self.front_min = -math.pi / 2
14+
self.front_max = math.pi / 2
15+
16+
self.sub = self.create_subscription(
17+
LaserScan,
18+
'/scan',
19+
self.scan_callback,
20+
10
21+
)
22+
23+
self.pub = self.create_publisher(
24+
LaserScan,
25+
'/scan_filtered',
26+
10
27+
)
28+
29+
def scan_callback(self, msg):
30+
31+
filtered = LaserScan()
32+
33+
# copy metadata
34+
filtered.header = msg.header
35+
filtered.angle_min = msg.angle_min
36+
filtered.angle_max = msg.angle_max
37+
filtered.angle_increment = msg.angle_increment
38+
filtered.time_increment = msg.time_increment
39+
filtered.scan_time = msg.scan_time
40+
filtered.range_min = msg.range_min
41+
filtered.range_max = msg.range_max
42+
43+
filtered.ranges = list(msg.ranges)
44+
filtered.intensities = list(msg.intensities)
45+
46+
for i in range(len(filtered.ranges)):
47+
48+
angle = msg.angle_min + i * msg.angle_increment
49+
50+
# mask the FRONT 180°
51+
if self.front_min <= angle <= self.front_max:
52+
filtered.ranges[i] = float('inf')
53+
54+
self.pub.publish(filtered)
55+
56+
57+
def main(args=None):
58+
rclpy.init(args=args)
59+
node = ScanAngleFilter()
60+
rclpy.spin(node)
61+
node.destroy_node()
62+
rclpy.shutdown()
63+
64+
65+
if __name__ == '__main__':
66+
main()

go2_robot_sdk/go2_robot_sdk/sequential_nav_test.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,14 @@ def send_goal(self, pose):
5757

5858
def run_sequence(self):
5959
i = 0
60-
for i in range (0,2):
61-
self.send_goal(self.make_pose(-1.61775, 17.2127, 1.70432)) #main entrance
60+
for i in range (0,3):
61+
self.send_goal(self.make_pose(-46.2362, 73.379, -1.29229)) #main entrance
6262
time.sleep(1.0)
63-
self.send_goal(self.make_pose(9.57915, 19.4981, -1.21812)) #front main entrance
63+
self.send_goal(self.make_pose(-51.2816, 68.0833, -3.08686)) #front main entrance
6464
time.sleep(1.0)
65-
self.send_goal(self.make_pose(-1.61775, 17.2127, 2.36622)) #main entrance
65+
self.send_goal(self.make_pose(-55.4247, 72.4208, 1.56608)) #main entrance
6666
time.sleep(1.0)
67-
self.send_goal(self.make_pose(2.27953, -1.53849, -1.41637)) #second hall
68-
time.sleep(1.0)
69-
self.send_goal(self.make_pose(12.5844, 1.70121, -1.21812)) #front second entrance
70-
time.sleep(1.0)
71-
self.send_goal(self.make_pose(2.27953, -1.53849, 2.36622)) #second hall
67+
self.send_goal(self.make_pose(-50.5007, 77.558, -0.357111)) #second hall
7268
time.sleep(1.0)
7369

7470

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/usr/bin/env python3
2+
3+
import serial
4+
import socket
5+
import threading
6+
import time
7+
from enum import IntFlag
8+
9+
10+
class Outputs(IntFlag):
11+
MAIN_LED = 0x08
12+
STATUS_LED = 0x02
13+
ALARM = 0x04
14+
15+
alarm_stop_event = threading.Event()
16+
17+
UDP_IP = "0.0.0.0"
18+
UDP_PORT = 5005
19+
20+
def send_command(ser, cmd_byte):
21+
ser.write(bytes([cmd_byte]))
22+
23+
def flash_led_alarm(ser, duration=5):
24+
end_time = time.time() + duration
25+
while time.time() < end_time:
26+
if alarm_stop_event.is_set(): # Stop immediately if event is set
27+
break
28+
send_command(ser, Outputs.MAIN_LED | Outputs.ALARM)
29+
time.sleep(0.5)
30+
if alarm_stop_event.is_set():
31+
break
32+
send_command(ser, 0x00)
33+
time.sleep(0.5)
34+
35+
send_command(ser, 0x00)
36+
alarm_stop_event.clear()
37+
38+
send_command(ser, 0x00)
39+
40+
def handle_command(ser, command):
41+
cmd_num = int(command)
42+
43+
if cmd_num == 0:
44+
alarm_stop_event.set() # Stop any running alarm
45+
send_command(ser, 0x00)
46+
47+
elif cmd_num == 1:
48+
threading.Thread(
49+
target=flash_led_alarm,
50+
args=(ser, 5),
51+
daemon=True
52+
).start()
53+
54+
elif cmd_num == 2:
55+
send_command(ser, Outputs.MAIN_LED)
56+
57+
def main():
58+
59+
ser = serial.Serial('/dev/ttyUSB1', 115200, timeout=1)
60+
61+
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
62+
sock.bind((UDP_IP, UDP_PORT))
63+
64+
print(f"Listening for UDP commands on port {UDP_PORT}")
65+
66+
try:
67+
68+
while True:
69+
70+
data, addr = sock.recvfrom(1024)
71+
message = data.decode().strip()
72+
send_command(ser, 0x02)
73+
74+
print(f"Received UDP from {addr}: {message}")
75+
76+
if message.startswith("cmd:"):
77+
cmd_value = message.split("cmd:", 1)[1]
78+
handle_command(ser, cmd_value)
79+
else:
80+
print("Ignored non-command message")
81+
82+
except KeyboardInterrupt:
83+
pass
84+
85+
finally:
86+
ser.close()
87+
sock.close()
88+
89+
if __name__ == "__main__":
90+
main()
91+

go2_robot_sdk/launch/2_mapping.launch.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# Minimal mapping launch file - optimized for SLAM with external 2D LiDAR
2-
# Usage: ros2 launch go2_robot_sdk mapping_minimal.launch.py
3-
41
import os
52
from ament_index_python.packages import get_package_share_directory
63
from launch import LaunchDescription
@@ -29,8 +26,6 @@ def generate_launch_description():
2926
'sllidar_launch': os.path.join(sllidar_package_dir, 'launch', 'sllidar_s3_launch.py'),
3027
}
3128

32-
print(f"Minimal mapping stack")
33-
3429
# Launch arguments
3530
use_sim_time = LaunchConfiguration('use_sim_time', default='false')
3631
with_slam = LaunchConfiguration('slam', default='true')
@@ -74,7 +69,7 @@ def generate_launch_description():
7469
package='tf2_ros',
7570
executable='static_transform_publisher',
7671
name='static_transform_publisher',
77-
arguments=['0.2', '0', '0.1', '0', '0', '0', 'base_link', 'laser'],
72+
arguments=['0.2', '0', '0.1', '3.1415926535', '0', '0', 'base_link', 'laser'],
7873
),
7974
]
8075

@@ -96,9 +91,18 @@ def generate_launch_description():
9691
}.items(),
9792
)
9893

94+
#LiDAR filter
95+
filterer_node = Node(
96+
package='go2_robot_sdk',
97+
executable='scan_angle_filter',
98+
name='scan_angle_filter',
99+
output='screen'
100+
)
101+
102+
99103
# Combine all components
100104
return LaunchDescription(
101105
launch_args +
102106
core_nodes +
103-
[lidar_launch, slam_launch] # Combine them in a list
107+
[lidar_launch, slam_launch, filterer_node]
104108
)

go2_robot_sdk/launch/navigation_bringup_launch.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def generate_launch_description():
7373
package='tf2_ros',
7474
executable='static_transform_publisher',
7575
name='base_to_laser_tf',
76-
arguments=['0.2', '0', '0.1', '0', '0', '0', 'base_link', 'laser'],
76+
arguments=['0.2', '0', '0.1', '3.1415926535', '0', '0', 'base_link', 'laser'],
7777
),
7878

7979
# Initial map to odom transform
@@ -125,10 +125,24 @@ def generate_launch_description():
125125
)
126126
]
127127
)
128+
#LiDAR filter
129+
filterer_node = Node(
130+
package='go2_robot_sdk',
131+
executable='scan_angle_filter',
132+
name='scan_angle_filter',
133+
output='screen'
134+
)#
135+
#alarm script
136+
alarm_node = Node(
137+
package='go2_robot_sdk',
138+
executable='wip_main',
139+
name='wip_main',
140+
output='screen'
141+
)
128142

129143
# Combine all components
130144
return LaunchDescription(
131145
launch_args +
132146
core_nodes +
133-
[lidar_launch, nav_launch, initial_pose_timer, controller_node]
147+
[lidar_launch, nav_launch, initial_pose_timer, controller_node, filterer_node, alarm_node]
134148
)

go2_robot_sdk/map/office.pgm

63.6 KB
Binary file not shown.

go2_robot_sdk/map/office.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
image: office.pgm
22
mode: trinary
3-
resolution: 0.050
4-
origin: [-6.633, -6.401, 0]
3+
resolution: 0.070
4+
origin: [-62.084, 63.224, 0]
55
negate: 0
66
occupied_thresh: 0.65
77
free_thresh: 0.196

go2_robot_sdk/setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
'initial_pose_pub = go2_robot_sdk.initial_pose_pub:main',
4242
'sequential_nav_test = go2_robot_sdk.sequential_nav_test:main',
4343
'nav_controller = go2_robot_sdk.nav_controller:main',
44+
'scan_angle_filter = go2_robot_sdk.scan_angle_filter:main',
45+
'wip_main = go2_robot_sdk.wip_main:main',
4446
],
4547
},
4648
)

0 commit comments

Comments
 (0)