Skip to content
Snippets Groups Projects
Commit 4981d368 authored by Vishwanath Hugar's avatar Vishwanath Hugar Committed by Josef Jiru
Browse files

Resolve "Add getRoute and setRoute APIs to SUMO"

parent 2c47a9f8
No related branches found
No related tags found
No related merge requests found
......@@ -460,6 +460,47 @@ private:
};
class SetRoute : public Command
{
public:
SetRoute(std::string vehicle, StringList edgeIdList)
: m_vehicle (vehicle), m_edgeIdList (edgeIdList)
{
}
private:
int DoGetId () const override
{
return libsumo::CMD_SET_VEHICLE_VARIABLE;
}
int DoGetDataLength () const override
{
return
1 + CodingTraits<std::string>::Size (m_vehicle) +
1 + CodingTraits<StringList>::Size (m_edgeIdList);
}
bool DoSerializeData (BufferType& buffer) const override
{
CodingTraits<UByte>::Append (buffer, libsumo::VAR_ROUTE);
CodingTraits<std::string>::Append (buffer, m_vehicle);
CodingTraits<UByte>::Append (buffer, CodingTraits<StringList>::IDENTIFIER);
CodingTraits<int>::Append (buffer, (int)m_edgeIdList.size());
for (int i = 0; i < (int)m_edgeIdList.size(); ++i) {
CodingTraits<std::string>::Append (buffer, m_edgeIdList[i]);
}
return true;
}
std::string m_vehicle;
StringList m_edgeIdList;
};
} // namespace command
} // namespace traci
......
......@@ -35,7 +35,7 @@ Vehicle::Vehicle (Ptr<TraCi> traci, std::string id)
m_speed (m_traci, id), m_speedLateral (m_traci, id), m_maxSpeed (m_traci, id),
m_maxSpeedLateral (m_traci, id), m_heading (m_traci, id), m_acceleration (m_traci, id),
m_maxAcceleration (m_traci, id), m_maxDeceleration (m_traci, id),
m_laneIdx (m_traci, id), m_roadId (m_traci, id), m_color (m_traci, id)
m_laneIdx (m_traci, id), m_roadId (m_traci, id), m_routeId (m_traci, id), m_route (m_traci, id), m_color (m_traci, id)
{
}
......@@ -175,6 +175,18 @@ Vehicle::GetRoadID (bool forceReload) const
return m_roadId.GetValue (forceReload);
}
std::string
Vehicle::GetRouteID (bool forceReload) const
{
return m_routeId.GetValue (forceReload);
}
std::vector<std::string>
Vehicle::GetRoute (bool forceReload) const
{
return m_route.GetValue (forceReload);
}
Color
Vehicle::GetColor (bool forceReload) const
{
......@@ -243,6 +255,18 @@ Vehicle::moveToXY (std::string edgeID, int laneID, double x, double y, double an
m_traci->ExecuteCommand (my_command, my_result);
}
void
Vehicle::setRoute (std::vector<std::string> edgeIdList)
{
NS_LOG_INFO("TraCiVehicle: Sending route to vehicle "+m_id+" : route = ");
for (auto const& edgeId : edgeIdList) {
NS_LOG_INFO("EdgeId: "+ edgeId+ " ");
}
traci::command::SetRoute my_command(m_id, edgeIdList);
traci::result::NoResult my_result;
m_traci->ExecuteCommand (my_command, my_result);
}
}
}
......@@ -165,6 +165,14 @@ public:
std::string
GetRoadID (bool forceReload = false) const;
//! Get current route id
std::string
GetRouteID (bool forceReload = false) const;
//! Get route, edge list
std::vector<std::string>
GetRoute (bool forceReload = false) const;
Color
GetColor (bool forceReload = false) const;
......@@ -265,6 +273,17 @@ public:
void
moveToXY (std::string edgeID, int laneID, double x, double y, double angle=-1000000.0);
/*!
* @brief set route for vehicle.
*
* The first edge in the list has to be the one that the vehicle is at at the moment.
*
* Parameters:
* - new edgeId list
*/
void
setRoute (std::vector<std::string> edgeIdList);
private:
Ptr<TraCi> m_traci; // link to the traci instance
std::string m_id; // id of the object
......@@ -287,6 +306,8 @@ private:
CachedVariable<double, libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::VAR_DECEL> m_maxDeceleration;
CachedVariable<int, libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::VAR_LANE_INDEX> m_laneIdx;
CachedVariable<std::string, libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::VAR_ROAD_ID> m_roadId;
CachedVariable<std::string, libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::VAR_ROUTE_ID> m_routeId;
CachedVariable<std::vector<std::string>, libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::VAR_EDGES> m_route;
CachedVariable<Color, libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::VAR_COLOR> m_color;
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment