-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathidm_controller2.h
93 lines (79 loc) · 3.22 KB
/
idm_controller2.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
#pragma once
#include <memory>
#include <Eigen/Geometry>
#include "drake/automotive/gen/idm_planner_parameters.h"
#include "drake/automotive/idm_planner2.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.
///
/// Instantiated templates for the following kinds of T's are provided:
/// - double
///
/// They are already available to link against in the containing library.
///
/// Input Port 0: PoseVector for the ego car.
/// (InputPortDescriptor getter: ego_pose_input())
///
/// Input Port 1: FrameVelocity of the ego car.
/// (InputPortDescriptor getter: ego_velocity_input())
///
/// Input Port 2: PoseBundle for the traffic cars, possibly inclusive of the ego
/// car's pose.
/// (InputPortDescriptor getter: traffic_input())
///
/// Output Port 0: A BasicVector containing the acceleration request.
/// OutputPortDescriptor getter: acceleration_output())
///
/// @ingroup automotive_controllers
template <typename T>
class IdmController2 : public systems::LeafSystem<T> {
public:
DRAKE_NO_COPY_NO_MOVE_NO_ASSIGN(IdmController2)
/// Constructor.
/// @param road is the pre-defined RoadGeometry.
explicit IdmController2(const maliput::api::RoadGeometry& road);
~IdmController2() override;
/// See the class description for details on the following input ports.
/// @{
const systems::InputPortDescriptor<T>& ego_pose_input() const;
const systems::InputPortDescriptor<T>& ego_velocity_input() const;
const systems::InputPortDescriptor<T>& traffic_input() const;
const systems::OutputPortDescriptor<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 ImplDoCalcOutput(
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,
systems::BasicVector<T>* command) const;
private:
// Converts @p pose into RoadPosition.
const maliput::api::RoadPosition GetRoadPosition(
const Isometry3<T>& pose) const;
void DoCalcOutput(const systems::Context<T>& context,
systems::SystemOutput<T>* output) const override;
const maliput::api::RoadGeometry& road_;
// 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 drake