forked from RobotLocomotion/drake
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathidm_controller.h
138 lines (118 loc) · 4.98 KB
/
idm_controller.h
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
#pragma once
#include <memory>
#include <vector>
#include <Eigen/Geometry>
#include "drake/automotive/calc_ongoing_road_position.h"
#include "drake/automotive/gen/idm_planner_parameters.h"
#include "drake/automotive/idm_planner.h"
#include "drake/automotive/maliput/api/lane_data.h"
#include "drake/automotive/maliput/api/road_geometry.h"
#include "drake/automotive/pose_selector.h"
#include "drake/common/drake_copyable.h"
#include "drake/systems/framework/leaf_system.h"
#include "drake/systems/rendering/pose_bundle.h"
#include "drake/systems/rendering/pose_vector.h"
namespace drake {
namespace automotive {
/// IdmController implements the IDM (Intelligent Driver Model) planner,
/// computed based only on the nearest car ahead. See IdmPlanner and
/// PoseSelector for details. The output of this block is an acceleration value
/// passed as a command to the vehicle.
///
/// Input Port 0: PoseVector for the ego car.
/// (InputPort getter: ego_pose_input())
///
/// Input Port 1: FrameVelocity of the ego car.
/// (InputPort getter: ego_velocity_input())
///
/// Input Port 2: PoseBundle for the traffic cars, possibly inclusive of the ego
/// car's pose.
/// (InputPort getter: traffic_input())
///
/// Output Port 0: A BasicVector containing the acceleration request.
/// (OutputPort getter: acceleration_output())
///
/// Instantiated templates for the following kinds of T's are provided:
///
/// - double
/// - AutoDiffXd
///
/// They are already available to link against in the containing library.
///
/// @ingroup automotive_controllers
template <typename T>
class IdmController : public systems::LeafSystem<T> {
public:
DRAKE_NO_COPY_NO_MOVE_NO_ASSIGN(IdmController)
/// Constructor.
/// @param road The pre-defined RoadGeometry.
/// @param path_or_branches If ScanStrategy::kBranches, performs IDM
/// computations using vehicles detected in confluent branches; if
/// ScanStrategy::kPath, limits to vehicles on the default path. See
/// documentation for PoseSelector::FindSingleClosestPose().
/// @param road_position_strategy Determines whether or not to cache
/// RoadPosition. See `calc_ongoing_road_position.h`.
/// @param period_sec The update period to use if road_position_strategy ==
/// RoadPositionStrategy::kCache.
IdmController(const maliput::api::RoadGeometry& road,
ScanStrategy path_or_branches,
RoadPositionStrategy road_position_strategy,
double period_sec);
/// Scalar-converting copy constructor. See @ref system_scalar_conversion.
template <typename U>
explicit IdmController(const IdmController<U>& other)
: IdmController<T>(other.road_, other.path_or_branches_,
other.road_position_strategy_,
other.period_sec_) {}
~IdmController() override;
/// See the class description for details on the following input ports.
/// @{
const systems::InputPort<T>& ego_pose_input() const;
const systems::InputPort<T>& ego_velocity_input() const;
const systems::InputPort<T>& traffic_input() const;
const systems::OutputPort<T>& acceleration_output() const;
/// @}
protected:
const maliput::api::RoadGeometry& road() const { return road_; }
int ego_pose_index() const { return ego_pose_index_; }
int ego_velocity_index() const { return ego_velocity_index_; }
int traffic_index() const { return traffic_index_; }
int acceleration_index() const { return acceleration_index_; }
void ImplCalcAcceleration(
const systems::rendering::PoseVector<T>& ego_pose,
const systems::rendering::FrameVelocity<T>& ego_velocity,
const systems::rendering::PoseBundle<T>& traffic_poses,
const IdmPlannerParameters<T>& idm_params,
const maliput::api::RoadPosition& ego_rp,
systems::BasicVector<T>* command) const;
void DoCalcUnrestrictedUpdate(
const systems::Context<T>& context,
const std::vector<const systems::UnrestrictedUpdateEvent<T>*>&,
systems::State<T>* state) const override;
private:
// Allow different specializations to access each other's private data.
template <typename> friend class IdmController;
// Converts @p pose into RoadPosition.
const maliput::api::RoadPosition GetRoadPosition(
const Isometry3<T>& pose) const;
void CalcAcceleration(const systems::Context<T>& context,
systems::BasicVector<T>* accel_output) const;
const maliput::api::RoadGeometry& road_;
const ScanStrategy path_or_branches_{};
const RoadPositionStrategy road_position_strategy_{};
const double period_sec_{};
// Indices for the input / output ports.
const int ego_pose_index_{};
const int ego_velocity_index_{};
const int traffic_index_{};
const int acceleration_index_{};
};
} // namespace automotive
namespace systems {
namespace scalar_conversion {
// Disable symbolic support, because we use ExtractDoubleOrThrow.
template <>
struct Traits<automotive::IdmController> : public NonSymbolicTraits {};
} // namespace scalar_conversion
} // namespace systems
} // namespace drake