NASA Astrobee Robot Software  0.19.1
Flight software for the Astrobee robots operating inside the International Space Station.
op_state.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 EXECUTIVE_OP_STATE_H_
20 #define EXECUTIVE_OP_STATE_H_
21 
22 #include <ros/ros.h>
23 
24 #include <executive/executive.h>
25 
26 #include <ff_msgs/ArmAction.h>
27 #include <ff_msgs/CommandArg.h>
28 #include <ff_msgs/CommandConstants.h>
29 #include <ff_msgs/ControlState.h>
30 #include <ff_msgs/DockAction.h>
31 #include <ff_msgs/MotionAction.h>
32 #include <ff_util/ff_action.h>
33 
34 #include <string>
35 
36 using ff_msgs::CommandConstants;
37 
38 namespace executive {
39 class Executive;
40 class OpStateRepo;
45 class OpState {
46  public:
47  virtual ~OpState() {}
48  virtual OpState* StartupState(std::string const& cmd_id = "");
49  virtual OpState* HandleCmd(ff_msgs::CommandStampedPtr const& cmd);
50  OpState* HandleCmd(ff_msgs::CommandStampedPtr const& cmd,
51  bool& completed,
52  bool& successful);
53 
54  virtual OpState* HandleResult(
56  std::string const& result_response,
57  std::string const& cmd_id,
58  Action const& action);
59 
60  virtual OpState* HandleWaitCallback();
61 
63  ff_msgs::AckStampedConstPtr const& ack);
64 
65  virtual void AckCmd(std::string const& cmd_id,
66  uint8_t completed_status = ff_msgs::AckCompletedStatus::OK,
67  std::string const& message = "",
68  uint8_t status = ff_msgs::AckStatus::COMPLETED);
69 
70  std::string GenerateActionFailedMsg(
72  Action const& action,
73  std::string const& action_result = "");
74 
75  std::string GetActionString(Action const& action);
76 
77  virtual bool PausePlan(ff_msgs::CommandStampedPtr const& cmd);
78 
79  OpState* TransitionToState(unsigned char id);
80 
81  std::string const& name() const {return name_;}
82  unsigned char const& id() const {return id_;}
83 
84  protected:
85  OpState(std::string const& name, unsigned char id);
86  void SetExec(Executive *const exec);
87  void SetPlanStatus(bool successful, std::string err_msg = "");
88 
89  std::string const name_;
90  unsigned char const id_;
92 
93  private:
94  friend class OpStateRepo;
95  OpState (const OpState&) = delete;
96  OpState& operator= (const OpState&) = delete;
97 };
98 typedef std::unique_ptr<OpState> OpStatePtr;
99 } // namespace executive
100 #endif // EXECUTIVE_OP_STATE_H_
executive::OpState::PausePlan
virtual bool PausePlan(ff_msgs::CommandStampedPtr const &cmd)
Definition: op_state.cc:193
executive::OpState::HandleResult
virtual OpState * HandleResult(ff_util::FreeFlyerActionState::Enum const &state, std::string const &result_response, std::string const &cmd_id, Action const &action)
Definition: op_state.cc:85
executive::OpState::GetActionString
std::string GetActionString(Action const &action)
Definition: op_state.cc:152
executive::OpStatePtr
std::unique_ptr< OpState > OpStatePtr
Definition: op_state.h:98
executive::OpState::exec_
Executive * exec_
Definition: op_state.h:91
executive::Action
Action
Definition: executive_action_client.h:29
executive::OpStateRepo
Definition: op_state_repo.h:43
executive::OpState::name_
const std::string name_
Definition: op_state.h:89
executive::OpState::AckCmd
virtual void AckCmd(std::string const &cmd_id, uint8_t completed_status=ff_msgs::AckCompletedStatus::OK, std::string const &message="", uint8_t status=ff_msgs::AckStatus::COMPLETED)
Definition: op_state.cc:104
executive::OpState::OpState
OpState(std::string const &name, unsigned char id)
Definition: op_state.cc:24
executive::OpState::HandleCmd
virtual OpState * HandleCmd(ff_msgs::CommandStampedPtr const &cmd)
Definition: op_state.cc:43
executive::OpState::GenerateActionFailedMsg
std::string GenerateActionFailedMsg(ff_util::FreeFlyerActionState::Enum const &state, Action const &action, std::string const &action_result="")
Definition: op_state.cc:114
ff_action.h
ff_util::FreeFlyerActionState::Enum
Enum
Definition: ff_action.h:41
executive::OpState::SetExec
void SetExec(Executive *const exec)
Definition: op_state.cc:37
executive::OpState::TransitionToState
OpState * TransitionToState(unsigned char id)
Definition: op_state.cc:200
executive::OpState::SetPlanStatus
void SetPlanStatus(bool successful, std::string err_msg="")
Definition: op_state.cc:217
executive::OpState::~OpState
virtual ~OpState()
Definition: op_state.h:47
executive::Executive
Definition: executive.h:100
state
uint8_t state
Definition: signal_lights.h:90
executive.h
executive::OpState::id
unsigned char const & id() const
Definition: op_state.h:82
executive::OpState::HandleGuestScienceAck
virtual OpState * HandleGuestScienceAck(ff_msgs::AckStampedConstPtr const &ack)
Definition: op_state.cc:98
executive::OpState::name
std::string const & name() const
Definition: op_state.h:81
executive
Definition: executive.h:87
executive::OpState::StartupState
virtual OpState * StartupState(std::string const &cmd_id="")
Definition: op_state.cc:30
executive::OpState::HandleWaitCallback
virtual OpState * HandleWaitCallback()
Definition: op_state.cc:93
executive::OpState::id_
unsigned const char id_
Definition: op_state.h:90
executive::OpState
Definition: op_state.h:45