Carma-platform v4.2.0
CARMA Platform is built on robot operating system (ROS) and utilizes open source software (OSS) that enables Cooperative Driving Automation (CDA) features to allow Automated Driving Systems to interact and cooperate with infrastructure and other vehicles through communication.
port_drayage_worker.hpp
Go to the documentation of this file.
1#pragma once
2
3/*
4 * Copyright (C) 2020-2022 LEIDOS.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
7 * use this file except in compliance with the License. You may obtain a copy of
8 * the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15 * License for the specific language governing permissions and limitations under
16 * the License.
17 */
18
19#include <rclcpp/rclcpp.hpp>
20#include <functional>
21#include <carma_v2x_msgs/msg/mobility_operation.hpp>
22#include <carma_planning_msgs/msg/guidance_state.hpp>
23#include <carma_planning_msgs/msg/route_event.hpp>
24#include <carma_planning_msgs/srv/set_active_route.hpp>
25#include <carma_msgs/msg/ui_instructions.hpp>
26#include <geometry_msgs/msg/twist_stamped.hpp>
27#include <geometry_msgs/msg/pose_stamped.hpp>
28#include "std_msgs/msg/string.hpp"
30
31#include <lanelet2_extension/projection/local_frame_projector.h>
32#include <boost/optional.hpp>
33#include <boost/property_tree/ptree.hpp>
34#include <boost/property_tree/json_parser.hpp>
35
36namespace port_drayage_plugin
37{
43 {
44 boost::optional<std::string> cargo_id;
45 std::string operation = "";
46 boost::optional<std::string> current_action_id; // Identifier for the action this message is related to
47 boost::optional<double> dest_longitude; // Destination longitude for the carma vehicle
48 boost::optional<double> dest_latitude; // Destination latitude for the carma vehicle
49 boost::optional<double> start_longitude; // Starting longitude of the carma vehicle
50 boost::optional<double> start_latitude; // Starting latitude of the carma vehicle
51 };
52
57 {
58 double latitude = 0.0;
59 double longitude = 0.0;
60 };
61
67 {
68 public:
72 enum Operation {
82 };
83
89 operation_enum_(op) {};
90
96
101 std::string operationToString() const;
102
106 friend std::ostream& operator<<(std::ostream& output, const OperationID& oid){
107 return output << oid.operationToString();
108 }
109
113 friend bool operator==(const std::string& lhs, const OperationID& rhs) {
114 return lhs == rhs.operationToString();
115 }
116
117 private:
118 // Data member containing this object's Operation enum value
119 const Operation operation_enum_ = Operation::DEFAULT_OPERATION;
120 };
121
126 {
127 private:
128 std::shared_ptr<carma_planning_msgs::msg::RouteEvent> latest_route_event_ = nullptr;
131 std::string cmv_id_;
132 std::string cargo_id_; // Empty if CMV is not currently carrying cargo
133 std::function<void(carma_v2x_msgs::msg::MobilityOperation)> publish_mobility_operation_;
134 std::function<void(carma_msgs::msg::UIInstructions)> publish_ui_instructions_;
135 std::function<bool(std::shared_ptr<carma_planning_msgs::srv::SetActiveRoute::Request>)> call_set_active_route_service_;
136 std::shared_ptr<lanelet::projection::LocalFrameProjector> map_projector_ = nullptr;
137 std::string georeference_{""};
138 bool starting_at_staging_area_; // Flag indicating CMV's first destination; 'true' indicates Staging Area Entrance; 'false' indicates Port Entrance.
139 bool enable_port_drayage_; // Flag to enable to port drayage operations. If false, state machine will remain in 'INACTIVE' state
140
141 // Data member for storing the strategy_params field of the last processed port drayage MobilityOperation message intended for this vehicle's cmv_id
143
144 // Constants
145 const std::string PORT_DRAYAGE_PLUGIN_ID = "port_drayage_plugin";
146 const std::string PORT_DRAYAGE_STRATEGY_ID = "carma/port_drayage";
147 const std::string SET_GUIDANCE_ACTIVE_SERVICE_ID = "/guidance/set_guidance_active";
148
149 // Clock for this object
150 rclcpp::Clock::SharedPtr clock_;
151
152 // Logger interface for this object
153 rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr logger_;
154
155 public:
156
169 PortDrayageWorker(rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr logger,
170 rclcpp::Clock::SharedPtr clock,
171 std::function<void(carma_v2x_msgs::msg::MobilityOperation)> mobility_operations_publisher,
172 std::function<void(carma_msgs::msg::UIInstructions)> ui_instructions_publisher,
173 std::function<bool(std::shared_ptr<carma_planning_msgs::srv::SetActiveRoute::Request>)> call_set_active_route);
174
179 void setVehicleID(const std::string& cmv_id);
180
185 void setCargoID(const std::string& cargo_id);
186
191 void setEnablePortDrayageFlag(bool enable_port_drayage);
192
197 void setStartingAtStagingAreaFlag(bool starting_at_staging_area);
198
203
208
216 std::shared_ptr<carma_planning_msgs::srv::SetActiveRoute::Request> composeSetActiveRouteRequest(boost::optional<double> dest_latitude, boost::optional<double> dest_longitude) const;
217
224 carma_msgs::msg::UIInstructions composeUIInstructions(const std::string& current_operation, const std::string& previous_operation);
225
230 carma_v2x_msgs::msg::MobilityOperation composeArrivalMessage() const;
231
236 void onNewGeoreference(std_msgs::msg::String::UniquePtr msg);
237
242 void onNewPose(geometry_msgs::msg::PoseStamped::UniquePtr msg);
243
248 void onInboundMobilityOperation(carma_v2x_msgs::msg::MobilityOperation::UniquePtr msg);
249
257
264 void mobilityOperationMessageParser(std::string mobility_operation_strategy_params);
265
270 void onGuidanceState(const carma_planning_msgs::msg::GuidanceState::UniquePtr msg);
271
276 void onRouteEvent(const carma_planning_msgs::msg::RouteEvent::UniquePtr msg);
277
283
284 // PortDrayageMobilityOperationMsg object for storing strategy_params data of a received port drayage MobilityOperation message intended for this vehicle's cmv_id
286
287 // LatLonCoordinate object for storing the vehicle's current gps latitude/longitude coordinates
289 };
290} // namespace port_drayage_plugin
Helper class containing an enum for valid port drayage MobilityOperation message operation IDs and a ...
OperationID::Operation getOperationID() const
Getter function to obtain the Operation enum associated with this object.
friend bool operator==(const std::string &lhs, const OperationID &rhs)
Overloaded == operator for comparision with String objects.
friend std::ostream & operator<<(std::ostream &output, const OperationID &oid)
Stream operator for this object.
Operation
Enum containing possible operation IDs used to define destinations for port drayage.
OperationID(enum Operation op)
Standard constructor for OperationID.
std::string operationToString() const
Function to convert this object's 'operation_enum_' to a human-readable string.
void setVehicleID(const std::string &cmv_id)
Setter function to set this object's cmv_id_ string.
carma_msgs::msg::UIInstructions composeUIInstructions(const std::string &current_operation, const std::string &previous_operation)
Creates a UIInstructions message that can be used to create a pop-up on the Web UI to notify a user t...
PortDrayageWorker(rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr logger, rclcpp::Clock::SharedPtr clock, std::function< void(carma_v2x_msgs::msg::MobilityOperation)> mobility_operations_publisher, std::function< void(carma_msgs::msg::UIInstructions)> ui_instructions_publisher, std::function< bool(std::shared_ptr< carma_planning_msgs::srv::SetActiveRoute::Request >)> call_set_active_route)
Standard constructor for the PortDrayageWorker.
void setStartingAtStagingAreaFlag(bool starting_at_staging_area)
Setter function to set this object's starting_at_staging_area flag.
PortDrayageState getPortDrayageState()
Get the current state of the port drayage state machine.
void onRouteEvent(const carma_planning_msgs::msg::RouteEvent::UniquePtr msg)
Callback to process each Route Event.
PortDrayageMobilityOperationMsg latest_mobility_operation_msg_
void updateCargoInformationAfterActionCompletion(const PortDrayageMobilityOperationMsg &previous_port_drayage_msg)
Method to update worker's cargo-related data members depending on whether the previously completed ac...
void onArrivedAtDestination()
Callback for usage by the PortDrayageStateMachine when the vehicle has arrived at a destination.
void setEnablePortDrayageFlag(bool enable_port_drayage)
Setter function to set this object's enable_port_drayage flag.
std::function< void(carma_v2x_msgs::msg::MobilityOperation)> publish_mobility_operation_
void mobilityOperationMessageParser(std::string mobility_operation_strategy_params)
Function to help parse the text included in an inbound MobilityOperation message's strategy_params fi...
void onNewPose(geometry_msgs::msg::PoseStamped::UniquePtr msg)
Callback for the pose subscriber. The pose will be converted into lat/lon and stored locally.
void onReceivedNewDestination()
Callback for usage by the PortDrayageStateMachine when the vehicle has received a new destination.
std::shared_ptr< carma_planning_msgs::srv::SetActiveRoute::Request > composeSetActiveRouteRequest(boost::optional< double > dest_latitude, boost::optional< double > dest_longitude) const
Create a SetActiveRoute service request to set a new active route for the system based on the destina...
std::shared_ptr< lanelet::projection::LocalFrameProjector > map_projector_
std::function< void(carma_msgs::msg::UIInstructions)> publish_ui_instructions_
rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr logger_
void onGuidanceState(const carma_planning_msgs::msg::GuidanceState::UniquePtr msg)
Callback to process the current status of the guidance state machine.
void onInboundMobilityOperation(carma_v2x_msgs::msg::MobilityOperation::UniquePtr msg)
Callback to process a received MobilityOperation message.
void setCargoID(const std::string &cargo_id)
Setter function to set this object's cargo_id_ string.
std::shared_ptr< carma_planning_msgs::msg::RouteEvent > latest_route_event_
void onNewGeoreference(std_msgs::msg::String::UniquePtr msg)
Callback for map projection string to define lat/lon <--> map conversion.
std::function< bool(std::shared_ptr< carma_planning_msgs::srv::SetActiveRoute::Request >)> call_set_active_route_service_
carma_v2x_msgs::msg::MobilityOperation composeArrivalMessage() const
Assemble the current dataset into a MobilityOperations message with a JSON formatted body containing ...
PortDrayageState
Enum containing the possible state values for the PortDrayagePlugin.
Convenience struct for storing the vehicle's current latitude/longitude coordinates.
Convenience struct for storing all data contained in a received MobilityOperation message's strategy_...