Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2017 Fraunhofer ESK
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Karsten Roscher <karsten.roscher@esk.fraunhofer.de>
*/
#include "traci-vehicle.h"
#include "traci-geometry.h"
namespace ns3 {
namespace traci {
Vehicle::Vehicle (Ptr<TraCi> traci, std::string id)
: m_traci (traci), m_id (id),
m_position (m_traci, id),
m_length (m_traci, id), m_width (m_traci, id), m_height (m_traci, id),
m_speed (m_traci, id), m_maxSpeed (m_traci, id), m_heading (m_traci, id),
m_color (m_traci, id)
{
}
std::string
Vehicle::GetId () const
{
return m_id;
}
Ptr<TraCi>
Vehicle::GetTraCi () const
{
return m_traci;
}
void
Vehicle::SetNode (Ptr<Node> node)
{
m_node = node;
}
Ptr<Node>
Vehicle::GetNode () const
{
return m_node;
}
Vector
Vehicle::GetPosition (bool forceReload) const
{
// Note: This is ok for now since Position3D is just a typedef for Vector.
// If it changes some day, the compiler should complain.
return m_position.GetValue (forceReload);
}
Vector2D
Vehicle::GetPosition2d (bool forceReload) const
{
// we reuse the 3D position here
Vector pos = GetPosition (forceReload);
return Vector2D (pos.x, pos.y);
}
Vector
Vehicle::GetCenterPosition (bool forceReload) const
{
return ShiftPosition (
GetPosition (forceReload),
GetHeading (forceReload),
-GetLength (forceReload) / 2.0);
}
double
Vehicle::GetLength (bool forceReload) const
{
return m_length.GetValue (forceReload);
}
double
Vehicle::GetWidth (bool forceReload) const
{
return m_width.GetValue (forceReload);
}
double
Vehicle::GetHeight (bool forceReload) const
{
return m_height.GetValue (forceReload);
}
double
Vehicle::GetSpeed (bool forceReload) const
{
return m_speed.GetValue (forceReload);
}
double
Vehicle::GetMaxSpeed (bool forceReload) const
{
return m_maxSpeed.GetValue (forceReload);
}
Heading
Vehicle::GetHeading (bool forceReload) const
{
return Heading (m_heading.GetValue (forceReload));
}
Vector
Vehicle::GetVelocity (bool forceReload) const
{
double speed = GetSpeed (forceReload);
Heading heading = GetHeading (forceReload);
return VelocityFromSpeedHeading (speed, heading);
}
Color
Vehicle::GetColor (bool forceReload) const
{
return m_color.GetValue (forceReload);
}
void
Vehicle::SetColor (const Color& color)
{
SetVariable (VAR_COLOR, color);
}
}
}