-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathtrajectory_agent.h
121 lines (103 loc) · 4.17 KB
/
trajectory_agent.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
#pragma once
#include <Eigen/Geometry>
#include "drake/automotive/agent_trajectory.h"
#include "drake/automotive/gen/simple_car_state.h"
#include "drake/common/drake_copyable.h"
#include "drake/common/extract_double.h"
#include "drake/systems/framework/leaf_system.h"
#include "drake/systems/rendering/frame_velocity.h"
#include "drake/systems/rendering/pose_vector.h"
namespace drake {
namespace automotive {
/// Container for static data for a given agent model.
struct AgentData {
enum class AgentType { kCar, kBicycle, kPedestrian };
// TODO(jadecastro) Add more types as necessary.
explicit AgentData(const AgentType& t) : type(t) {}
AgentType type{AgentType::kCar};
};
// Provide an explicit specialization for the kCar agent type.
struct CarAgent : AgentData {
CarAgent() : AgentData(AgentType::kCar) {}
};
/// TrajectoryAgent models an agent that follows a pre-established trajectory,
/// taking as input an AgentData structure and an AgentTrajectory.
///
/// Note that, when T = AutoDiffXd, the AutoDiffXd derivatives for each element
/// of the the outputs are empty.
///
/// output port 0: A SimpleCarState containing:
/// * position: x, y, heading;
/// heading is 0 rad when pointed +x, pi/2 rad when pointed +y;
/// heading is defined around the +z axis, positive-left-turn.
/// * speed: ṡ = √{ẋ² + ẏ²}
/// (OutputPort getter: raw_pose_output())
///
/// output port 1: A PoseVector containing X_WA, where A is the agent's
/// reference frame.
/// (OutputPort getter: pose_output())
///
/// output port 2: A FrameVelocity containing the spatial velocity V_WA, where A
/// is the agent's reference frame.
/// (OutputPort getter: velocity_output())
///
/// Instantiated templates for the following kinds of T's are provided:
/// - double
/// - drake::AutoDiffXd
///
/// They are already available to link against in the containing library.
///
/// @ingroup automotive_plants
template <typename T>
class TrajectoryAgent final : public systems::LeafSystem<T> {
public:
DRAKE_NO_COPY_NO_MOVE_NO_ASSIGN(TrajectoryAgent)
/// Constructs a TrajectoryAgent system that traces a given AgentTrajectory.
///
/// @param agent_data an AgentData structure defining the agent.
/// @param trajectory an AgentTrajectory containing the trajectory.
/// @param sampling_time_sec the requested sampling time (in sec) for this
/// system. @default 0.01.
TrajectoryAgent(const AgentData& agent_data,
const AgentTrajectory& trajectory,
double sampling_time_sec = 0.01);
/// Scalar-converting copy constructor. See @ref system_scalar_conversion.
template <typename U>
explicit TrajectoryAgent(const TrajectoryAgent<U>& other)
: TrajectoryAgent<T>(other.agent_data_, other.trajectory_) {}
/// @name Accessors for the outputs, as enumerated in the class documentation.
/// @{
const systems::OutputPort<T>& raw_pose_output() const {
return this->get_output_port(0);
}
const systems::OutputPort<T>& pose_output() const {
return this->get_output_port(1);
}
const systems::OutputPort<T>& velocity_output() const {
return this->get_output_port(2);
}
/// @}
private:
// Converts a PoseVelocity, evaluated at the current time, into a
// SimpleCarState output.
void CalcStateOutput(const systems::Context<T>& context,
SimpleCarState<T>* output_vector) const;
// Converts a PoseVelocity, evaluated at the current time, into a PoseVector
// output.
void CalcPoseOutput(const systems::Context<T>& context,
systems::rendering::PoseVector<T>* pose) const;
// Converts a PoseVelocity, evaluated at the current time, into a
// FrameVelocity output.
void CalcVelocityOutput(const systems::Context<T>& context,
systems::rendering::FrameVelocity<T>* velocity) const;
// Extracts the PoseVelocity value at the current time, as provided in
// Context.
PoseVelocity GetValues(const systems::Context<T>& context) const;
// Allow different specializations to access each other's private data.
template <typename>
friend class TrajectoryAgent;
const AgentData agent_data_;
const AgentTrajectory trajectory_;
};
} // namespace automotive
} // namespace drake