task_sequence_processing_state.cpp
Go to the documentation of this file.
1 //#include "choreo_gui/states/scanning_state.h"
2 
3 #include <ros/console.h>
8 #include <QtConcurrent/QtConcurrentRun>
9 
10 // input params
11 #include <choreo_msgs/ModelInputParameters.h>
12 #include <choreo_msgs/TaskSequenceInputParameters.h>
13 
14 // note: this action client's name MUST be the same to server's name
15 const static std::string TASK_SEQUENCE_PROCESSING_ACTION_CLIENT_NAME = "task_sequence_processing_action";
16 const static std::string TASK_SEQUENCE_PLANNING_ACTION_CLIENT_NAME = "task_sequence_planning_action";
17 
19  : task_sequence_processing_action_client_(TASK_SEQUENCE_PROCESSING_ACTION_CLIENT_NAME, true),
20  task_sequence_planning_action_client_(TASK_SEQUENCE_PLANNING_ACTION_CLIENT_NAME, true)
21 {
22 }
23 
25 {}
26 
28 {
29  gui.setText("Task Sequence Processing State (recompute assembly sequence or read a saved one).\n"
30  "Click 'Next' to continue.\n");
31 // gui.setButtonsEnabled(false);
32 
33  gui_ptr_ = &gui;
34 
35  QObject::connect(this, SIGNAL(feedbackReceived(QString)), this, SLOT(setFeedbackText(QString)));
36  QObject::connect(&gui.selection_widget(), SIGNAL(closeWidgetAndContinue()), this, SLOT(toNextState()));
37  QObject::connect(&gui.selection_widget(), SIGNAL(recomputeTaskSequenceChosen()), this, SLOT(taskSequencePlanningOn()));
38 
40 }
41 
43 
45 {
46  Q_EMIT newStateAvailable(new SelectTasksState());
47 }
48 
50 {
52  Q_EMIT newStateAvailable(new SystemInitState());
53 }
54 
56 {
58  Q_EMIT newStateAvailable(new SystemInitState());
59 }
60 
62 {
63  this->onNext(*gui_ptr_);
64 }
65 
67 {
69 
70  std::string assembly_type;
71  // it will first try to call tasks sequence processor to see if we can read any existing sequence result
73  gui_ptr_->params().taskSequenceInputParams(), assembly_type);
74 
75  gui_ptr_->selection_widget().setAssemblyType(assembly_type);
77 }
78 
80  const choreo_msgs::ModelInputParameters& model_params,
81  const choreo_msgs::TaskSequenceInputParameters& task_sequence_params,
82  std::string& assembly_type)
83 {
84  choreo_msgs::TaskSequenceProcessingGoal goal;
85  goal.action = choreo_msgs::TaskSequenceProcessingGoal::FIND_AND_PROCESS;
86  goal.use_default_parameters = false;
87  goal.model_params = model_params;
88  goal.task_sequence_params = task_sequence_params;
89 
92  {
93 // ROS_INFO_STREAM("[UI] task sequence processing action server connected!");
94  }
95  else
96  {
97  ROS_ERROR_STREAM("[UI] action task sequence processing server not connected");
98  }
99 
101  goal,
105 
107 
109  {
110  assembly_type = task_sequence_processing_action_client_.getResult()->assembly_type;
111  return true;
112  }
113  else
114  {
115  assembly_type.clear();
116  return false;
117  }
118 }
119 
121 {
122  gui_ptr_->appendText(feedback.toStdString());
123 }
124 
125 // Action Callbacks
128  const choreo_msgs::TaskSequenceProcessingResultConstPtr& result)
129 {
130 }
131 
133 {
134 }
135 
137  const choreo_msgs::TaskSequenceProcessingFeedbackConstPtr& feedback)
138 {
139  Q_EMIT feedbackReceived(QString::fromStdString((feedback->last_completed).c_str()));
140 }
141 
143 {
144  gui_ptr_->setButtonsEnabled(false);
148 }
149 
151  const choreo_msgs::ModelInputParameters& model_params,
152  const choreo_msgs::TaskSequenceInputParameters& task_sequence_params)
153 {
154  choreo_msgs::TaskSequencePlanningGoal goal;
155  goal.model_params = model_params;
156  goal.task_sequence_params = task_sequence_params;
157 
158  ROS_INFO("[UI] Waiting for task sequence planning action server to start.");
161  {
162  ROS_INFO_STREAM("[UI] task seq planning action server connected!");
163  }
164  else
165  {
166  ROS_WARN_STREAM("[UI] action task seq planning server not connected");
167  }
168 
170  goal,
174  ROS_INFO_STREAM("[UI] Goal sent from task sequence planning state");
175 }
176 
177 // Action Callbacks
180  const choreo_msgs::TaskSequencePlanningResultConstPtr& result)
181 {
182  std::string assembly_type;
183 
186  assembly_type))
187  {
189  }
190 }
191 
193 {
194 }
195 
197  const choreo_msgs::TaskSequencePlanningFeedbackConstPtr& feedback)
198 {
199  Q_EMIT feedbackReceived(QString::fromStdString((feedback->last_completed).c_str()));
200 }
void setText(const std::string &txt)
void taskSequencePlanningDoneCallback(const actionlib::SimpleClientGoalState &state, const choreo_msgs::TaskSequencePlanningResultConstPtr &result)
void taskSequenceProcessingDoneCallback(const actionlib::SimpleClientGoalState &state, const choreo_msgs::TaskSequenceProcessingResultConstPtr &result)
The ChoreoWidget class works in states:
Definition: choreo_widget.h:34
bool waitForServer(const ros::Duration &timeout=ros::Duration(0, 0)) const
bool makeTaskSequenceProcessingRequest(const choreo_msgs::ModelInputParameters &model_params, const choreo_msgs::TaskSequenceInputParameters &task_sequence_params, std::string &assembly_type)
bool waitForResult(const ros::Duration &timeout=ros::Duration(0, 0))
ParamsSubmenu & params()
Definition: choreo_widget.h:54
static const std::string TASK_SEQUENCE_PROCESSING_ACTION_CLIENT_NAME
const choreo_msgs::TaskSequenceInputParameters & taskSequenceInputParams() const
void taskSequenceProcessingFeedbackCallback(const choreo_msgs::TaskSequenceProcessingFeedbackConstPtr &feedback)
void showTaskSequenceRecomputePopUp(bool found_task_plan)
actionlib::SimpleActionClient< choreo_msgs::TaskSequencePlanningAction > task_sequence_planning_action_client_
void feedbackReceived(QString feedback)
#define ROS_INFO(...)
SelectionWidget & selection_widget()
Definition: choreo_widget.h:55
#define ROS_WARN_STREAM(args)
actionlib::SimpleActionClient< choreo_msgs::TaskSequenceProcessingAction > task_sequence_processing_action_client_
void setAssemblyType(const std::string &at)
void sendGoal(const Goal &goal, SimpleDoneCallback done_cb=SimpleDoneCallback(), SimpleActiveCallback active_cb=SimpleActiveCallback(), SimpleFeedbackCallback feedback_cb=SimpleFeedbackCallback())
void taskSequencePlanningFeedbackCallback(const choreo_msgs::TaskSequencePlanningFeedbackConstPtr &feedback)
#define ROS_INFO_STREAM(args)
bool makeTaskSequencePlanningRequest(const choreo_msgs::ModelInputParameters &model_params, const choreo_msgs::TaskSequenceInputParameters &task_sequence_params)
static const std::string TASK_SEQUENCE_PLANNING_ACTION_CLIENT_NAME
void appendText(const std::string &txt)
void setButtonsEnabled(bool enabled)
#define ROS_ERROR_STREAM(args)
ResultConstPtr getResult() const
const choreo_msgs::ModelInputParameters & modelInputParams() const
void newStateAvailable(GuiState *)


choreo_gui
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 03:58:56