Skip to content
Snippets Groups Projects
Commit 843b77f6 authored by Josef Jiru's avatar Josef Jiru
Browse files

Merge branch '8-add-reroutepark-and-getlaneid-command' into 'master'

Resolve "Add reroutePark and getLaneId command"

Closes #8

See merge request ezcar2x/ns3/traci!9
parents 2c18d491 a1791b2c
No related branches found
No related tags found
No related merge requests found
...@@ -563,6 +563,46 @@ private: ...@@ -563,6 +563,46 @@ private:
}; };
class ReroutePark : public Command
{
public:
ReroutePark(std::string vehicle, std::string parkAreaId)
: m_vehicle (vehicle), m_parkId (parkAreaId)
{
}
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<int>::Size (7) + // compound variable
1 + CodingTraits<std::string>::Size (m_parkId);
}
bool DoSerializeData (BufferType& buffer) const override
{
CodingTraits<UByte>::Append (buffer, libsumo::CMD_REROUTE_TO_PARKING);
CodingTraits<std::string>::Append (buffer, m_vehicle);
CodingTraits<UByte>::Append (buffer, libsumo::TYPE_COMPOUND);
CodingTraits<int>::Append (buffer, 1);
CodingTraits<UByte>::Append (buffer, CodingTraits<std::string>::IDENTIFIER);
CodingTraits<std::string>::Append (buffer, m_parkId);
return true;
}
std::string m_vehicle;
std::string m_parkId;
};
} // namespace command } // namespace command
} // namespace traci } // namespace traci
} // namespace ns3 } // namespace ns3
......
...@@ -35,7 +35,8 @@ Vehicle::Vehicle (Ptr<TraCi> traci, std::string id) ...@@ -35,7 +35,8 @@ Vehicle::Vehicle (Ptr<TraCi> traci, std::string id)
m_speed (m_traci, id), m_speedLateral (m_traci, id), m_maxSpeed (m_traci, 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_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_maxAcceleration (m_traci, id), m_maxDeceleration (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) m_laneIdx (m_traci, id), m_laneId (m_traci, id), m_roadId (m_traci, id), m_routeId (m_traci, id),
m_route (m_traci, id), m_color (m_traci, id)
{ {
} }
...@@ -169,6 +170,12 @@ Vehicle::GetLaneIndex (bool forceReload) const ...@@ -169,6 +170,12 @@ Vehicle::GetLaneIndex (bool forceReload) const
return m_laneIdx.GetValue (forceReload); return m_laneIdx.GetValue (forceReload);
} }
std::string
Vehicle::GetLaneId (bool forceReload) const
{
return m_laneId.GetValue (forceReload);
}
std::string std::string
Vehicle::GetRoadID (bool forceReload) const Vehicle::GetRoadID (bool forceReload) const
{ {
...@@ -275,7 +282,16 @@ Vehicle::setStop (std::string edgeID, double endpos, int lane, double stopdurati ...@@ -275,7 +282,16 @@ Vehicle::setStop (std::string edgeID, double endpos, int lane, double stopdurati
traci::command::SetStop my_command(m_id, edgeID, endpos, (traci::Byte)lane, stopduration, (traci::Byte)stopflag, startpos, stopuntil); traci::command::SetStop my_command(m_id, edgeID, endpos, (traci::Byte)lane, stopduration, (traci::Byte)stopflag, startpos, stopuntil);
traci::result::NoResult my_result; traci::result::NoResult my_result;
m_traci->ExecuteCommand (my_command, my_result); m_traci->ExecuteCommand (my_command, my_result);
}
void
Vehicle::reroutePark (std::string parkAreaId)
{
NS_LOG_INFO("TraCiVehicle: Change the next parking area in parkAreaId "+parkAreaId);
traci::command::ReroutePark my_command(m_id, parkAreaId);
traci::result::NoResult my_result;
m_traci->ExecuteCommand (my_command, my_result);
} }
} }
......
...@@ -161,6 +161,10 @@ public: ...@@ -161,6 +161,10 @@ public:
int int
GetLaneIndex (bool forceReload = false) const; GetLaneIndex (bool forceReload = false) const;
//! Get current lane ID
std::string
GetLaneId (bool forceReload = false) const;
//! Get current road id //! Get current road id
std::string std::string
GetRoadID (bool forceReload = false) const; GetRoadID (bool forceReload = false) const;
...@@ -298,6 +302,16 @@ public: ...@@ -298,6 +302,16 @@ public:
void void
setStop (std::string edgeID, double endpos, int lane, double stopduration, int stopflag, double startpos, double stopuntil); setStop (std::string edgeID, double endpos, int lane, double stopduration, int stopflag, double startpos, double stopuntil);
/*!
* @brief reroute vehicle to parking area.
*
* Parameters:
* - parking area ID
*/
void
reroutePark (std::string parkAreaId);
private: private:
Ptr<TraCi> m_traci; // link to the traci instance Ptr<TraCi> m_traci; // link to the traci instance
std::string m_id; // id of the object std::string m_id; // id of the object
...@@ -319,6 +333,7 @@ private: ...@@ -319,6 +333,7 @@ private:
CachedVariable<double, libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::VAR_ACCEL> m_maxAcceleration; CachedVariable<double, libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::VAR_ACCEL> m_maxAcceleration;
CachedVariable<double, libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::VAR_DECEL> m_maxDeceleration; 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<int, libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::VAR_LANE_INDEX> m_laneIdx;
CachedVariable<std::string, libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::VAR_LANE_ID> m_laneId;
CachedVariable<std::string, libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::VAR_ROAD_ID> m_roadId; 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::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<std::vector<std::string>, libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::VAR_EDGES> m_route;
......
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