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

Merge branch '3-add-lateral-resolution-as-parameter-to-sumo_config' into 'master'

added setmaxspeedlateral command and implementation

Closes #3

See merge request ezcar2x/ns3/traci!4
parents f824c931 d94734bb
No related branches found
No related tags found
No related merge requests found
...@@ -366,6 +366,43 @@ private: ...@@ -366,6 +366,43 @@ private:
}; };
class SetMaxSpeedLateral : public Command
{
public:
SetMaxSpeedLateral(std::string vehicle, double speed)
: m_vehicle (vehicle), m_speed (speed)
{
}
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<double>::Size (m_speed);
}
bool DoSerializeData (BufferType& buffer) const override
{
CodingTraits<UByte>::Append (buffer, libsumo::VAR_MAXSPEED_LAT);
CodingTraits<std::string>::Append (buffer, m_vehicle);
CodingTraits<UByte>::Append (buffer, CodingTraits<double>::IDENTIFIER);
CodingTraits<double>::Append (buffer, m_speed);
return true;
}
std::string m_vehicle;
double m_speed;
};
class MoveToXY : public Command class MoveToXY : public Command
{ {
public: public:
......
...@@ -33,7 +33,8 @@ Vehicle::Vehicle (Ptr<TraCi> traci, std::string id) ...@@ -33,7 +33,8 @@ Vehicle::Vehicle (Ptr<TraCi> traci, std::string id)
m_position (m_traci, id), m_position (m_traci, id),
m_length (m_traci, id), m_width (m_traci, id), m_height (m_traci, id), m_length (m_traci, id), m_width (m_traci, id), m_height (m_traci, id),
m_speed (m_traci, id), m_speed_lateral (m_traci, id), m_maxSpeed (m_traci, id), m_speed (m_traci, id), m_speed_lateral (m_traci, id), m_maxSpeed (m_traci, id),
m_heading (m_traci, id), m_acceleration (m_traci, id), m_color (m_traci, id) m_heading (m_traci, id), m_acceleration (m_traci, id),
m_lane_idx (m_traci, id), m_road_id (m_traci, id), m_color (m_traci, id)
{ {
} }
...@@ -143,6 +144,18 @@ Vehicle::GetAcceleration (bool forceReload) const ...@@ -143,6 +144,18 @@ Vehicle::GetAcceleration (bool forceReload) const
return m_acceleration.GetValue (forceReload); return m_acceleration.GetValue (forceReload);
} }
int
Vehicle::GetLaneIndex (bool forceReload) const
{
return m_lane_idx.GetValue (forceReload);
}
std::string
Vehicle::GetRoadID (bool forceReload) const
{
return m_road_id.GetValue (forceReload);
}
Color Color
Vehicle::GetColor (bool forceReload) const Vehicle::GetColor (bool forceReload) const
{ {
...@@ -175,6 +188,15 @@ Vehicle::setSpeed (double speed) ...@@ -175,6 +188,15 @@ Vehicle::setSpeed (double speed)
m_traci->ExecuteCommand (my_command, my_result); m_traci->ExecuteCommand (my_command, my_result);
} }
void
Vehicle::setMaxSpeedLateral (double max_speed)
{
NS_LOG_INFO("TraCiVehicle: Sending SetMaxSpeedLateral to vehicle "+m_id+" : max_speed = "+std::to_string(max_speed));
traci::command::SetMaxSpeedLateral my_command(m_id, max_speed);
traci::result::NoResult my_result;
m_traci->ExecuteCommand (my_command, my_result);
}
void void
Vehicle::slowDown (double speed, double duration) Vehicle::slowDown (double speed, double duration)
{ {
......
...@@ -145,6 +145,14 @@ public: ...@@ -145,6 +145,14 @@ public:
double double
GetAcceleration (bool forceReload = false) const; GetAcceleration (bool forceReload = false) const;
//! Get current lane idx
int
GetLaneIndex (bool forceReload = false) const;
//! Get current road id
std::string
GetRoadID (bool forceReload = false) const;
Color Color
GetColor (bool forceReload = false) const; GetColor (bool forceReload = false) const;
...@@ -213,6 +221,15 @@ public: ...@@ -213,6 +221,15 @@ public:
void void
setSpeed (double speed); setSpeed (double speed);
/*!
* @brief set maximum lateral speed of the specified vehicle.
*
* Parameters:
* - new max speed to set
*/
void
setMaxSpeedLateral (double max_speed);
/*! /*!
* @brief gradually change the speed over given duration. * @brief gradually change the speed over given duration.
* *
...@@ -253,6 +270,8 @@ private: ...@@ -253,6 +270,8 @@ private:
CachedVariable<double, libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::VAR_MAXSPEED> m_maxSpeed; CachedVariable<double, libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::VAR_MAXSPEED> m_maxSpeed;
CachedVariable<double, libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::VAR_ANGLE> m_heading; CachedVariable<double, libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::VAR_ANGLE> m_heading;
CachedVariable<double, libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::VAR_ACCELERATION> m_acceleration; CachedVariable<double, libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::VAR_ACCELERATION> m_acceleration;
CachedVariable<int, libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::VAR_LANE_INDEX> m_lane_idx;
CachedVariable<std::string, libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::VAR_ROAD_ID> m_road_id;
CachedVariable<Color, libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::VAR_COLOR> m_color; 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