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

feat: add control mode request adapter #28

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ find_package(ament_cmake_auto REQUIRED)
ament_auto_find_build_dependencies()

install(PROGRAMS
script/control_mode_adapter.py
script/object_marker.py
DESTINATION lib/${PROJECT_NAME}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<log message="This is aichallenge_system_launch."/>
<include file="$(find-pkg-share aichallenge_submit_launch)/launch/aichallenge_submit.launch.xml" />

<!-- Workaround because the simulator cannot use the service. -->
<node pkg="aichallenge_system_launch" exec="control_mode_adapter.py" output="screen"/>

<!-- RViz -->
<group>
<node pkg="rviz2" exec="rviz2" name="rviz2" output="screen" args="-d $(var rviz_config) -s $(find-pkg-share autoware_launch)/rviz/image/autoware.png"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env python3
import rclpy
import rclpy.node
from std_msgs.msg import Bool
from autoware_auto_vehicle_msgs.srv import ControlModeCommand

# Workaround because the simulator cannot use the service.
class ControlModeAdapterNode(rclpy.node.Node):
def __init__(self):
super().__init__("control_mode_adapter")
self.sub = self.create_service(ControlModeCommand, "/control/control_mode_request", self.callback)
self.pub = self.create_publisher(Bool, "/control/control_mode_request_topic", 1)

def callback(self, req, res):
msg = Bool()
if req.mode == ControlModeCommand.Request.AUTONOMOUS:
res.success = True
msg.data = True
self.pub.publish(msg)
return res
if req.mode == ControlModeCommand.Request.MANUAL:
res.success = True
msg.data = False
self.pub.publish(msg)
return res
res.success = False
return res

def main(args=None):
rclpy.init(args=args)
rclpy.spin(ControlModeAdapterNode())
rclpy.shutdown()

if __name__ == "__main__":
main()