forked from AutomotiveAIChallenge/aichallenge-2024
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add control mode request adapter (#28)
Signed-off-by: Takagi, Isamu <[email protected]>
- Loading branch information
1 parent
3cb387d
commit 2a6a28f
Showing
3 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
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
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
35 changes: 35 additions & 0 deletions
35
...workspace/src/aichallenge_system/aichallenge_system_launch/script/control_mode_adapter.py
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 |
---|---|---|
@@ -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() |