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

Test gazebo scan #71

Merged
merged 7 commits into from
Oct 16, 2023
Merged
Changes from 1 commit
Commits
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
16 changes: 15 additions & 1 deletion rosbot_gazebo/test/simulation_test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.

import rclpy
import tf_transformations

from threading import Event
from threading import Thread
Expand All @@ -22,10 +23,11 @@

from geometry_msgs.msg import Twist
from nav_msgs.msg import Odometry
import tf_transformations
from sensor_msgs.msg import LaserScan


class SimulationTestNode(Node):
MINIMAL_LASER_SCAN_RANGE = 0.1
__test__ = False

def __init__(self, name="test_node"):
Expand All @@ -37,6 +39,7 @@ def __init__(self, name="test_node"):
self.goal_x_event = Event()
self.goal_y_event = Event()
self.goal_theta_event = Event()
self.scan_event = Event()

def set_and_publish_velocities(
self, goal_x_distance, goal_y_distance, goal_theta_angle
Expand All @@ -52,6 +55,11 @@ def create_test_subscribers_and_publishers(self):
self.odom_sub = self.create_subscription(
Odometry, "/odometry/filtered", self.odometry_callback, 10
)

self.scan_sub = self.create_subscription(
LaserScan, "/scan", self.scan_callback, 10
)

self.timer = None

def start_node_thread(self):
Expand Down Expand Up @@ -83,6 +91,12 @@ def odometry_callback(self, data: Odometry):
if yaw > self.goal_theta_angle:
self.goal_theta_event.set()

def scan_callback(self, data: LaserScan):
if min(data.ranges) < self.MINIMAL_LASER_SCAN_RANGE:
print(f"Ranges: {data.ranges}")
return
self.scan_event.set()
delihus marked this conversation as resolved.
Show resolved Hide resolved

def publish_cmd_vel_messages(self):
twist_msg = Twist()
twist_msg.linear.x = self.goal_x_distance
Expand Down