Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/libtraci/Vehicle.cpp
169665 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2017-2025 German Aerospace Center (DLR) and others.
4
// This program and the accompanying materials are made available under the
5
// terms of the Eclipse Public License 2.0 which is available at
6
// https://www.eclipse.org/legal/epl-2.0/
7
// This Source Code may also be made available under the following Secondary
8
// Licenses when the conditions for such availability set forth in the Eclipse
9
// Public License 2.0 are satisfied: GNU General Public License, version 2
10
// or later which is available at
11
// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
/****************************************************************************/
14
/// @file Vehicle.cpp
15
/// @author Jakob Erdmann
16
/// @author Michael Behrisch
17
/// @author Mirko Barthauer
18
/// @date 30.05.2012
19
///
20
// C++ TraCI client API implementation
21
/****************************************************************************/
22
#include <config.h>
23
#include <sstream>
24
25
#define LIBTRACI 1
26
#include <libsumo/StorageHelper.h>
27
#include <libsumo/Vehicle.h>
28
#include "Domain.h"
29
30
namespace libtraci {
31
32
typedef Domain<libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::CMD_SET_VEHICLE_VARIABLE> Dom;
33
34
35
// ===========================================================================
36
// static member definitions
37
// ===========================================================================
38
std::vector<std::string>
39
Vehicle::getIDList() {
40
return Dom::getStringVector(libsumo::TRACI_ID_LIST, "");
41
}
42
43
44
int
45
Vehicle::getIDCount() {
46
return Dom::getInt(libsumo::ID_COUNT, "");
47
}
48
49
50
LIBTRACI_SUBSCRIPTION_IMPLEMENTATION(Vehicle, VEHICLE)
51
LIBTRACI_PARAMETER_IMPLEMENTATION(Vehicle, VEHICLE)
52
53
double
54
Vehicle::getSpeed(const std::string& vehID) {
55
return Dom::getDouble(libsumo::VAR_SPEED, vehID);
56
}
57
58
double
59
Vehicle::getLateralSpeed(const std::string& vehID) {
60
return Dom::getDouble(libsumo::VAR_SPEED_LAT, vehID);
61
}
62
63
double
64
Vehicle::getAcceleration(const std::string& vehID) {
65
return Dom::getDouble(libsumo::VAR_ACCELERATION, vehID);
66
}
67
68
69
double
70
Vehicle::getSpeedWithoutTraCI(const std::string& vehID) {
71
return Dom::getDouble(libsumo::VAR_SPEED_WITHOUT_TRACI, vehID);
72
}
73
74
75
libsumo::TraCIPosition
76
Vehicle::getPosition(const std::string& vehID, const bool includeZ) {
77
return includeZ ? getPosition3D(vehID) : Dom::getPos(libsumo::VAR_POSITION, vehID);
78
}
79
80
81
libsumo::TraCIPosition
82
Vehicle::getPosition3D(const std::string& vehID) {
83
return Dom::getPos3D(libsumo::VAR_POSITION3D, vehID);
84
}
85
86
87
double
88
Vehicle::getAngle(const std::string& vehID) {
89
return Dom::getDouble(libsumo::VAR_ANGLE, vehID);
90
}
91
92
93
double
94
Vehicle::getSlope(const std::string& vehID) {
95
return Dom::getDouble(libsumo::VAR_SLOPE, vehID);
96
}
97
98
99
std::string
100
Vehicle::getRoadID(const std::string& vehID) {
101
return Dom::getString(libsumo::VAR_ROAD_ID, vehID);
102
}
103
104
105
double
106
Vehicle::getDeparture(const std::string& vehID) {
107
return Dom::getDouble(libsumo::VAR_DEPARTURE, vehID);
108
}
109
110
111
double
112
Vehicle::getDepartDelay(const std::string& vehID) {
113
return Dom::getDouble(libsumo::VAR_DEPART_DELAY, vehID);
114
}
115
116
117
std::string
118
Vehicle::getLaneID(const std::string& vehID) {
119
return Dom::getString(libsumo::VAR_LANE_ID, vehID);
120
}
121
122
123
int
124
Vehicle::getLaneIndex(const std::string& vehID) {
125
return Dom::getInt(libsumo::VAR_LANE_INDEX, vehID);
126
}
127
128
129
std::string
130
Vehicle::getSegmentID(const std::string& vehID) {
131
return Dom::getString(libsumo::VAR_SEGMENT_ID, vehID);
132
}
133
134
135
int
136
Vehicle::getSegmentIndex(const std::string& vehID) {
137
return Dom::getInt(libsumo::VAR_SEGMENT_INDEX, vehID);
138
}
139
140
141
std::string
142
Vehicle::getTypeID(const std::string& vehID) {
143
return Dom::getString(libsumo::VAR_TYPE, vehID);
144
}
145
146
147
std::string
148
Vehicle::getRouteID(const std::string& vehID) {
149
return Dom::getString(libsumo::VAR_ROUTE_ID, vehID);
150
}
151
152
153
int
154
Vehicle::getRouteIndex(const std::string& vehID) {
155
return Dom::getInt(libsumo::VAR_ROUTE_INDEX, vehID);
156
}
157
158
159
libsumo::TraCIColor
160
Vehicle::getColor(const std::string& vehID) {
161
return Dom::getCol(libsumo::VAR_COLOR, vehID);
162
}
163
164
double
165
Vehicle::getLanePosition(const std::string& vehID) {
166
return Dom::getDouble(libsumo::VAR_LANEPOSITION, vehID);
167
}
168
169
double
170
Vehicle::getLateralLanePosition(const std::string& vehID) {
171
return Dom::getDouble(libsumo::VAR_LANEPOSITION_LAT, vehID);
172
}
173
174
double
175
Vehicle::getCO2Emission(const std::string& vehID) {
176
return Dom::getDouble(libsumo::VAR_CO2EMISSION, vehID);
177
}
178
179
double
180
Vehicle::getCOEmission(const std::string& vehID) {
181
return Dom::getDouble(libsumo::VAR_COEMISSION, vehID);
182
}
183
184
double
185
Vehicle::getHCEmission(const std::string& vehID) {
186
return Dom::getDouble(libsumo::VAR_HCEMISSION, vehID);
187
}
188
189
double
190
Vehicle::getPMxEmission(const std::string& vehID) {
191
return Dom::getDouble(libsumo::VAR_PMXEMISSION, vehID);
192
}
193
194
double
195
Vehicle::getNOxEmission(const std::string& vehID) {
196
return Dom::getDouble(libsumo::VAR_NOXEMISSION, vehID);
197
}
198
199
double
200
Vehicle::getFuelConsumption(const std::string& vehID) {
201
return Dom::getDouble(libsumo::VAR_FUELCONSUMPTION, vehID);
202
}
203
204
double
205
Vehicle::getNoiseEmission(const std::string& vehID) {
206
return Dom::getDouble(libsumo::VAR_NOISEEMISSION, vehID);
207
}
208
209
double
210
Vehicle::getElectricityConsumption(const std::string& vehID) {
211
return Dom::getDouble(libsumo::VAR_ELECTRICITYCONSUMPTION, vehID);
212
}
213
214
int
215
Vehicle::getPersonNumber(const std::string& vehID) {
216
return Dom::getInt(libsumo::VAR_PERSON_NUMBER, vehID);
217
}
218
219
int
220
Vehicle::getPersonCapacity(const std::string& vehID) {
221
return Dom::getInt(libsumo::VAR_PERSON_CAPACITY, vehID);
222
}
223
224
225
double
226
Vehicle::getBoardingDuration(const std::string& vehID) {
227
return Dom::getDouble(libsumo::VAR_BOARDING_DURATION, vehID);
228
}
229
230
231
double
232
Vehicle::getImpatience(const std::string& vehID) {
233
return Dom::getDouble(libsumo::VAR_IMPATIENCE, vehID);
234
}
235
236
237
std::vector<std::string>
238
Vehicle::getPersonIDList(const std::string& vehID) {
239
return Dom::getStringVector(libsumo::LAST_STEP_PERSON_ID_LIST, vehID);
240
}
241
242
std::pair<std::string, double>
243
Vehicle::getLeader(const std::string& vehID, double dist) {
244
tcpip::Storage content;
245
StoHelp::writeTypedDouble(content, dist);
246
std::unique_lock<std::mutex> lock{ libtraci::Connection::getActive().getMutex() };
247
tcpip::Storage& ret = Dom::get(libsumo::VAR_LEADER, vehID, &content);
248
ret.readInt(); // components
249
ret.readUnsignedByte();
250
const std::string leaderID = ret.readString();
251
ret.readUnsignedByte();
252
const double gap = ret.readDouble();
253
return std::make_pair(leaderID, gap);
254
}
255
256
257
std::pair<std::string, double>
258
Vehicle::getFollower(const std::string& vehID, double dist) {
259
tcpip::Storage content;
260
StoHelp::writeTypedDouble(content, dist);
261
std::unique_lock<std::mutex> lock{ libtraci::Connection::getActive().getMutex() };
262
tcpip::Storage& ret = Dom::get(libsumo::VAR_FOLLOWER, vehID, &content);
263
ret.readInt(); // components
264
const std::string leaderID = StoHelp::readTypedString(ret);
265
return std::make_pair(leaderID, StoHelp::readTypedDouble(ret));
266
}
267
268
269
std::vector<libsumo::TraCIJunctionFoe>
270
Vehicle::getJunctionFoes(const std::string& vehID, double dist) {
271
std::vector<libsumo::TraCIJunctionFoe> result;
272
tcpip::Storage content;
273
StoHelp::writeTypedDouble(content, dist);
274
std::unique_lock<std::mutex> lock{ libtraci::Connection::getActive().getMutex() };
275
tcpip::Storage& ret = Dom::get(libsumo::VAR_FOES, vehID, &content);
276
ret.readInt(); // compound size
277
StoHelp::readJunctionFoeVector(ret, result);
278
return result;
279
}
280
281
282
double
283
Vehicle::getWaitingTime(const std::string& vehID) {
284
return Dom::getDouble(libsumo::VAR_WAITING_TIME, vehID);
285
}
286
287
288
double
289
Vehicle::getAccumulatedWaitingTime(const std::string& vehID) {
290
return Dom::getDouble(libsumo::VAR_ACCUMULATED_WAITING_TIME, vehID);
291
}
292
293
294
double
295
Vehicle::getAdaptedTraveltime(const std::string& vehID, double time, const std::string& edgeID) {
296
tcpip::Storage content;
297
StoHelp::writeCompound(content, 2);
298
StoHelp::writeTypedDouble(content, time);
299
StoHelp::writeTypedString(content, edgeID);
300
return Dom::getDouble(libsumo::VAR_EDGE_TRAVELTIME, vehID, &content);
301
}
302
303
304
double
305
Vehicle::getEffort(const std::string& vehID, double time, const std::string& edgeID) {
306
tcpip::Storage content;
307
StoHelp::writeCompound(content, 2);
308
StoHelp::writeTypedDouble(content, time);
309
StoHelp::writeTypedString(content, edgeID);
310
return Dom::getDouble(libsumo::VAR_EDGE_EFFORT, vehID, &content);
311
}
312
313
314
bool
315
Vehicle::isRouteValid(const std::string& vehID) {
316
return Dom::getInt(libsumo::VAR_ROUTE_VALID, vehID) != 0;
317
}
318
319
320
std::vector<std::string>
321
Vehicle::getRoute(const std::string& vehID) {
322
return Dom::getStringVector(libsumo::VAR_EDGES, vehID);
323
}
324
325
326
int
327
Vehicle::getSignals(const std::string& vehID) {
328
return Dom::getInt(libsumo::VAR_SIGNALS, vehID);
329
}
330
331
332
std::vector<libsumo::TraCIBestLanesData>
333
Vehicle::getBestLanes(const std::string& vehID) {
334
std::unique_lock<std::mutex> lock{ libtraci::Connection::getActive().getMutex() };
335
std::vector<libsumo::TraCIBestLanesData> result;
336
tcpip::Storage& ret = Dom::get(libsumo::VAR_BEST_LANES, vehID);
337
ret.readInt();
338
StoHelp::readBestLanesVector(ret, result);
339
return result;
340
}
341
342
343
std::vector<libsumo::TraCINextTLSData>
344
Vehicle::getNextTLS(const std::string& vehID) {
345
std::unique_lock<std::mutex> lock{ libtraci::Connection::getActive().getMutex() };
346
std::vector<libsumo::TraCINextTLSData> result;
347
tcpip::Storage& ret = Dom::get(libsumo::VAR_NEXT_TLS, vehID);
348
ret.readInt(); // components
349
StoHelp::readTLSDataVector(ret, result);
350
return result;
351
}
352
353
std::vector<libsumo::TraCINextStopData>
354
Vehicle::getNextStops(const std::string& vehID) {
355
return getStops(vehID, 0);
356
}
357
358
std::vector<libsumo::TraCIConnection>
359
Vehicle::getNextLinks(const std::string& vehID) {
360
std::unique_lock<std::mutex> lock{ libtraci::Connection::getActive().getMutex() };
361
std::vector<libsumo::TraCIConnection> result;
362
tcpip::Storage& ret = Dom::get(libsumo::VAR_NEXT_LINKS, vehID);
363
ret.readInt(); // components
364
// number of items
365
const int linkNo = StoHelp::readTypedInt(ret);
366
for (int i = 0; i < linkNo; ++i) {
367
libsumo::TraCIConnection con;
368
StoHelp::readConnection(ret, con);
369
result.emplace_back(con);
370
}
371
return result;
372
}
373
374
std::vector<libsumo::TraCINextStopData>
375
Vehicle::getStops(const std::string& vehID, int limit) {
376
std::vector<libsumo::TraCINextStopData> result;
377
tcpip::Storage content;
378
StoHelp::writeTypedInt(content, limit);
379
std::unique_lock<std::mutex> lock{ libtraci::Connection::getActive().getMutex() };
380
tcpip::Storage& ret = Dom::get(libsumo::VAR_NEXT_STOPS2, vehID, &content);
381
ret.readInt(); // components
382
StoHelp::readStopVector(ret, result);
383
return result;
384
}
385
386
std::string
387
Vehicle::getStopParameter(const std::string& vehID, int nextStopIndex, const std::string& param, bool customParam) {
388
tcpip::Storage content;
389
StoHelp::writeCompound(content, 3);
390
StoHelp::writeTypedInt(content, nextStopIndex);
391
StoHelp::writeTypedString(content, param);
392
StoHelp::writeTypedByte(content, customParam);
393
return Dom::getString(libsumo::VAR_STOP_PARAMETER, vehID, &content);
394
}
395
396
int
397
Vehicle::getStopState(const std::string& vehID) {
398
return Dom::getInt(libsumo::VAR_STOPSTATE, vehID);
399
}
400
401
402
double
403
Vehicle::getDistance(const std::string& vehID) {
404
return Dom::getDouble(libsumo::VAR_DISTANCE, vehID);
405
}
406
407
408
double
409
Vehicle::getDrivingDistance(const std::string& vehID, const std::string& edgeID, double pos, int laneIndex) {
410
tcpip::Storage content;
411
StoHelp::writeCompound(content, 2);
412
content.writeUnsignedByte(libsumo::POSITION_ROADMAP);
413
content.writeString(edgeID);
414
content.writeDouble(pos);
415
content.writeUnsignedByte(laneIndex);
416
content.writeUnsignedByte(libsumo::REQUEST_DRIVINGDIST);
417
return Dom::getDouble(libsumo::DISTANCE_REQUEST, vehID, &content);
418
}
419
420
421
double
422
Vehicle::getDrivingDistance2D(const std::string& vehID, double x, double y) {
423
tcpip::Storage content;
424
StoHelp::writeCompound(content, 2);
425
content.writeUnsignedByte(libsumo::POSITION_2D);
426
content.writeDouble(x);
427
content.writeDouble(y);
428
content.writeUnsignedByte(libsumo::REQUEST_DRIVINGDIST);
429
return Dom::getDouble(libsumo::DISTANCE_REQUEST, vehID, &content);
430
}
431
432
433
double
434
Vehicle::getAllowedSpeed(const std::string& vehID) {
435
return Dom::getDouble(libsumo::VAR_ALLOWED_SPEED, vehID);
436
}
437
438
439
double
440
Vehicle::getSpeedFactor(const std::string& vehID) {
441
return Dom::getDouble(libsumo::VAR_SPEED_FACTOR, vehID);
442
}
443
444
445
int
446
Vehicle::getSpeedMode(const std::string& vehID) {
447
return Dom::getInt(libsumo::VAR_SPEEDSETMODE, vehID);
448
}
449
450
451
int
452
Vehicle::getLaneChangeMode(const std::string& vehID) {
453
return Dom::getInt(libsumo::VAR_LANECHANGE_MODE, vehID);
454
}
455
456
457
int
458
Vehicle::getRoutingMode(const std::string& vehID) {
459
return Dom::getInt(libsumo::VAR_ROUTING_MODE, vehID);
460
}
461
462
463
std::string
464
Vehicle::getLine(const std::string& vehID) {
465
return Dom::getString(libsumo::VAR_LINE, vehID);
466
}
467
468
469
470
std::vector<std::string>
471
Vehicle::getVia(const std::string& vehID) {
472
return Dom::getStringVector(libsumo::VAR_VIA, vehID);
473
}
474
475
476
std::pair<int, int>
477
Vehicle::getLaneChangeState(const std::string& vehID, int direction) {
478
tcpip::Storage content;
479
StoHelp::writeTypedInt(content, direction);
480
std::unique_lock<std::mutex> lock{ libtraci::Connection::getActive().getMutex() };
481
tcpip::Storage& ret = Dom::get(libsumo::CMD_CHANGELANE, vehID, &content);
482
ret.readInt(); // components
483
const int stateWithoutTraCI = StoHelp::readTypedInt(ret);
484
const int state = StoHelp::readTypedInt(ret);
485
return std::make_pair(stateWithoutTraCI, state);
486
}
487
488
489
std::vector<std::pair<std::string, double> >
490
Vehicle::getNeighbors(const std::string& vehID, const int mode) {
491
std::vector<std::pair<std::string, double> > neighs;
492
tcpip::Storage content;
493
content.writeUnsignedByte(libsumo::TYPE_UBYTE);
494
content.writeUnsignedByte(mode);
495
std::unique_lock<std::mutex> lock{ libtraci::Connection::getActive().getMutex() };
496
tcpip::Storage& ret = Dom::get(libsumo::VAR_NEIGHBORS, vehID, &content);
497
const int items = ret.readInt(); // components
498
for (int i = 0; i < items; i++) {
499
const std::string neighID = ret.readString();
500
neighs.emplace_back(neighID, ret.readDouble());
501
}
502
return neighs;
503
}
504
505
506
double
507
Vehicle::getFollowSpeed(const std::string& vehID, double speed, double gap, double leaderSpeed, double leaderMaxDecel, const std::string& leaderID) {
508
tcpip::Storage content;
509
StoHelp::writeCompound(content, 5);
510
StoHelp::writeTypedDouble(content, speed);
511
StoHelp::writeTypedDouble(content, gap);
512
StoHelp::writeTypedDouble(content, leaderSpeed);
513
StoHelp::writeTypedDouble(content, leaderMaxDecel);
514
StoHelp::writeTypedString(content, leaderID);
515
return Dom::getDouble(libsumo::VAR_FOLLOW_SPEED, vehID, &content);
516
}
517
518
519
double
520
Vehicle::getSecureGap(const std::string& vehID, double speed, double leaderSpeed, double leaderMaxDecel, const std::string& leaderID) {
521
tcpip::Storage content;
522
StoHelp::writeCompound(content, 4);
523
StoHelp::writeTypedDouble(content, speed);
524
StoHelp::writeTypedDouble(content, leaderSpeed);
525
StoHelp::writeTypedDouble(content, leaderMaxDecel);
526
StoHelp::writeTypedString(content, leaderID);
527
return Dom::getDouble(libsumo::VAR_SECURE_GAP, vehID, &content);
528
}
529
530
531
double
532
Vehicle::getStopSpeed(const std::string& vehID, const double speed, double gap) {
533
tcpip::Storage content;
534
StoHelp::writeCompound(content, 2);
535
StoHelp::writeTypedDouble(content, speed);
536
StoHelp::writeTypedDouble(content, gap);
537
return Dom::getDouble(libsumo::VAR_STOP_SPEED, vehID, &content);
538
}
539
540
double
541
Vehicle::getStopDelay(const std::string& vehID) {
542
return Dom::getDouble(libsumo::VAR_STOP_DELAY, vehID);
543
}
544
545
double
546
Vehicle::getStopArrivalDelay(const std::string& vehID) {
547
return Dom::getDouble(libsumo::VAR_STOP_ARRIVALDELAY, vehID);
548
}
549
550
double
551
Vehicle::getTimeLoss(const std::string& vehID) {
552
return Dom::getDouble(libsumo::VAR_TIMELOSS, vehID);
553
}
554
555
std::vector<std::string>
556
Vehicle::getTaxiFleet(int taxiState) {
557
tcpip::Storage content;
558
StoHelp::writeTypedInt(content, taxiState);
559
return Dom::getStringVector(libsumo::VAR_TAXI_FLEET, "", &content);
560
}
561
562
std::vector<std::string>
563
Vehicle::getLoadedIDList() {
564
return Dom::getStringVector(libsumo::VAR_LOADED_LIST, "");
565
}
566
567
std::vector<std::string>
568
Vehicle::getTeleportingIDList() {
569
return Dom::getStringVector(libsumo::VAR_TELEPORTING_LIST, "");
570
}
571
572
std::string
573
Vehicle::getEmissionClass(const std::string& vehID) {
574
return Dom::getString(libsumo::VAR_EMISSIONCLASS, vehID);
575
}
576
577
std::string
578
Vehicle::getShapeClass(const std::string& vehID) {
579
return Dom::getString(libsumo::VAR_SHAPECLASS, vehID);
580
}
581
582
583
double
584
Vehicle::getLength(const std::string& vehID) {
585
return Dom::getDouble(libsumo::VAR_LENGTH, vehID);
586
}
587
588
589
double
590
Vehicle::getAccel(const std::string& vehID) {
591
return Dom::getDouble(libsumo::VAR_ACCEL, vehID);
592
}
593
594
595
double
596
Vehicle::getDecel(const std::string& vehID) {
597
return Dom::getDouble(libsumo::VAR_DECEL, vehID);
598
}
599
600
601
double Vehicle::getEmergencyDecel(const std::string& vehID) {
602
return Dom::getDouble(libsumo::VAR_EMERGENCY_DECEL, vehID);
603
}
604
605
606
double Vehicle::getApparentDecel(const std::string& vehID) {
607
return Dom::getDouble(libsumo::VAR_APPARENT_DECEL, vehID);
608
}
609
610
611
double Vehicle::getActionStepLength(const std::string& vehID) {
612
return Dom::getDouble(libsumo::VAR_ACTIONSTEPLENGTH, vehID);
613
}
614
615
616
double Vehicle::getLastActionTime(const std::string& vehID) {
617
return Dom::getDouble(libsumo::VAR_LASTACTIONTIME, vehID);
618
}
619
620
621
double
622
Vehicle::getTau(const std::string& vehID) {
623
return Dom::getDouble(libsumo::VAR_TAU, vehID);
624
}
625
626
627
double
628
Vehicle::getImperfection(const std::string& vehID) {
629
return Dom::getDouble(libsumo::VAR_IMPERFECTION, vehID);
630
}
631
632
633
double
634
Vehicle::getSpeedDeviation(const std::string& vehID) {
635
return Dom::getDouble(libsumo::VAR_SPEED_DEVIATION, vehID);
636
}
637
638
639
std::string
640
Vehicle::getVehicleClass(const std::string& vehID) {
641
return Dom::getString(libsumo::VAR_VEHICLECLASS, vehID);
642
}
643
644
645
double
646
Vehicle::getMinGap(const std::string& vehID) {
647
return Dom::getDouble(libsumo::VAR_MINGAP, vehID);
648
}
649
650
651
double
652
Vehicle::getMinGapLat(const std::string& vehID) {
653
return Dom::getDouble(libsumo::VAR_MINGAP_LAT, vehID);
654
}
655
656
657
double
658
Vehicle::getMaxSpeed(const std::string& vehID) {
659
return Dom::getDouble(libsumo::VAR_MAXSPEED, vehID);
660
}
661
662
663
double
664
Vehicle::getMaxSpeedLat(const std::string& vehID) {
665
return Dom::getDouble(libsumo::VAR_MAXSPEED_LAT, vehID);
666
}
667
668
669
std::string
670
Vehicle::getLateralAlignment(const std::string& vehID) {
671
return Dom::getString(libsumo::VAR_LATALIGNMENT, vehID);
672
}
673
674
675
double
676
Vehicle::getWidth(const std::string& vehID) {
677
return Dom::getDouble(libsumo::VAR_WIDTH, vehID);
678
}
679
680
681
double
682
Vehicle::getHeight(const std::string& vehID) {
683
return Dom::getDouble(libsumo::VAR_HEIGHT, vehID);
684
}
685
686
687
double
688
Vehicle::getMass(const std::string& vehID) {
689
return Dom::getDouble(libsumo::VAR_MASS, vehID);
690
}
691
692
693
void
694
Vehicle::setStop(const std::string& vehID,
695
const std::string& edgeID,
696
double pos,
697
int laneIndex,
698
double duration,
699
int flags,
700
double startPos,
701
double until) {
702
tcpip::Storage content;
703
StoHelp::writeCompound(content, 7);
704
StoHelp::writeTypedString(content, edgeID);
705
StoHelp::writeTypedDouble(content, pos);
706
StoHelp::writeTypedByte(content, laneIndex);
707
StoHelp::writeTypedDouble(content, duration);
708
StoHelp::writeTypedByte(content, flags);
709
StoHelp::writeTypedDouble(content, startPos);
710
StoHelp::writeTypedDouble(content, until);
711
Dom::set(libsumo::CMD_STOP, vehID, &content);
712
}
713
714
715
void
716
Vehicle::replaceStop(const std::string& vehID,
717
int nextStopIndex,
718
const std::string& edgeID,
719
double pos,
720
int laneIndex,
721
double duration,
722
int flags,
723
double startPos,
724
double until,
725
int teleport) {
726
tcpip::Storage content;
727
StoHelp::writeCompound(content, 9);
728
StoHelp::writeTypedString(content, edgeID);
729
StoHelp::writeTypedDouble(content, pos);
730
StoHelp::writeTypedByte(content, laneIndex);
731
StoHelp::writeTypedDouble(content, duration);
732
StoHelp::writeTypedInt(content, flags);
733
StoHelp::writeTypedDouble(content, startPos);
734
StoHelp::writeTypedDouble(content, until);
735
StoHelp::writeTypedInt(content, nextStopIndex);
736
StoHelp::writeTypedByte(content, teleport);
737
Dom::set(libsumo::CMD_REPLACE_STOP, vehID, &content);
738
}
739
740
741
void
742
Vehicle::insertStop(const std::string& vehID,
743
int nextStopIndex,
744
const std::string& edgeID,
745
double pos,
746
int laneIndex,
747
double duration,
748
int flags,
749
double startPos,
750
double until,
751
int teleport) {
752
tcpip::Storage content;
753
StoHelp::writeCompound(content, 9);
754
StoHelp::writeTypedString(content, edgeID);
755
StoHelp::writeTypedDouble(content, pos);
756
StoHelp::writeTypedByte(content, laneIndex);
757
StoHelp::writeTypedDouble(content, duration);
758
StoHelp::writeTypedInt(content, flags);
759
StoHelp::writeTypedDouble(content, startPos);
760
StoHelp::writeTypedDouble(content, until);
761
StoHelp::writeTypedInt(content, nextStopIndex);
762
StoHelp::writeTypedByte(content, teleport);
763
Dom::set(libsumo::CMD_INSERT_STOP, vehID, &content);
764
}
765
766
767
void
768
Vehicle::setStopParameter(const std::string& vehID, int nextStopIndex,
769
const std::string& param, const std::string& value,
770
bool customParam) {
771
tcpip::Storage content;
772
StoHelp::writeCompound(content, 4);
773
StoHelp::writeTypedInt(content, nextStopIndex);
774
StoHelp::writeTypedString(content, param);
775
StoHelp::writeTypedString(content, value);
776
StoHelp::writeTypedByte(content, customParam);
777
Dom::set(libsumo::VAR_STOP_PARAMETER, vehID, &content);
778
}
779
780
781
void
782
Vehicle::rerouteParkingArea(const std::string& vehID, const std::string& parkingAreaID) {
783
tcpip::Storage content;
784
StoHelp::writeCompound(content, 1);
785
StoHelp::writeTypedString(content, parkingAreaID);
786
Dom::set(libsumo::CMD_REROUTE_TO_PARKING, vehID, &content);
787
}
788
789
790
void
791
Vehicle::resume(const std::string& vehID) {
792
tcpip::Storage content;
793
StoHelp::writeCompound(content, 0);
794
Dom::set(libsumo::CMD_RESUME, vehID, &content);
795
}
796
797
798
void
799
Vehicle::changeTarget(const std::string& vehID, const std::string& edgeID) {
800
Dom::setString(libsumo::CMD_CHANGETARGET, vehID, edgeID);
801
}
802
803
804
void
805
Vehicle::changeLane(const std::string& vehID, int laneIndex, double duration) {
806
tcpip::Storage content;
807
StoHelp::writeCompound(content, 2);
808
StoHelp::writeTypedByte(content, laneIndex);
809
StoHelp::writeTypedDouble(content, duration);
810
Dom::set(libsumo::CMD_CHANGELANE, vehID, &content);
811
}
812
813
void
814
Vehicle::changeLaneRelative(const std::string& vehID, int indexOffset, double duration) {
815
tcpip::Storage content;
816
StoHelp::writeCompound(content, 3);
817
StoHelp::writeTypedByte(content, indexOffset);
818
StoHelp::writeTypedDouble(content, duration);
819
StoHelp::writeTypedByte(content, 1);
820
Dom::set(libsumo::CMD_CHANGELANE, vehID, &content);
821
}
822
823
824
void
825
Vehicle::changeSublane(const std::string& vehID, double latDist) {
826
Dom::setDouble(libsumo::CMD_CHANGESUBLANE, vehID, latDist);
827
}
828
829
830
void
831
Vehicle::add(const std::string& vehID,
832
const std::string& routeID,
833
const std::string& typeID,
834
const std::string& depart,
835
const std::string& departLane,
836
const std::string& departPos,
837
const std::string& departSpeed,
838
const std::string& arrivalLane,
839
const std::string& arrivalPos,
840
const std::string& arrivalSpeed,
841
const std::string& fromTaz,
842
const std::string& toTaz,
843
const std::string& line,
844
int personCapacity,
845
int personNumber) {
846
tcpip::Storage content;
847
StoHelp::writeCompound(content, 14);
848
StoHelp::writeTypedString(content, routeID);
849
StoHelp::writeTypedString(content, typeID);
850
StoHelp::writeTypedString(content, depart);
851
StoHelp::writeTypedString(content, departLane);
852
StoHelp::writeTypedString(content, departPos);
853
StoHelp::writeTypedString(content, departSpeed);
854
855
StoHelp::writeTypedString(content, arrivalLane);
856
StoHelp::writeTypedString(content, arrivalPos);
857
StoHelp::writeTypedString(content, arrivalSpeed);
858
859
StoHelp::writeTypedString(content, fromTaz);
860
StoHelp::writeTypedString(content, toTaz);
861
StoHelp::writeTypedString(content, line);
862
863
StoHelp::writeTypedInt(content, personCapacity);
864
StoHelp::writeTypedInt(content, personNumber);
865
866
Dom::set(libsumo::ADD_FULL, vehID, &content);
867
}
868
869
870
void
871
Vehicle::moveToXY(const std::string& vehID, const std::string& edgeID, const int laneIndex,
872
const double x, const double y, double angle, const int keepRoute, double matchThreshold) {
873
tcpip::Storage content;
874
StoHelp::writeCompound(content, 7);
875
StoHelp::writeTypedString(content, edgeID);
876
StoHelp::writeTypedInt(content, laneIndex);
877
StoHelp::writeTypedDouble(content, x);
878
StoHelp::writeTypedDouble(content, y);
879
StoHelp::writeTypedDouble(content, angle);
880
StoHelp::writeTypedByte(content, keepRoute);
881
StoHelp::writeTypedDouble(content, matchThreshold);
882
Dom::set(libsumo::MOVE_TO_XY, vehID, &content);
883
}
884
885
void
886
Vehicle::slowDown(const std::string& vehID, double speed, double duration) {
887
tcpip::Storage content;
888
StoHelp::writeCompound(content, 2);
889
StoHelp::writeTypedDouble(content, speed);
890
StoHelp::writeTypedDouble(content, duration);
891
Dom::set(libsumo::CMD_SLOWDOWN, vehID, &content);
892
}
893
894
void
895
Vehicle::openGap(const std::string& vehID, double newTimeHeadway, double newSpaceHeadway, double duration, double changeRate, double maxDecel, const std::string& referenceVehID) {
896
tcpip::Storage content;
897
StoHelp::writeCompound(content, referenceVehID != "" ? 6 : 5);
898
StoHelp::writeTypedDouble(content, newTimeHeadway);
899
StoHelp::writeTypedDouble(content, newSpaceHeadway);
900
StoHelp::writeTypedDouble(content, duration);
901
StoHelp::writeTypedDouble(content, changeRate);
902
StoHelp::writeTypedDouble(content, maxDecel);
903
if (referenceVehID != "") {
904
StoHelp::writeTypedString(content, referenceVehID);
905
}
906
Dom::set(libsumo::CMD_OPENGAP, vehID, &content);
907
}
908
909
void
910
Vehicle::deactivateGapControl(const std::string& vehID) {
911
openGap(vehID, -1, -1, -1, -1);
912
}
913
914
void
915
Vehicle::requestToC(const std::string& vehID, double leadTime) {
916
std::ostringstream oss;
917
oss.setf(std::ios::fixed, std::ios::floatfield);
918
oss << std::setprecision(2);
919
oss << leadTime;
920
setParameter(vehID, "device.toc.requestToC", oss.str());
921
}
922
923
void
924
Vehicle::setSpeed(const std::string& vehID, double speed) {
925
Dom::setDouble(libsumo::VAR_SPEED, vehID, speed);
926
}
927
928
void
929
Vehicle::setAcceleration(const std::string& vehID, double acceleration, double duration) {
930
tcpip::Storage content;
931
StoHelp::writeCompound(content, 2);
932
StoHelp::writeTypedDouble(content, acceleration);
933
StoHelp::writeTypedDouble(content, duration);
934
Dom::set(libsumo::VAR_ACCELERATION, vehID, &content);
935
}
936
937
void
938
Vehicle::setPreviousSpeed(const std::string& vehID, double prevSpeed, double prevAcceleration) {
939
tcpip::Storage content;
940
StoHelp::writeCompound(content, 2);
941
StoHelp::writeTypedDouble(content, prevSpeed);
942
StoHelp::writeTypedDouble(content, prevAcceleration);
943
Dom::set(libsumo::VAR_PREV_SPEED, vehID, &content);
944
}
945
946
void
947
Vehicle::setSpeedMode(const std::string& vehID, int speedMode) {
948
Dom::setInt(libsumo::VAR_SPEEDSETMODE, vehID, speedMode);
949
}
950
951
void
952
Vehicle::setLaneChangeMode(const std::string& vehID, int laneChangeMode) {
953
Dom::setInt(libsumo::VAR_LANECHANGE_MODE, vehID, laneChangeMode);
954
}
955
956
void
957
Vehicle::setRoutingMode(const std::string& vehID, int routingMode) {
958
Dom::setInt(libsumo::VAR_ROUTING_MODE, vehID, routingMode);
959
}
960
961
void
962
Vehicle::setType(const std::string& vehID, const std::string& typeID) {
963
Dom::setString(libsumo::VAR_TYPE, vehID, typeID);
964
}
965
966
void
967
Vehicle::setRouteID(const std::string& vehID, const std::string& routeID) {
968
Dom::setString(libsumo::VAR_ROUTE_ID, vehID, routeID);
969
}
970
971
void
972
Vehicle::setRoute(const std::string& vehID, const std::string& edgeID) {
973
setRoute(vehID, std::vector<std::string>({edgeID}));
974
}
975
976
void
977
Vehicle::setRoute(const std::string& vehID, const std::vector<std::string>& edgeIDs) {
978
Dom::setStringVector(libsumo::VAR_ROUTE, vehID, edgeIDs);
979
}
980
981
void
982
Vehicle::setLateralLanePosition(const std::string& vehID, double posLat) {
983
Dom::setDouble(libsumo::VAR_LANEPOSITION_LAT, vehID, posLat);
984
}
985
986
void
987
Vehicle::updateBestLanes(const std::string& vehID) {
988
tcpip::Storage content;
989
Dom::set(libsumo::VAR_UPDATE_BESTLANES, vehID, &content);
990
}
991
992
993
void
994
Vehicle::setAdaptedTraveltime(const std::string& vehID, const std::string& edgeID,
995
double time, double begSeconds, double endSeconds) {
996
tcpip::Storage content;
997
if (time == libsumo::INVALID_DOUBLE_VALUE) {
998
// reset
999
StoHelp::writeCompound(content, 1);
1000
StoHelp::writeTypedString(content, edgeID);
1001
} else if (begSeconds == libsumo::INVALID_DOUBLE_VALUE) {
1002
// set value for the whole simulation
1003
StoHelp::writeCompound(content, 2);
1004
StoHelp::writeTypedString(content, edgeID);
1005
StoHelp::writeTypedDouble(content, time);
1006
} else {
1007
StoHelp::writeCompound(content, 4);
1008
StoHelp::writeTypedDouble(content, begSeconds);
1009
StoHelp::writeTypedDouble(content, endSeconds);
1010
StoHelp::writeTypedString(content, edgeID);
1011
StoHelp::writeTypedDouble(content, time);
1012
}
1013
Dom::set(libsumo::VAR_EDGE_TRAVELTIME, vehID, &content);
1014
}
1015
1016
1017
void
1018
Vehicle::setEffort(const std::string& vehID, const std::string& edgeID,
1019
double effort, double begSeconds, double endSeconds) {
1020
tcpip::Storage content;
1021
if (effort == libsumo::INVALID_DOUBLE_VALUE) {
1022
// reset
1023
StoHelp::writeCompound(content, 1);
1024
StoHelp::writeTypedString(content, edgeID);
1025
} else if (begSeconds == libsumo::INVALID_DOUBLE_VALUE) {
1026
// set value for the whole simulation
1027
StoHelp::writeCompound(content, 2);
1028
StoHelp::writeTypedString(content, edgeID);
1029
StoHelp::writeTypedDouble(content, effort);
1030
} else {
1031
StoHelp::writeCompound(content, 4);
1032
StoHelp::writeTypedDouble(content, begSeconds);
1033
StoHelp::writeTypedDouble(content, endSeconds);
1034
StoHelp::writeTypedString(content, edgeID);
1035
StoHelp::writeTypedDouble(content, effort);
1036
}
1037
Dom::set(libsumo::VAR_EDGE_EFFORT, vehID, &content);
1038
}
1039
1040
1041
void
1042
Vehicle::rerouteTraveltime(const std::string& vehID, const bool /* currentTravelTimes */) {
1043
tcpip::Storage content;
1044
StoHelp::writeCompound(content, 0);
1045
Dom::set(libsumo::CMD_REROUTE_TRAVELTIME, vehID, &content);
1046
}
1047
1048
1049
void
1050
Vehicle::rerouteEffort(const std::string& vehID) {
1051
tcpip::Storage content;
1052
StoHelp::writeCompound(content, 0);
1053
Dom::set(libsumo::CMD_REROUTE_EFFORT, vehID, &content);
1054
}
1055
1056
1057
void
1058
Vehicle::setSignals(const std::string& vehID, int signals) {
1059
Dom::setInt(libsumo::VAR_SIGNALS, vehID, signals);
1060
}
1061
1062
1063
void
1064
Vehicle::moveTo(const std::string& vehID, const std::string& laneID, double pos, int reason) {
1065
tcpip::Storage content;
1066
StoHelp::writeCompound(content, 3);
1067
StoHelp::writeTypedString(content, laneID);
1068
StoHelp::writeTypedDouble(content, pos);
1069
StoHelp::writeTypedInt(content, reason);
1070
Dom::set(libsumo::VAR_MOVE_TO, vehID, &content);
1071
}
1072
1073
1074
void
1075
Vehicle::setActionStepLength(const std::string& vehID, double actionStepLength, bool resetActionOffset) {
1076
//if (actionStepLength < 0) {
1077
// raise TraCIException("Invalid value for actionStepLength. Given value must be non-negative.")
1078
//{
1079
// Use negative value to indicate resetActionOffset == False
1080
if (!resetActionOffset) {
1081
actionStepLength *= -1;
1082
}
1083
Dom::setDouble(libsumo::VAR_ACTIONSTEPLENGTH, vehID, actionStepLength);
1084
}
1085
1086
1087
void
1088
Vehicle::remove(const std::string& vehID, char reason) {
1089
tcpip::Storage content;
1090
content.writeUnsignedByte(libsumo::TYPE_BYTE);
1091
content.writeUnsignedByte(reason);
1092
Dom::set(libsumo::REMOVE, vehID, &content);
1093
}
1094
1095
1096
void
1097
Vehicle::setColor(const std::string& vehID, const libsumo::TraCIColor& color) {
1098
Dom::setCol(libsumo::VAR_COLOR, vehID, color);
1099
}
1100
1101
1102
void
1103
Vehicle::setSpeedFactor(const std::string& vehID, double factor) {
1104
Dom::setDouble(libsumo::VAR_SPEED_FACTOR, vehID, factor);
1105
}
1106
1107
1108
void
1109
Vehicle::setLine(const std::string& vehID, const std::string& line) {
1110
Dom::setString(libsumo::VAR_LINE, vehID, line);
1111
}
1112
1113
1114
void
1115
Vehicle::setVia(const std::string& vehID, const std::vector<std::string>& edgeList) {
1116
Dom::setStringVector(libsumo::VAR_VIA, vehID, edgeList);
1117
}
1118
1119
1120
void
1121
Vehicle::setLength(const std::string& vehID, double length) {
1122
Dom::setDouble(libsumo::VAR_LENGTH, vehID, length);
1123
}
1124
1125
1126
void
1127
Vehicle::setMaxSpeed(const std::string& vehID, double speed) {
1128
Dom::setDouble(libsumo::VAR_MAXSPEED, vehID, speed);
1129
}
1130
1131
1132
void
1133
Vehicle::setVehicleClass(const std::string& vehID, const std::string& clazz) {
1134
Dom::setString(libsumo::VAR_VEHICLECLASS, vehID, clazz);
1135
}
1136
1137
1138
void
1139
Vehicle::setShapeClass(const std::string& vehID, const std::string& clazz) {
1140
Dom::setString(libsumo::VAR_SHAPECLASS, vehID, clazz);
1141
}
1142
1143
1144
void
1145
Vehicle::setEmissionClass(const std::string& vehID, const std::string& clazz) {
1146
Dom::setString(libsumo::VAR_EMISSIONCLASS, vehID, clazz);
1147
}
1148
1149
1150
void
1151
Vehicle::setWidth(const std::string& vehID, double width) {
1152
Dom::setDouble(libsumo::VAR_WIDTH, vehID, width);
1153
}
1154
1155
1156
void
1157
Vehicle::setHeight(const std::string& vehID, double height) {
1158
Dom::setDouble(libsumo::VAR_HEIGHT, vehID, height);
1159
}
1160
1161
1162
void
1163
Vehicle::setMass(const std::string& vehID, double mass) {
1164
Dom::setDouble(libsumo::VAR_MASS, vehID, mass);
1165
}
1166
1167
1168
void
1169
Vehicle::setMinGap(const std::string& vehID, double minGap) {
1170
Dom::setDouble(libsumo::VAR_MINGAP, vehID, minGap);
1171
}
1172
1173
1174
void
1175
Vehicle::setAccel(const std::string& vehID, double accel) {
1176
Dom::setDouble(libsumo::VAR_ACCEL, vehID, accel);
1177
}
1178
1179
1180
void
1181
Vehicle::setDecel(const std::string& vehID, double decel) {
1182
Dom::setDouble(libsumo::VAR_DECEL, vehID, decel);
1183
}
1184
1185
1186
void
1187
Vehicle::setEmergencyDecel(const std::string& vehID, double decel) {
1188
Dom::setDouble(libsumo::VAR_EMERGENCY_DECEL, vehID, decel);
1189
}
1190
1191
1192
void
1193
Vehicle::setApparentDecel(const std::string& vehID, double decel) {
1194
Dom::setDouble(libsumo::VAR_APPARENT_DECEL, vehID, decel);
1195
}
1196
1197
1198
void
1199
Vehicle::setImperfection(const std::string& vehID, double imperfection) {
1200
Dom::setDouble(libsumo::VAR_IMPERFECTION, vehID, imperfection);
1201
}
1202
1203
1204
void
1205
Vehicle::setTau(const std::string& vehID, double tau) {
1206
Dom::setDouble(libsumo::VAR_TAU, vehID, tau);
1207
}
1208
1209
1210
void
1211
Vehicle::setMinGapLat(const std::string& vehID, double minGapLat) {
1212
Dom::setDouble(libsumo::VAR_MINGAP_LAT, vehID, minGapLat);
1213
}
1214
1215
1216
void
1217
Vehicle::setMaxSpeedLat(const std::string& vehID, double speed) {
1218
Dom::setDouble(libsumo::VAR_MAXSPEED_LAT, vehID, speed);
1219
}
1220
1221
1222
void
1223
Vehicle::setLateralAlignment(const std::string& vehID, const std::string& latAlignment) {
1224
Dom::setString(libsumo::VAR_LATALIGNMENT, vehID, latAlignment);
1225
}
1226
1227
1228
void
1229
Vehicle::setImpatience(const std::string& vehID, double impatience) {
1230
Dom::setDouble(libsumo::VAR_IMPATIENCE, vehID, impatience);
1231
}
1232
1233
void
1234
Vehicle::setBoardingDuration(const std::string& vehID, double boardingDuration) {
1235
Dom::setDouble(libsumo::VAR_BOARDING_DURATION, vehID, boardingDuration);
1236
}
1237
1238
1239
void
1240
Vehicle::highlight(const std::string& vehID, const libsumo::TraCIColor& col, double size, const int alphaMax, const double duration, const int type) {
1241
tcpip::Storage content;
1242
StoHelp::writeCompound(content, alphaMax > 0 ? 5 : 2);
1243
content.writeUnsignedByte(libsumo::TYPE_COLOR);
1244
content.writeUnsignedByte(col.r);
1245
content.writeUnsignedByte(col.g);
1246
content.writeUnsignedByte(col.b);
1247
content.writeUnsignedByte(col.a);
1248
StoHelp::writeTypedDouble(content, size);
1249
if (alphaMax > 0) {
1250
content.writeUnsignedByte(libsumo::TYPE_UBYTE);
1251
content.writeUnsignedByte(alphaMax);
1252
StoHelp::writeTypedDouble(content, duration);
1253
content.writeUnsignedByte(libsumo::TYPE_UBYTE);
1254
content.writeUnsignedByte(type);
1255
}
1256
Dom::set(libsumo::VAR_HIGHLIGHT, vehID, &content);
1257
}
1258
1259
void
1260
Vehicle::dispatchTaxi(const std::string& vehID, const std::vector<std::string>& reservations) {
1261
Dom::setStringVector(libsumo::CMD_TAXI_DISPATCH, vehID, reservations);
1262
}
1263
1264
1265
void
1266
Vehicle::subscribeLeader(const std::string& vehID, double dist, double begin, double end) {
1267
subscribe(vehID, std::vector<int>({ libsumo::VAR_LEADER }), begin, end,
1268
libsumo::TraCIResults({ {libsumo::VAR_LEADER, std::make_shared<libsumo::TraCIDouble>(dist)} }));
1269
}
1270
1271
1272
void
1273
Vehicle::addSubscriptionFilterLanes(const std::vector<int>& lanes, bool noOpposite, double downstreamDist, double upstreamDist) {
1274
tcpip::Storage content;
1275
content.writeUnsignedByte((int)lanes.size());
1276
for (int lane : lanes) {
1277
content.writeUnsignedByte(lane < 0 ? lane + 256 : lane);
1278
}
1279
libtraci::Connection::getActive().addFilter(libsumo::FILTER_TYPE_LANES, &content);
1280
if (noOpposite) {
1281
addSubscriptionFilterNoOpposite();
1282
}
1283
if (downstreamDist != libsumo::INVALID_DOUBLE_VALUE) {
1284
addSubscriptionFilterDownstreamDistance(downstreamDist);
1285
}
1286
if (upstreamDist != libsumo::INVALID_DOUBLE_VALUE) {
1287
addSubscriptionFilterUpstreamDistance(upstreamDist);
1288
}
1289
}
1290
1291
1292
void
1293
Vehicle::addSubscriptionFilterNoOpposite() {
1294
libtraci::Connection::getActive().addFilter(libsumo::FILTER_TYPE_NOOPPOSITE);
1295
}
1296
1297
1298
void
1299
Vehicle::addSubscriptionFilterDownstreamDistance(double dist) {
1300
tcpip::Storage content;
1301
StoHelp::writeTypedDouble(content, dist);
1302
libtraci::Connection::getActive().addFilter(libsumo::FILTER_TYPE_DOWNSTREAM_DIST, &content);
1303
}
1304
1305
1306
void
1307
Vehicle::addSubscriptionFilterUpstreamDistance(double dist) {
1308
tcpip::Storage content;
1309
StoHelp::writeTypedDouble(content, dist);
1310
libtraci::Connection::getActive().addFilter(libsumo::FILTER_TYPE_UPSTREAM_DIST, &content);
1311
}
1312
1313
1314
void
1315
Vehicle::addSubscriptionFilterCFManeuver(double downstreamDist, double upstreamDist) {
1316
addSubscriptionFilterLeadFollow(std::vector<int>(1));
1317
if (downstreamDist != libsumo::INVALID_DOUBLE_VALUE) {
1318
addSubscriptionFilterDownstreamDistance(downstreamDist);
1319
}
1320
if (upstreamDist != libsumo::INVALID_DOUBLE_VALUE) {
1321
addSubscriptionFilterUpstreamDistance(upstreamDist);
1322
}
1323
}
1324
1325
1326
void
1327
Vehicle::addSubscriptionFilterLCManeuver(int direction, bool noOpposite, double downstreamDist, double upstreamDist) {
1328
if (direction == libsumo::INVALID_INT_VALUE) {
1329
addSubscriptionFilterLeadFollow({ -1, 0, 1 });
1330
} else if (direction != -1 && direction != 1) {
1331
// warnings.warn("Ignoring lane change subscription filter with non-neighboring lane offset direction=%s." % direction)
1332
return;
1333
} else {
1334
addSubscriptionFilterLeadFollow({ 0, direction });
1335
}
1336
if (noOpposite) {
1337
addSubscriptionFilterNoOpposite();
1338
}
1339
if (downstreamDist != libsumo::INVALID_DOUBLE_VALUE) {
1340
addSubscriptionFilterDownstreamDistance(downstreamDist);
1341
}
1342
if (upstreamDist != libsumo::INVALID_DOUBLE_VALUE) {
1343
addSubscriptionFilterUpstreamDistance(upstreamDist);
1344
}
1345
}
1346
1347
1348
void
1349
Vehicle::addSubscriptionFilterLeadFollow(const std::vector<int>& lanes) {
1350
libtraci::Connection::getActive().addFilter(libsumo::FILTER_TYPE_LEAD_FOLLOW);
1351
addSubscriptionFilterLanes(lanes);
1352
}
1353
1354
1355
void
1356
Vehicle::addSubscriptionFilterTurn(double downstreamDist, double foeDistToJunction) {
1357
tcpip::Storage content;
1358
StoHelp::writeTypedDouble(content, foeDistToJunction);
1359
libtraci::Connection::getActive().addFilter(libsumo::FILTER_TYPE_TURN, &content);
1360
if (downstreamDist != libsumo::INVALID_DOUBLE_VALUE) {
1361
addSubscriptionFilterDownstreamDistance(downstreamDist);
1362
}
1363
}
1364
1365
1366
void
1367
Vehicle::addSubscriptionFilterVClass(const std::vector<std::string>& vClasses) {
1368
tcpip::Storage content;
1369
StoHelp::writeTypedStringList(content, vClasses);
1370
libtraci::Connection::getActive().addFilter(libsumo::FILTER_TYPE_VCLASS, &content);
1371
}
1372
1373
1374
void
1375
Vehicle::addSubscriptionFilterVType(const std::vector<std::string>& vTypes) {
1376
tcpip::Storage content;
1377
StoHelp::writeTypedStringList(content, vTypes);
1378
libtraci::Connection::getActive().addFilter(libsumo::FILTER_TYPE_VTYPE, &content);
1379
}
1380
1381
1382
void
1383
Vehicle::addSubscriptionFilterFieldOfVision(double openingAngle) {
1384
tcpip::Storage content;
1385
StoHelp::writeTypedDouble(content, openingAngle);
1386
libtraci::Connection::getActive().addFilter(libsumo::FILTER_TYPE_FIELD_OF_VISION, &content);
1387
}
1388
1389
1390
void
1391
Vehicle::addSubscriptionFilterLateralDistance(double lateralDist, double downstreamDist, double upstreamDist) {
1392
tcpip::Storage content;
1393
StoHelp::writeTypedDouble(content, lateralDist);
1394
libtraci::Connection::getActive().addFilter(libsumo::FILTER_TYPE_LATERAL_DIST, &content);
1395
if (downstreamDist != libsumo::INVALID_DOUBLE_VALUE) {
1396
addSubscriptionFilterDownstreamDistance(downstreamDist);
1397
}
1398
if (upstreamDist != libsumo::INVALID_DOUBLE_VALUE) {
1399
addSubscriptionFilterUpstreamDistance(upstreamDist);
1400
}
1401
}
1402
1403
1404
}
1405
1406
1407
/****************************************************************************/
1408
1409