select_plan_state.cpp
Go to the documentation of this file.
1 //
2 // Created by yijiangh on 7/10/17.
3 //
4 
5 #include <ros/ros.h>
6 #include <ros/console.h>
7 
10 #include <QtConcurrent/QtConcurrentRun>
11 
12 //
13 #include <choreo_msgs/GetAvailableProcessPlans.h>
14 #include <choreo_msgs/OutputProcessPlans.h>
15 
16 const static std::string GET_AVAILABLE_PROCESS_PLANS_SERVICE = "get_available_process_plans";
17 
19 {
20  gui.setText("Select Plan State.\n"
21  "Please select the desired plan to be simulated in selection window.\n"
22  "Click <Simulate> to continue. ");
23 
24  ptr_gui_ = &gui;
25 
26  ros::ServiceClient client = gui.nodeHandle().serviceClient<choreo_msgs::GetAvailableProcessPlans>(
28 
29  choreo_msgs::GetAvailableProcessPlans srv;
30  std::vector<std::string> plan_names;
31 
32  // fetch all computed plans from core at start
33  if (client.call(srv))
34  {
35  plan_names = srv.response.names;
36  }
37  else
38  {
39  ROS_ERROR_STREAM("[Select Plan State] Could not fetch plan names");
40  }
41 
42  if (plan_names.empty())
43  {
44  gui.appendText("failed to fetch any computed plan.\n"
45  "Return to Init State");
46  Q_EMIT newStateAvailable(new SystemInitState());
47  return;
48  }
49  else
50  {
51  gui.selection_widget().addFetchedPlans(plan_names);
52  }
53 
54  gui.setButtonsEnabled(false);
55  selected_plan_ids_.clear();
56  sim_speed_ = 1.0;
57 
58  connect(&gui.selection_widget(), SIGNAL(flushSimulation()), this, SLOT(triggerSimulation()));
59  connect(&gui.selection_widget(), SIGNAL(flushOutputProcess()), this, SLOT(triggerOutputProcess()));
60 
61  selectPlan(gui);
62 }
63 
65 
67 
69 {
71  Q_EMIT newStateAvailable(new SystemInitState());
72 }
73 
75 {
77  Q_EMIT newStateAvailable(new SystemInitState());
78 }
79 
81 {
83  gui.selection_widget().show();
85 }
86 
88 {
89  QtConcurrent::run(this, &SelectPlanState::simulateAll);
90 }
91 
93 {
94  QtConcurrent::run(this, &SelectPlanState::makeOutputProcessRequest);
95 }
96 
98 {
99  selected_plan_ids_.clear();
102 
103  for (std::size_t i = 0; i < selected_plan_ids_.size(); ++i)
104  {
106  ROS_INFO_STREAM("[ui] simulate #" << selected_plan_ids_[i]);
107  }
108 
110 }
111 
113 {
114  choreo_msgs::SimulateMotionPlanGoal goal;
115  goal.action = choreo_msgs::SimulateMotionPlanGoal::SINGLE_PATH_RUN;
116  goal.index = plan_id;
117  goal.simulate = true;
118  goal.wait_for_execution = true;
119  goal.sim_speed = sim_speed_;
120 
121  ptr_gui_->sendGoalAndWait(goal);
122 }
123 
125 {
126  choreo_msgs::OutputProcessPlans srv;
127 
128  std::vector<int> int_ids = ptr_gui_->selection_widget().getChosenIds();
129  for(auto id : int_ids)
130  {
131  srv.request.names.push_back(std::to_string(id));
132  }
133 
134  ros::ServiceClient output_process_client =
135  ptr_gui_->nodeHandle().serviceClient<choreo_msgs::OutputProcessPlans>(
136  "output_process_plans");
137 
138  ptr_gui_->setButtonsEnabled(false);
140 
141  output_process_client.waitForExistence();
142 
143  if (output_process_client.call(srv))
144  {
145  ptr_gui_->selection_widget().setStatusBar("output plans done.", true);
146  }
147  else
148  {
149  ptr_gui_->selection_widget().setStatusBar("output plans failed!", false);
150  ROS_ERROR_STREAM("unable to output process");
151  }
152 
155 }
void setMode(const MODE &_mode)
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
void setText(const std::string &txt)
The ChoreoWidget class works in states:
Definition: choreo_widget.h:34
void addFetchedPlans(const std::vector< std::string > &plan_names)
virtual void onNext(ChoreoWidget &gui)
void simulateOne(const int &plan_id)
bool call(MReq &req, MRes &res)
void selectPlan(ChoreoWidget &gui)
static const std::string GET_AVAILABLE_PROCESS_PLANS_SERVICE
bool waitForExistence(ros::Duration timeout=ros::Duration(-1))
SelectionWidget & selection_widget()
Definition: choreo_widget.h:55
virtual void onBack(ChoreoWidget &gui)
virtual void onReset(ChoreoWidget &gui)
#define ROS_INFO_STREAM(args)
ros::NodeHandle & nodeHandle()
Definition: choreo_widget.h:53
virtual void onExit(ChoreoWidget &gui)
void setInputEnabled(bool enabled)
std::vector< int > getChosenIds()
void appendText(const std::string &txt)
void setButtonsEnabled(bool enabled)
void setStatusBar(std::string string, bool state)
#define ROS_ERROR_STREAM(args)
void sendGoalAndWait(const choreo_msgs::SimulateMotionPlanGoal &goal)
std::vector< int > getSelectedIdsForSimulation()
void newStateAvailable(GuiState *)
std::vector< int > selected_plan_ids_
virtual void onStart(ChoreoWidget &gui)


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