choreo_widget.cpp
Go to the documentation of this file.
1 #include <ros/console.h>
2 #include "choreo_msgs/ChoreoParameters.h"
3 
6 
7 #include <ui_choreo_widget.h>
8 #include <QtConcurrent/QtConcurrentRun>
9 
10 // TODO temp
12 #include <choreo_msgs/ProcessPlanningAction.h>
13 const static std::string PROCESS_PLANNING_ACTION_CLIENT_NAME = "process_planning_action";
14 
15 const std::string CHOREO_PARAMETERS_SERVICE = "choreo_parameters";
16 const static std::string SIMULATE_MOTION_PLAN_ACTION_SERVER_NAME = "simulate_motion_plan_as";
17 
19  : QWidget(parent),
20  active_state_(NULL),
21  simulate_motion_plan_action_client_(SIMULATE_MOTION_PLAN_ACTION_SERVER_NAME, true)
22 {
23  // UI setup
24  ui_ = new Ui::ChoreoWidget;
25  ui_->setupUi(this);
26 
27 // ui_->tabWidget->setCurrentIndex(1);
28 
29  params_ = new ParamsSubmenu();
30  params_->setWindowFlags(Qt::WindowStaysOnTopHint);
31 
33 
34  // Starts in scan teach state
36 
37  // Wire in buttons
38  connect(ui_->pushbutton_next, SIGNAL(clicked()), this, SLOT(onNextButton()));
39  connect(ui_->pushbutton_back, SIGNAL(clicked()), this, SLOT(onBackButton()));
40  connect(ui_->pushbutton_reset, SIGNAL(clicked()), this, SLOT(onResetButton()));
41  connect(ui_->pushbutton_params, SIGNAL(clicked()), this, SLOT(onParamsButton()));
42  connect(ui_->pushbutton_picknplace, SIGNAL(clicked()), this, SLOT(onPicknPlace()));
43 
44  // wire in picknplace button
45 
46  // Wire in params signals
47  connect(params_, SIGNAL(saveRequested()), this, SLOT(onParamsSave()));
48  connect(params_, SIGNAL(acceptRequested()), this, SLOT(onParamsAccept()));
49 
50  // Wire in selection signals
51  connect(selection_widget_, SIGNAL(enterSelectionWidget()), this, SLOT(onDisableButtons()));
52  connect(selection_widget_, SIGNAL(exitSelectionWidget()), this, SLOT(onEnableButtons()));
53  connect(selection_widget_, SIGNAL(enableChoreoWidgetButtons()), this, SLOT(onEnableButtons()));
54  connect(selection_widget_, SIGNAL(setOutputSaveDirOn()), this, SLOT(showOutputSaveDirParams()));
55 
56  // Connect to ROS save params services
58 
59  // Start Service Client
60  ros::NodeHandle nh;
62  nh.serviceClient<choreo_msgs::ChoreoParameters>(CHOREO_PARAMETERS_SERVICE);
63 }
64 
66 {
67  delete active_state_;
68  delete params_;
69 }
70 
71 void choreo_gui::ChoreoWidget::setText(const std::string& txt)
72 {
73  ui_->textedit_status->setPlainText(QString::fromStdString(txt));
74 }
75 
76 void choreo_gui::ChoreoWidget::appendText(const std::string& txt)
77 {
78  ui_->textedit_status->moveCursor(QTextCursor::End);
79  ui_->textedit_status->insertPlainText(QString::fromStdString(txt));
80  ui_->textedit_status->moveCursor(QTextCursor::End);
81 }
82 
84 {
85  active_state_->onNext(*this);
86 }
87 
89 {
90  active_state_->onBack(*this);
91 }
92 
94 {
95  active_state_->onReset(*this);
96 
97  choreo_msgs::SimulateMotionPlanGoal goal;
98  goal.action = choreo_msgs::SimulateMotionPlanGoal::RESET_TO_DEFAULT_POSE;
99  goal.simulate = true;
100  goal.wait_for_execution = true;
101 
102  QtConcurrent::run(this, &ChoreoWidget::sendGoalAndWait, goal);
103 }
104 
106 {
107  params_->show();
108 
109 }
110 
112 {
113  choreo_msgs::ChoreoParameters msg;
114  msg.request.action = choreo_msgs::ChoreoParameters::Request::SAVE_PARAMETERS;
115  msg.request.model_params = params_->modelInputParams();
116  msg.request.task_sequence_params = params_->taskSequenceInputParams();
117  msg.request.robot_params = params_->robotInputParams();
118  msg.request.output_save_dir_params = params_->outputSaveDirInputParams();
119 
120  if (!choreo_parameters_client_.call(msg.request, msg.response))
121  ROS_WARN_STREAM("Could not complete service call to save parameters!");
122 }
123 
125 {
126  choreo_msgs::ChoreoParameters msg;
127  msg.request.action = choreo_msgs::ChoreoParameters::Request::SET_PARAMETERS;
128  msg.request.model_params = params_->modelInputParams();
129  msg.request.task_sequence_params = params_->taskSequenceInputParams();
130  msg.request.robot_params = params_->robotInputParams();
131  msg.request.output_save_dir_params = params_->outputSaveDirInputParams();
132 
133  if (!choreo_parameters_client_.call(msg.request, msg.response))
134  ROS_WARN_STREAM("Could not complete service call to set parameters!");
135 }
136 
138 {
139  setButtonsEnabled(true);
140 }
141 
143 {
144  setButtonsEnabled(false);
145 }
146 
148 {
149  choreo_msgs::ProcessPlanningGoal goal;
150  goal.action = choreo_msgs::ProcessPlanningGoal::PICKNPLACE_TEST;
151 
152  ROS_INFO("Waiting for pickn place process planning action server to start.");
154  process_planning_action_client(PROCESS_PLANNING_ACTION_CLIENT_NAME, true);
155  process_planning_action_client.waitForServer();
156 
157  if(process_planning_action_client.isServerConnected())
158  {
159  ROS_INFO_STREAM("process planning action server connected!");
160  }
161  else
162  {
163  ROS_WARN_STREAM("action process planning server not connected");
164  }
165 
166  process_planning_action_client.sendGoal(goal);
167  ROS_INFO_STREAM("Goal sent from pick n place process planning state");
168 }
169 
171 {
172  // Don't transition to a null new state
173  if (!new_state)
174  return;
175 
176  if (active_state_)
177  {
178  active_state_->onExit(*this);
179  delete active_state_;
180  }
181 
182  active_state_ = new_state;
183  connect(new_state, SIGNAL(newStateAvailable(GuiState*)), this, SLOT(changeState(GuiState*)));
184 
185  new_state->onStart(*this);
186 }
187 
189 {
191 }
192 
194 {
195  ui_->pushbutton_next->setEnabled(enabled);
196  ui_->pushbutton_back->setEnabled(enabled);
197  ui_->pushbutton_reset->setEnabled(enabled);
198 }
199 
201 {
202  ui_->pushbutton_params->setEnabled(enabled);
203 }
204 
206 {
207  choreo_msgs::ChoreoParameters srv;
208  srv.request.action = srv.request.GET_CURRENT_PARAMETERS;
209  ros::ServiceClient param_client =
210  nodeHandle().serviceClient<choreo_msgs::ChoreoParameters>(CHOREO_PARAMETERS_SERVICE);
211 
212  setButtonsEnabled(false);
213  if(!param_client.waitForExistence(ros::Duration(10)))
214  {
215  ROS_ERROR("[UI] Unable to connect to parameter server in core service!");
216  }
217  else
218  {
219  ROS_INFO_STREAM("[UI] Connected to parameter server in core service.");
220  }
221 
222  if (param_client.call(srv))
223  {
224  this->params().setModelInputParams(srv.response.model_params);
225  this->params().setTaskSequenceInputParams(srv.response.task_sequence_params);
226  this->params().setRobotInputParams(srv.response.robot_params);
227  this->params().setOutputSaveDirInputParams(srv.response.output_save_dir_params);
228  }
229  else
230  {
231  ROS_WARN_STREAM("[UI] Unable to fetch choreo parameters");
232  }
233  setButtonsEnabled(true);
234 }
235 
236 void choreo_gui::ChoreoWidget::setLabelText(const std::string& txt)
237 {
238  ui_->label_status->setText( QString::fromStdString(txt));
239 }
240 
241 void choreo_gui::ChoreoWidget::sendGoal(const choreo_msgs::SimulateMotionPlanGoal& goal)
242 {
244 }
245 
246 void choreo_gui::ChoreoWidget::sendGoalAndWait(const choreo_msgs::SimulateMotionPlanGoal& goal)
247 {
248  ros::Duration timeout = ros::Duration(60);
250 }
ros::ServiceClient choreo_parameters_client_
Definition: choreo_widget.h:96
#define NULL
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
void setText(const std::string &txt)
virtual void onNext(ChoreoWidget &gui)=0
void setModelInputParams(const choreo_msgs::ModelInputParameters &params)
bool waitForServer(const ros::Duration &timeout=ros::Duration(0, 0)) const
static const std::string SIMULATE_MOTION_PLAN_ACTION_SERVER_NAME
void showOutputSaveDirInputConfigWidget(bool enable)
void setLabelText(const std::string &txt)
const choreo_msgs::OutputSaveDirInputParameters & outputSaveDirInputParams() const
bool call(MReq &req, MRes &res)
SelectionWidget * selection_widget_
Definition: choreo_widget.h:87
ParamsSubmenu & params()
Definition: choreo_widget.h:54
void changeState(GuiState *new_state)
ChoreoWidget(QWidget *parent=0)
static const std::string PROCESS_PLANNING_ACTION_CLIENT_NAME
const choreo_msgs::TaskSequenceInputParameters & taskSequenceInputParams() const
const choreo_msgs::RobotInputParameters & robotInputParams() const
virtual void onReset(ChoreoWidget &gui)=0
bool waitForExistence(ros::Duration timeout=ros::Duration(-1))
ParamsSubmenu * params_
Definition: choreo_widget.h:86
virtual void onBack(ChoreoWidget &gui)=0
#define ROS_INFO(...)
void sendGoal(const choreo_msgs::SimulateMotionPlanGoal &goal)
void setRobotInputParams(const choreo_msgs::RobotInputParameters &params)
SimpleClientGoalState sendGoalAndWait(const Goal &goal, const ros::Duration &execute_timeout=ros::Duration(0, 0), const ros::Duration &preempt_timeout=ros::Duration(0, 0))
#define ROS_WARN_STREAM(args)
Ui::ChoreoWidget * ui_
Definition: choreo_widget.h:85
virtual void onExit(ChoreoWidget &gui)=0
void sendGoal(const Goal &goal, SimpleDoneCallback done_cb=SimpleDoneCallback(), SimpleActiveCallback active_cb=SimpleActiveCallback(), SimpleFeedbackCallback feedback_cb=SimpleFeedbackCallback())
#define ROS_INFO_STREAM(args)
ros::NodeHandle & nodeHandle()
Definition: choreo_widget.h:53
actionlib::SimpleActionClient< choreo_msgs::SimulateMotionPlanAction > simulate_motion_plan_action_client_
Definition: choreo_widget.h:98
void setTaskSequenceInputParams(const choreo_msgs::TaskSequenceInputParameters &params)
void appendText(const std::string &txt)
void setButtonsEnabled(bool enabled)
void sendGoalAndWait(const choreo_msgs::SimulateMotionPlanGoal &goal)
void setOutputSaveDirInputParams(const choreo_msgs::OutputSaveDirInputParameters &params)
void setParamsButtonEnabled(bool enabled)
#define ROS_ERROR(...)
const choreo_msgs::ModelInputParameters & modelInputParams() const
virtual void onStart(ChoreoWidget &gui)=0
const std::string CHOREO_PARAMETERS_SERVICE


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