-
Notifications
You must be signed in to change notification settings - Fork 29
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
Ros2 navigator utils remote control #1195
Open
Jorge-R08
wants to merge
2
commits into
master
Choose a base branch
from
ros2_navigator_utils_remote_control
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
52 changes: 36 additions & 16 deletions
52
NaviGator/utils/remote_control/navigator_emergency_control/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,39 @@ | ||
cmake_minimum_required(VERSION 3.0.2) | ||
cmake_minimum_required(VERSION 3.5) | ||
project(navigator_emergency_controller) | ||
|
||
find_package(catkin REQUIRED COMPONENTS | ||
roscpp | ||
std_msgs | ||
geometry_msgs | ||
navigator_msg_multiplexer | ||
nav_msgs | ||
) | ||
set(CMAKE_CXX_STANDARD 14) | ||
|
||
catkin_package( | ||
CATKIN_DEPENDS | ||
std_msgs | ||
nav_msgs | ||
geometry_msgs | ||
roscpp | ||
navigator_msg_multiplexer | ||
) | ||
if(NOT CMAKE_CXX_STANDARD) | ||
set(CMAKE_CXX_STANDARD 14) | ||
endif() | ||
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") | ||
add_compile_options(-Wall -Wextra -Wpedantic) | ||
endif() | ||
|
||
|
||
# find_package(catkin REQUIRED COMPONENTS | ||
# roscpp | ||
# std_msgs | ||
# geometry_msgs | ||
# navigator_msg_multiplexer | ||
# nav_msgs | ||
# ) | ||
|
||
find_package(ament_cmake REQUIRED) | ||
find_package(roscpp REQUIRED) | ||
find_package(geometry_msgs REQUIRED) | ||
find_package(navigator_msg_multiplexer REQUIRED) | ||
find_package(nav_msgs REQUIRED) | ||
find_package(std_msgs REQUIRED) | ||
|
||
# catkin_package( | ||
# CATKIN_DEPENDS | ||
# std_msgs | ||
# nav_msgs | ||
# geometry_msgs | ||
# roscpp | ||
# navigator_msg_multiplexer | ||
# ) | ||
|
||
ament_export_dependencies(std_msgs nav_msgs geometry_msgs roscpp navigator_msg_multiplexer) | ||
ament_package() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
#!/usr/bin/env python3 | ||
import rospy | ||
import sys | ||
|
||
import rclpy | ||
from remote_control_lib import RemoteControl | ||
from sensor_msgs.msg import Joy | ||
|
||
|
@@ -32,11 +34,17 @@ class Joystick: | |
""" | ||
|
||
def __init__(self): | ||
self.force_scale = rospy.get_param("/joystick_wrench/force_scale", 600) | ||
self.torque_scale = rospy.get_param("/joystick_wrench/torque_scale", 500) | ||
self.force_scale = node.declare_parameter( | ||
"/joystick_wrench/force_scale", | ||
600, | ||
).value | ||
self.torque_scale = node.declare_parameter( | ||
"/joystick_wrench/torque_scale", | ||
500, | ||
).value | ||
|
||
self.remote = RemoteControl("emergency", "/wrench/emergency") | ||
rospy.Subscriber("joy_emergency", Joy, self.joy_recieved) | ||
node.create_subscription("joy_emergency", Joy, rclpy.qos.QoSProfile()) | ||
|
||
self.active = False | ||
self.reset() | ||
|
@@ -80,15 +88,15 @@ def check_for_timeout(self, joy: Joy): | |
# No change in state | ||
# The controller times out after 15 minutes | ||
if ( | ||
rospy.Time.now() - self.last_joy.header.stamp > rospy.Duration(15 * 60) | ||
rclpy.Time.now() - self.last_joy.header.stamp > rclpy.Duration(15 * 60) | ||
and self.active | ||
): | ||
rospy.logwarn("Controller Timed out. Hold start to resume.") | ||
node.get_logger().warn("Controller Timed out. Hold start to resume.") | ||
self.reset() | ||
|
||
else: | ||
joy.header.stamp = ( | ||
rospy.Time.now() | ||
rclpy.Time.now() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same |
||
) # In the sim, stamps weren't working right | ||
self.last_joy = joy | ||
|
||
|
@@ -102,7 +110,7 @@ def joy_recieved(self, joy: Joy) -> None: | |
Args: | ||
joy (Joy): The Joy message. | ||
""" | ||
self.last_time = rospy.Time.now() | ||
self.last_time = rclpy.Time.now() | ||
self.check_for_timeout(joy) | ||
|
||
# Assigns readable names to the buttons that are used | ||
|
@@ -116,14 +124,14 @@ def joy_recieved(self, joy: Joy) -> None: | |
thruster_deploy = bool(joy.buttons[5]) | ||
|
||
if go_inactive and not self.last_go_inactive: | ||
rospy.loginfo("Go inactive pressed. Going inactive") | ||
node.get_logger().info("Go inactive pressed. Going inactive") | ||
self.reset() | ||
return | ||
|
||
# Reset controller state if only start is pressed down about 1 seconds | ||
self.start_count += start | ||
if self.start_count > 5: | ||
rospy.loginfo("Resetting controller state") | ||
node.get_logger().info("Resetting controller state") | ||
self.reset() | ||
self.active = True | ||
|
||
|
@@ -170,19 +178,20 @@ def joy_recieved(self, joy: Joy) -> None: | |
rotation = joy.axes[3] * self.torque_scale | ||
self.remote.publish_wrench(x, y, rotation, joy.header.stamp) | ||
|
||
def die_check(self, _: rospy.timer.TimerEvent) -> None: | ||
def die_check(self, _: rclpy.timer.TimerEvent) -> None: | ||
""" | ||
Publishes zeros after 2 seconds of no update in case node dies. | ||
""" | ||
# No new instructions after 2 seconds | ||
if self.active and rospy.Time.now() - self.last_time > rospy.Duration(2): | ||
if self.active and rclpy.Time.now() - self.last_time > rclpy.Duration(2): | ||
# Zero the wrench, reset | ||
self.reset() | ||
|
||
|
||
if __name__ == "__main__": | ||
rospy.init_node("emergency") | ||
rclpy.init(args=sys.argv) | ||
node = rclpy.create_node("emergency") | ||
|
||
emergency = Joystick() | ||
rospy.Timer(rospy.Duration(1), emergency.die_check, oneshot=False) | ||
rospy.spin() | ||
rclpy.Timer(rclpy.Duration(1), emergency.die_check, oneshot=False) | ||
rclpy.spin() |
27 changes: 13 additions & 14 deletions
27
NaviGator/utils/remote_control/navigator_emergency_control/package.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,20 @@ | ||
<?xml version="1.0"?> | ||
<package> | ||
<package format="3"> | ||
<name>navigator_emergency_controller</name> | ||
<version>4.0.0</version> | ||
<description>A server that controls navigator in response to the /joy_emergency node</description> | ||
<maintainer email="[email protected]">David Zobel</maintainer> | ||
<license>MIT</license> | ||
<buildtool_depend>catkin</buildtool_depend> | ||
<build_depend>geometry_msgs</build_depend> | ||
<build_depend>message_runtime</build_depend> | ||
<build_depend>nav_msgs</build_depend> | ||
<build_depend>navigator_msg_multiplexer</build_depend> | ||
<build_depend>roscpp</build_depend> | ||
<build_depend>std_msgs</build_depend> | ||
<run_depend>roscpp</run_depend> | ||
<run_depend>std_msgs</run_depend> | ||
<run_depend>geometry_msgs</run_depend> | ||
<run_depend>message_runtime</run_depend> | ||
<run_depend>navigator_msg_multiplexer</run_depend> | ||
<run_depend>nav_msgs</run_depend> | ||
|
||
<buildtool_depend>ament_cmake</buildtool_depend> | ||
<depend>geometry_msgs</depend> | ||
<depend>message_runtime</depend> | ||
<depend>nav_msgs</depend> | ||
<depend>navigator_msg_multiplexer</depend> | ||
<depend>roscpp</depend> | ||
<depend>std_msgs</depend> | ||
|
||
<export> | ||
<build_type>ament_cmake</build_type> | ||
</export> | ||
</package> |
54 changes: 37 additions & 17 deletions
54
NaviGator/utils/remote_control/navigator_joystick_control/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,39 @@ | ||
cmake_minimum_required(VERSION 3.0.2) | ||
project(navigator_joystick_control) | ||
cmake_minimum_required(VERSION 3.5) | ||
project(navigator_emergency_controller) | ||
|
||
find_package(catkin REQUIRED COMPONENTS | ||
roscpp | ||
std_msgs | ||
geometry_msgs | ||
navigator_msg_multiplexer | ||
nav_msgs | ||
) | ||
set(CMAKE_CXX_STANDARD 14) | ||
|
||
catkin_package( | ||
CATKIN_DEPENDS | ||
std_msgs | ||
nav_msgs | ||
geometry_msgs | ||
roscpp | ||
navigator_msg_multiplexer | ||
) | ||
if(NOT CMAKE_CXX_STANDARD) | ||
set(CMAKE_CXX_STANDARD 14) | ||
endif() | ||
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") | ||
add_compile_options(-Wall -Wextra -Wpedantic) | ||
endif() | ||
|
||
|
||
# find_package(catkin REQUIRED COMPONENTS | ||
# roscpp | ||
# std_msgs | ||
# geometry_msgs | ||
# navigator_msg_multiplexer | ||
# nav_msgs | ||
# ) | ||
|
||
find_package(ament_cmake REQUIRED) | ||
find_package(roscpp REQUIRED) | ||
find_package(geometry_msgs REQUIRED) | ||
find_package(navigator_msg_multiplexer REQUIRED) | ||
find_package(nav_msgs REQUIRED) | ||
find_package(std_msgs REQUIRED) | ||
|
||
# catkin_package( | ||
# CATKIN_DEPENDS | ||
# std_msgs | ||
# nav_msgs | ||
# geometry_msgs | ||
# roscpp | ||
# navigator_msg_multiplexer | ||
# ) | ||
|
||
ament_export_dependencies(std_msgs nav_msgs geometry_msgs roscpp navigator_msg_multiplexer) | ||
ament_package() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 16 additions & 15 deletions
31
NaviGator/utils/remote_control/navigator_joystick_control/package.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,23 @@ | ||
<?xml version="1.0"?> | ||
<package> | ||
<package format="3"> | ||
<name>navigator_joystick_control</name> | ||
<version>4.0.0</version> | ||
<description>A server that controls navigator in response to the /Joy node</description> | ||
<maintainer email="[email protected]">Anthony Olive</maintainer> | ||
<license>MIT</license> | ||
<buildtool_depend>catkin</buildtool_depend> | ||
<build_depend>geometry_msgs</build_depend> | ||
<build_depend>message_runtime</build_depend> | ||
<build_depend>nav_msgs</build_depend> | ||
<build_depend>navigator_msg_multiplexer</build_depend> | ||
<build_depend>roscpp</build_depend> | ||
<build_depend>std_msgs</build_depend> | ||
<run_depend>roscpp</run_depend> | ||
<run_depend>std_msgs</run_depend> | ||
<run_depend>geometry_msgs</run_depend> | ||
<run_depend>message_runtime</run_depend> | ||
<run_depend>navigator_msg_multiplexer</run_depend> | ||
<run_depend>nav_msgs</run_depend> | ||
<run_depend>ros_alarms</run_depend> | ||
|
||
<buildtool_depend>ament_cmake</buildtool_depend> | ||
<depend>geometry_msgs</depend> | ||
<depend>message_runtime</depend> | ||
<depend>nav_msgs</depend> | ||
<depend>navigator_msg_multiplexer</depend> | ||
<depend>roscpp</depend> | ||
<depend>std_msgs</depend> | ||
|
||
<build_export_depend>ros_alarms</build_export_depend> | ||
<exec_depend>ros_alarms</exec_depend> | ||
|
||
<export> | ||
<build_type>ament_cmake</build_type> | ||
</export> | ||
</package> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rclpy.Time.now()
is not allowed in ROS 2