-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable ros2 service communication for vehicle control mode
- Loading branch information
1 parent
9c11577
commit a097671
Showing
5 changed files
with
79 additions
and
71 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using ROS2; | ||
using AWSIM; | ||
|
||
namespace AWSIM | ||
{ | ||
/// <summary> | ||
/// ros2 service communication about ControlModeCommand and switches the ControlMode of the Vehicle. | ||
/// i.e. "ros2 service call input/control_mode_request autoware_vehicle_msgs/srv/ControlModeCommand "mode: 1" | ||
/// </summary> | ||
public class ControlModeSrvServer : MonoBehaviour | ||
{ | ||
[SerializeField] string serviceName = "input/control_mode_request"; | ||
|
||
IService<autoware_vehicle_msgs.srv.ControlModeCommand_Request, autoware_vehicle_msgs.srv.ControlModeCommand_Response> service; | ||
|
||
[SerializeField] VehicleOverrideInputManager vehicleOverrideInputManager; | ||
|
||
public autoware_vehicle_msgs.srv.ControlModeCommand_Response ChangeControlMode(autoware_vehicle_msgs.srv.ControlModeCommand_Request request) | ||
{ | ||
autoware_vehicle_msgs.srv.ControlModeCommand_Response response = new autoware_vehicle_msgs.srv.ControlModeCommand_Response(); | ||
if (request.Mode == autoware_vehicle_msgs.srv.ControlModeCommand_Request.AUTONOMOUS) | ||
{ | ||
vehicleOverrideInputManager.ControlMode = VehicleControlMode.AUTONOMOUS; | ||
} | ||
// else if (request.Mode == autoware_vehicle_msgs.srv.ControlModeCommand_Request.AUTONOMOUS_STEER_ONLY) | ||
// { | ||
|
||
// } | ||
// else if (request.Mode == autoware_vehicle_msgs.srv.ControlModeCommand_Request.AUTONOMOUS_VELOCITY_ONLY) | ||
// { | ||
|
||
// } | ||
else if (request.Mode == autoware_vehicle_msgs.srv.ControlModeCommand_Request.MANUAL) | ||
{ | ||
vehicleOverrideInputManager.ControlMode = VehicleControlMode.MANUAL; | ||
} | ||
// else if (request.Mode == autoware_vehicle_msgs.srv.ControlModeCommand_Request.NO_COMMAND) | ||
// { | ||
|
||
// } | ||
|
||
response.Success = true; | ||
return response; | ||
} | ||
|
||
void Start() | ||
{ | ||
service = SimulatorROS2Node.CreateService<autoware_vehicle_msgs.srv.ControlModeCommand_Request, autoware_vehicle_msgs.srv.ControlModeCommand_Response> | ||
(serviceName, ChangeControlMode); | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...Scripts/Vehicles/EngageSubscriber.cs.meta → ...pts/Vehicles/ControlModeSrvServer.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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