NASA Astrobee Robot Software  Astrobee Version:
Flight software for the Astrobee robots operating inside the International Space Station.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
plan.h
Go to the documentation of this file.
1 /* Copyright (c) 2017, United States Government, as represented by the
2  * Administrator of the National Aeronautics and Space Administration.
3  *
4  * All rights reserved.
5  *
6  * The Astrobee platform is licensed under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with the
8  * License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15  * License for the specific language governing permissions and limitations
16  * under the License.
17  */
18 
19 #ifndef JSONLOADER_PLAN_H_
20 #define JSONLOADER_PLAN_H_
21 
22 #include <stdint.h>
23 
24 #include <jsonloader/command.h>
25 
26 #include <Eigen/Dense>
27 
28 #include <array>
29 #include <memory>
30 #include <vector>
31 #include <string>
32 
33 // Forward declaration, don't pull in Json if we don't have to
34 namespace Json {
35 class Value;
36 } // end namespace Json
37 
38 namespace jsonloader {
39 
40 class Milestone {
41  public:
42  virtual bool IsSegment() const noexcept = 0;
43  virtual bool IsStation() const noexcept = 0;
44 };
45 
46 class Station : public Milestone {
47  public:
48  using CommandPtr = std::unique_ptr<Command>;
49  using CommandSeq = std::vector<CommandPtr>;
50 
51  explicit Station(Json::Value const& obj);
52  Station(Station && other); // move constructor
53 
54  virtual bool IsSegment() const noexcept { return false; };
55  virtual bool IsStation() const noexcept { return true; };
56 
57  bool valid() const noexcept;
58 
59  bool stop_on_arrival() const noexcept;
60  float tolerance() const noexcept;
61 
62  Eigen::Vector3f const& position() const noexcept;
63  Eigen::Vector3f const& orientation() const noexcept;
64 
65  CommandSeq const& commands() const noexcept;
66 
67  private:
68  bool valid_;
69 
70  float tolerance_;
71  bool stop_on_arrival_;
72 
73  // Possibly change these?
74  Eigen::Vector3f position_; // position as x,y,z
75  Eigen::Vector3f orientation_; // orientation as r,p,y
76 
77  CommandSeq commands_;
78 };
79 
80 // Decouple from ros::Time
81 class Time {
82  public:
83  explicit Time(const uint32_t sec = 0, const uint32_t nsec = 0);
84  explicit Time(const double time);
85 
86  void Add(Time const& other);
87 
88  void Set(const double time);
89  void Set(const uint32_t sec, const uint32_t nsec);
90 
91  uint32_t sec() const noexcept;
92  uint32_t nsec() const noexcept;
93 
94  private:
95  void Normalize();
96 
97  uint32_t sec_;
98  uint32_t nsec_;
99 };
100 
101 // Storing time in a float is not going to work. Thus, we have to split it out
102 // into seconds and nanoseconds from the original double we receive.
103 //
104 // XXX(all): *IF* the waypoint format ever changes such that the first double
105 // value is not time, we are, as the french say: [explitive]ed
106 class Waypoint {
107  public:
108  explicit Waypoint(const std::size_t size = 0);
109  Waypoint(const std::size_t size, const double time);
110  Waypoint(const std::size_t size, Time const& time);
111 
112  Time& time() noexcept;
113  Time const& ctime() const noexcept;
114 
115  Eigen::VectorXf& waypoint() noexcept;
116  Eigen::VectorXf const& cwaypoint() const noexcept;
117 
118  private:
119  Time time_;
120  Eigen::VectorXf waypoint_;
121 };
122 
123 class Segment : public Milestone {
124  public:
125  using WaypointSeq = std::vector<Waypoint>;
126 
127  explicit Segment(Json::Value const& obj);
128  Segment();
129 
130  virtual bool IsSegment() const noexcept { return true; };
131  virtual bool IsStation() const noexcept { return false; };
132 
133  bool valid() const noexcept;
134 
135  bool stop_at_end() const noexcept;
136  bool face_forward() const noexcept;
137  float speed() const noexcept;
138  float tolerance() const noexcept;
139  std::string const& waypoint_type() const noexcept;
140  WaypointSeq const& waypoints() const noexcept;
141 
142  private:
143  bool valid_;
144 
145  bool stop_at_end_;
146  bool face_forward_;
147  float speed_;
148  float tolerance_;
149  std::string waypoint_type_;
150  WaypointSeq waypoints_;
151 };
152 
154  public:
155  explicit InertiaConfiguration(Json::Value const& obj);
157 
158  bool valid() const noexcept;
159 
160  std::string const& name() const noexcept;
161  float mass() const noexcept;
162  std::array<float, 9> const& matrix() const noexcept;
163 
164  private:
165  bool valid_;
166 
167  std::string name_;
168  float mass_;
169  std::array<float, 9> matrix_;
170 };
171 
173  public:
174  explicit OperatingLimits(Json::Value const& obj);
175  OperatingLimits();
176 
177  bool valid() const noexcept;
178 
179  std::string const& flight_mode() const noexcept;
180  std::string const& profile_name() const noexcept;
181 
182  float collision_distance() const noexcept;
183  float angular_accel() const noexcept;
184  float angular_velocity() const noexcept;
185  float linear_accel() const noexcept;
186  float linear_velocity() const noexcept;
187 
188  private:
189  bool valid_;
190 
191  std::string flight_mode_;
192  std::string profile_;
193 
194  float collision_distance_;
195  float angular_accel_;
196  float angular_vel_;
197  float linear_accel_;
198  float linear_vel_;
199 };
200 
201 class Plan {
202  public:
203  explicit Plan(Json::Value const& obj);
204  Plan(Plan const& other) = delete;
205  Plan(Plan &&other) = default;
206  Plan();
207 
208  Plan & operator=(Plan &&other) = default;
209 
210  std::size_t NumMilestones() const noexcept;
211  Milestone const& GetMilestone(std::size_t index) const;
212 
213  bool valid() const noexcept;
214 
215  std::string const& name() const noexcept;
216  float default_speed() const noexcept;
217  float default_tolerance() const noexcept;
218  InertiaConfiguration const& inertia_configuration() const noexcept;
219  OperatingLimits const& operating_limits() const noexcept;
220  std::vector<Station> const& stations() const noexcept;
221  std::vector<Segment> const& segments() const noexcept;
222 
223  std::string const& waypoint_type() const noexcept;
224 
225  private:
226  bool valid_;
227 
228  std::string name_;
229 
230  float default_speed_;
231  float default_tolerance_;
232 
233  std::string waypoint_type_;
234 
235  InertiaConfiguration inertia_config_;
236  OperatingLimits operating_limits_;
237 
238  std::vector<Station> stations_;
239  std::vector<Segment> segments_;
240 };
241 
242 } // end namespace jsonloader
243 
244 #endif // JSONLOADER_PLAN_H_
jsonloader::Station::CommandPtr
std::unique_ptr< Command > CommandPtr
Definition: plan.h:48
Value
std::pair< std::string, Keywords > Value
Definition: eps_driver_tool.cc:72
jsonloader::Milestone::IsSegment
virtual bool IsSegment() const noexcept=0
jsonloader::Station::IsStation
virtual bool IsStation() const noexcept
Definition: plan.h:55
jsonloader::Station::commands
CommandSeq const & commands() const noexcept
Definition: plan.cc:550
jsonloader::Time
Definition: plan.h:81
jsonloader::OperatingLimits
Definition: plan.h:172
jsonloader::Station::CommandSeq
std::vector< CommandPtr > CommandSeq
Definition: plan.h:49
jsonloader::Station
Definition: plan.h:46
jsonloader::Milestone
Definition: plan.h:40
jsonloader::Segment::IsSegment
virtual bool IsSegment() const noexcept
Definition: plan.h:130
jsonloader::Station::stop_on_arrival
bool stop_on_arrival() const noexcept
Definition: plan.cc:533
ff_util::Segment
std::vector< Setpoint > Segment
Definition: ff_flight.h:47
jsonloader
Definition: command.h:28
jsonloader::Station::position
Eigen::Vector3f const & position() const noexcept
Definition: plan.cc:541
command.h
gpio::Value
Value
Definition: GPIO.h:42
Json
Definition: command.h:24
name
std::string name
Definition: eps_simulator.cc:48
jsonloader::Station::orientation
Eigen::Vector3f const & orientation() const noexcept
Definition: plan.cc:545
jsonloader::Plan
Definition: plan.h:201
jsonloader::Station::valid
bool valid() const noexcept
Definition: plan.cc:529
std
Definition: tensor.h:39
jsonloader::Station::IsSegment
virtual bool IsSegment() const noexcept
Definition: plan.h:54
jsonloader::Station::Station
Station(Json::Value const &obj)
Definition: plan.cc:487
jsonloader::Milestone::IsStation
virtual bool IsStation() const noexcept=0
jsonloader::Segment::IsStation
virtual bool IsStation() const noexcept
Definition: plan.h:131
jsonloader::InertiaConfiguration
Definition: plan.h:153
jsonloader::Segment
Definition: plan.h:123
jsonloader::Segment::WaypointSeq
std::vector< Waypoint > WaypointSeq
Definition: plan.h:125
jsonloader::Station::tolerance
float tolerance() const noexcept
Definition: plan.cc:537
localization_common::Time
double Time
Definition: time.h:23
jsonloader::Waypoint
Definition: plan.h:106