SUMO - Simulation of Urban MObility
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
MSDevice_Example.cpp
Go to the documentation of this file.
1
/****************************************************************************/
7
// A device which stands as an implementation example and which outputs movereminder calls
8
/****************************************************************************/
9
// SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
10
// Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
11
/****************************************************************************/
12
//
13
// This file is part of SUMO.
14
// SUMO is free software: you can redistribute it and/or modify
15
// it under the terms of the GNU General Public License as published by
16
// the Free Software Foundation, either version 3 of the License, or
17
// (at your option) any later version.
18
//
19
/****************************************************************************/
20
21
// ===========================================================================
22
// included modules
23
// ===========================================================================
24
#ifdef _MSC_VER
25
#include <
windows_config.h
>
26
#else
27
#include <
config.h
>
28
#endif
29
30
#include <
utils/common/TplConvert.h
>
31
#include <
utils/options/OptionsCont.h
>
32
#include <
utils/iodevices/OutputDevice.h
>
33
#include <
utils/common/SUMOVehicle.h
>
34
#include <
microsim/MSNet.h
>
35
#include <
microsim/MSLane.h
>
36
#include <
microsim/MSEdge.h
>
37
#include <
microsim/MSVehicle.h
>
38
#include "
MSDevice_Tripinfo.h
"
39
#include "
MSDevice_Example.h
"
40
41
#ifdef CHECK_MEMORY_LEAKS
42
#include <
foreign/nvwa/debug_new.h
>
43
#endif // CHECK_MEMORY_LEAKS
44
45
46
// ===========================================================================
47
// method definitions
48
// ===========================================================================
49
// ---------------------------------------------------------------------------
50
// static initialisation methods
51
// ---------------------------------------------------------------------------
52
void
53
MSDevice_Example::insertOptions
(
OptionsCont
& oc) {
54
oc.
addOptionSubTopic
(
"Example Device"
);
55
56
oc.
doRegister
(
"device.example.explicit"
,
new
Option_String
());
57
oc.
addDescription
(
"device.example.explicit"
,
"Example Device"
,
"Assign a device to named vehicles"
);
58
59
oc.
doRegister
(
"device.example.parameter"
,
new
Option_Float
(0.0));
60
oc.
addDescription
(
"device.example.parameter"
,
"Example Device"
,
"An exemplary parameter which can be used by all instances of the example device"
);
61
}
62
63
64
void
65
MSDevice_Example::buildVehicleDevices
(
SUMOVehicle
& v, std::vector<MSDevice*>& into) {
66
OptionsCont
& oc =
OptionsCont::getOptions
();
67
if
(
equippedByDefaultAssignmentOptions
(oc,
"example"
, v)) {
68
// build the device
69
// get custom vehicle parameter
70
SUMOReal
customParameter2 = -1;
71
if
(v.
getParameter
().
knowsParameter
(
"example"
)) {
72
try
{
73
customParameter2 =
TplConvert::_2SUMOReal
(v.
getParameter
().
getParameter
(
"example"
,
"-1"
).c_str());
74
}
catch
(...) {
75
WRITE_WARNING
(
"Invalid value '"
+ v.
getParameter
().
getParameter
(
"example"
,
"-1"
) +
"'for vehicle parameter 'example'"
);
76
}
77
78
}
else
{
79
std::cout <<
"vehicle '"
<< v.
getID
() <<
"' does not supply vehicle parameter 'example'. Using default of "
<< customParameter2 <<
"\n"
;
80
}
81
// get custom vType parameter
82
SUMOReal
customParameter3 = -1;
83
if
(v.
getVehicleType
().
getParameter
().
knowsParameter
(
"example"
)) {
84
try
{
85
customParameter3 =
TplConvert::_2SUMOReal
(v.
getVehicleType
().
getParameter
().
getParameter
(
"example"
,
"-1"
).c_str());
86
}
catch
(...) {
87
WRITE_WARNING
(
"Invalid value '"
+ v.
getVehicleType
().
getParameter
().
getParameter
(
"example"
,
"-1"
) +
"'for vType parameter 'example'"
);
88
}
89
90
}
else
{
91
std::cout <<
"vehicle '"
<< v.
getID
() <<
"' does not supply vType parameter 'example'. Using default of "
<< customParameter3 <<
"\n"
;
92
}
93
MSDevice_Example
* device =
new
MSDevice_Example
(v,
"example_"
+ v.
getID
(),
94
oc.
getFloat
(
"device.example.parameter"
),
95
customParameter2,
96
customParameter3);
97
into.push_back(device);
98
}
99
}
100
101
102
// ---------------------------------------------------------------------------
103
// MSDevice_Example-methods
104
// ---------------------------------------------------------------------------
105
MSDevice_Example::MSDevice_Example
(
SUMOVehicle
& holder,
const
std::string&
id
,
106
SUMOReal
customValue1,
SUMOReal
customValue2,
SUMOReal
customValue3) :
107
MSDevice
(holder, id),
108
myCustomValue1(customValue1),
109
myCustomValue2(customValue2),
110
myCustomValue3(customValue3) {
111
std::cout <<
"initialized device '"
<<
id
<<
"' with myCustomValue1="
<<
myCustomValue1
<<
", myCustomValue2="
<<
myCustomValue2
<<
", myCustomValue3="
<<
myCustomValue3
<<
"\n"
;
112
}
113
114
115
MSDevice_Example::~MSDevice_Example
() {
116
}
117
118
119
bool
120
MSDevice_Example::notifyMove
(
SUMOVehicle
& veh,
SUMOReal
/* oldPos */
,
121
SUMOReal
/* newPos */
,
SUMOReal
newSpeed) {
122
std::cout <<
"device '"
<<
getID
() <<
"' notifyMove: newSpeed="
<< newSpeed <<
"\n"
;
123
// check whether another device is present on the vehicle:
124
MSDevice_Tripinfo
* otherDevice =
static_cast<
MSDevice_Tripinfo
*
>
(veh.
getDevice
(
MSDevice_Tripinfo::getTypeInfo
()));
125
if
(otherDevice != 0) {
126
std::cout <<
" veh '"
<< veh.
getID
() <<
" has device '"
<< otherDevice->
getID
() <<
"'\n"
;
127
}
128
return
true
;
// keep the device
129
}
130
131
132
bool
133
MSDevice_Example::notifyEnter
(
SUMOVehicle
& veh,
MSMoveReminder::Notification
reason) {
134
std::cout <<
"device '"
<<
getID
() <<
"' notifyEnter: reason="
<< reason <<
" currentEdge="
<< veh.
getEdge
()->
getID
() <<
"\n"
;
135
return
true
;
// keep the device
136
}
137
138
139
bool
140
MSDevice_Example::notifyLeave
(
SUMOVehicle
& veh,
SUMOReal
/*lastPos*/
,
141
MSMoveReminder::Notification
reason) {
142
std::cout <<
"device '"
<<
getID
() <<
"' notifyLeave: reason="
<< reason <<
" currentEdge="
<< veh.
getEdge
()->
getID
() <<
"\n"
;
143
return
true
;
// keep the device
144
}
145
146
147
void
148
MSDevice_Example::generateOutput
()
const
{
149
if
(
OptionsCont::getOptions
().isSet(
"tripinfo-output"
)) {
150
OutputDevice
& os =
OutputDevice::getDeviceByOption
(
"tripinfo-output"
);
151
os.
openTag
(
"example_device"
);
152
os.
writeAttr
(
"customValue1"
,
toString
(
myCustomValue1
));
153
os.
writeAttr
(
"customValue2"
,
toString
(
myCustomValue2
));
154
os.
closeTag
();
155
}
156
}
157
158
159
160
/****************************************************************************/
161
build
buildd
sumo-0.18~dfsg
src
microsim
devices
MSDevice_Example.cpp
Generated on Wed Oct 23 2013 01:15:09 for SUMO - Simulation of Urban MObility by
1.8.4