NASA Astrobee Robot Software  0.19.1
Flight software for the Astrobee robots operating inside the International Space Station.
sequencer.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 
20 #ifndef EXECUTIVE_UTILS_SEQUENCER_SEQUENCER_H_
21 #define EXECUTIVE_UTILS_SEQUENCER_SEQUENCER_H_
22 
23 #include <ros/console.h>
24 #include <ros/time.h>
25 
26 #include <ff_msgs/AgentStateStamped.h>
27 #include <ff_msgs/ControlState.h>
28 #include <ff_msgs/CommandStamped.h>
29 #include <ff_msgs/CompressedFile.h>
30 #include <ff_msgs/ControlFeedback.h>
31 #include <ff_msgs/PlanStatusStamped.h>
32 
33 #include <geometry_msgs/InertiaStamped.h>
34 
35 #include <jsonloader/command.h>
36 #include <jsonloader/plan.h>
37 
38 #include <string>
39 #include <vector>
40 
41 namespace sequencer {
42 
43 enum class ItemType {
44  NONE,
45  COMMAND,
46  SEGMENT
47 };
48 
49 class Sequencer {
50  public:
51  Sequencer();
52 
53  // because unions can't even :/ OMG.
54  ItemType CurrentType(bool reset_time = true) noexcept;
55  ff_msgs::CommandStamped::Ptr CurrentCommand() noexcept;
57 
58  // give feedback about the end of the current item (command/segment)
59  // this advances the current item if it is a successful ack.
60  //
61  // returns true if there are more command/segments in the plan.
62  bool Feedback(ff_msgs::AckCompletedStatus const& ack) noexcept;
63 
64  // give feedback about an index in the current segment
65  void Feedback(ff_msgs::ControlFeedback const& progress) noexcept;
66 
67  // get the current plan status
68  ff_msgs::PlanStatusStamped const& plan_status() noexcept;
69 
70  // I can haz validity?
71  bool valid() const noexcept;
72  jsonloader::Plan const& plan() const noexcept;
73 
74  // does the current plan have what it takes?
75  bool HaveInertia() const noexcept;
76  bool HaveOperatingLimits() const noexcept;
77 
78  // get the goods
79  geometry_msgs::InertiaStamped GetInertia() const noexcept;
80  bool GetOperatingLimits(ff_msgs::AgentStateStamped &state) const noexcept;
81 
82  private:
83  int AppendStatus(ff_msgs::Status const& msg) noexcept;
84 
85  void Reset() noexcept;
86 
87  friend bool LoadPlan(ff_msgs::CompressedFile::ConstPtr const& cf,
88  Sequencer * seq);
89 
90  bool valid_;
91 
92  jsonloader::Plan plan_;
93  ff_msgs::PlanStatusStamped status_;
94 
95  // when we started the current item
96  ros::Time start_;
97 
98  // milestone is a station or segment within a plan
99  int current_milestone_;
100 
101  // command within a station -1 means none
102  int current_command_;
103 
104  // which waypoint within a segment we are at, 0 means the first one
105  int current_index_;
106 
107  // index in the plan status where the current station is located
108  int station_idx_;
109  int station_duration_;
110 };
111 
112 // load a plan from a compressed file.
113 // returns true if everything be cool, otherwise not.
114 bool LoadPlan(ff_msgs::CompressedFile::ConstPtr const& cf, Sequencer *seq);
115 
116 std::vector<ff_msgs::ControlState>
118 
119 } // end namespace sequencer
120 
121 #endif // EXECUTIVE_UTILS_SEQUENCER_SEQUENCER_H_
plan.h
sequencer::Sequencer
Definition: sequencer.h:49
sequencer::Sequencer::plan_status
ff_msgs::PlanStatusStamped const & plan_status() noexcept
Definition: sequencer.cc:366
sequencer::Sequencer::CurrentSegment
jsonloader::Segment CurrentSegment() noexcept
Definition: sequencer.cc:238
sequencer::Sequencer::HaveOperatingLimits
bool HaveOperatingLimits() const noexcept
Definition: sequencer.cc:172
sequencer::ItemType::COMMAND
@ COMMAND
sequencer::Sequencer::CurrentCommand
ff_msgs::CommandStamped::Ptr CurrentCommand() noexcept
Definition: sequencer.cc:250
command.h
sequencer::Sequencer::CurrentType
ItemType CurrentType(bool reset_time=true) noexcept
Definition: sequencer.cc:196
sequencer::Sequencer::GetOperatingLimits
bool GetOperatingLimits(ff_msgs::AgentStateStamped &state) const noexcept
Definition: sequencer.cc:176
sequencer::Sequencer::GetInertia
geometry_msgs::InertiaStamped GetInertia() const noexcept
Definition: sequencer.cc:147
sequencer::ItemType
ItemType
Definition: sequencer.h:43
sequencer::Sequencer::valid
bool valid() const noexcept
Definition: sequencer.cc:362
sequencer::LoadPlan
bool LoadPlan(ff_msgs::CompressedFile::ConstPtr const &cf, Sequencer *seq)
Definition: sequencer.cc:85
sequencer::Sequencer::HaveInertia
bool HaveInertia() const noexcept
Definition: sequencer.cc:143
jsonloader::Plan
Definition: plan.h:201
sequencer::Segment2Trajectory
std::vector< ff_msgs::ControlState > Segment2Trajectory(jsonloader::Segment const &segment)
Definition: sequencer.cc:115
state
uint8_t state
Definition: signal_lights.h:90
jsonloader::Segment
Definition: plan.h:123
sequencer::Sequencer::Feedback
bool Feedback(ff_msgs::AckCompletedStatus const &ack) noexcept
Definition: sequencer.cc:289
sequencer::Sequencer::Sequencer
Sequencer()
Definition: sequencer.cc:124
sequencer::ItemType::NONE
@ NONE
localization_common::Time
double Time
Definition: time.h:23
sequencer::ItemType::SEGMENT
@ SEGMENT
sequencer::Sequencer::plan
jsonloader::Plan const & plan() const noexcept
Definition: sequencer.cc:139
sequencer
Definition: command_conversion.h:41
sequencer::Sequencer::LoadPlan
friend bool LoadPlan(ff_msgs::CompressedFile::ConstPtr const &cf, Sequencer *seq)
Definition: sequencer.cc:85