run_trials.hh
Go to the documentation of this file.
1 
10 #ifndef _RUN_TRIALS_HH_
11 #define _RUN_TRIALS_HH_
12 
13 // Gazebo
14 #include <gazebo/gazebo_client.hh>
15 #include <gazebo/gazebo_config.h>
16 #include <gazebo/transport/transport.hh>
17 #include <gazebo/msgs/msgs.hh>
18 // I/O streams
19 #include <iostream>
20 // Threads
21 #include <chrono>
22 #include <condition_variable>
23 #include <mutex>
24 #include <thread>
25 // Open YAML config files
26 #include "yaml-cpp/yaml.h"
27 
28 // Custom messages
29 #include "MessageTypes.hh"
30 // Grasp representation
31 #include "Grasp.hh"
32 // Rest pose utils
33 #include "RestPose.hh"
34 // Interface for hand plugin
35 #include "Interface.hh"
36 // Tools
37 #include "object_utils.hh"
38 // Debug streams
39 #include "debug.hh"
40 // Randomiser class
41 #include "Randomiser.hh"
42 
43 // GAP
44 
45 // Custom messages
46 #include "dr_request.pb.h"
47 // Domain randomization plugin interface
48 #include "DRInterface.hh"
49 
51 typedef std::map<std::string,std::string> Config;
52 
53 // Topics
54 
56 #define HAND_REQ_TOPIC "~/hand"
57 #define HAND_RES_TOPIC "~/hand/response"
59 #define TARGET_REQ_TOPIC "~/grasp/target"
61 #define TARGET_RES_TOPIC "~/grasp/target/response"
63 #define CONTACT_REQ_TOPIC "~/grasp/contact"
65 #define CONTACT_RES_TOPIC "~/grasp/contact/response"
67 #define CAMERA_REQ_TOPIC "~/grasp/rgbd"
69 #define CAMERA_RES_TOPIC "~/grasp/rgbd/response"
71 #define FACTORY_TOPIC "~/factory"
73 #define REQUEST_TOPIC "~/request"
75 
76 // Type enums
77 
78 // Target Plugin
79 
81 #define REQ_GET_POSE grasp::msgs::TargetRequest::GET_POSE
82 #define REQ_SET_POSE grasp::msgs::TargetRequest::SET_POSE
84 #define REQ_REST_POSE grasp::msgs::TargetRequest::GET_REST_POSE
86 #define REQ_RESET grasp::msgs::TargetRequest::RESET
88 #define RES_POSE grasp::msgs::TargetResponse::POSE
90 #define RES_REST_POSE grasp::msgs::TargetResponse::REST_POSE
92 
93 // Camera plugin
94 
96 #define REQ_CAPTURE grasp::msgs::CameraRequest::CAPTURE
97 
98 // Hand plugin
99 
101 #define POSITION grasp::msgs::Target::POSITION
102 #define VELOCITY grasp::msgs::Target::VELOCITY
104 
105 // Message type definitions
106 
108 typedef grasp::msgs::Hand HandMsg;
110 typedef const boost::shared_ptr<const grasp::msgs::Hand>
112 
116 typedef const boost::shared_ptr<const grasp::msgs::TargetRequest>
121 typedef const boost::shared_ptr<const grasp::msgs::TargetResponse>
123 
129 typedef const boost::shared_ptr<const grasp::msgs::ContactRequest>
134 typedef const boost::shared_ptr<const grasp::msgs::ContactResponse>
136 
140 typedef const boost::shared_ptr<const grasp::msgs::CameraRequest>
145 typedef const boost::shared_ptr<const grasp::msgs::CameraResponse>
147 
148 //
149 // Argument parsing and setup
150 //
151 
155 const std::string getUsage(const char* argv_0);
156 
161 void parseArgs(
162  int argc,
163  char** argv,
164  Config & config);
165 
171  gazebo::transport::NodePtr & node,
172  std::map<std::string, gazebo::transport::PublisherPtr> & pubs,
173  std::map<std::string, gazebo::transport::SubscriberPtr> & subs);
174 
175 //
176 // File I/O
177 //
178 
182 void obtainTargets(std::vector<std::string> & targets,
183  const std::string & file_name);
184 
191 bool importGrasps(const std::string & grasp_cfg_dir,
192  const std::string & robot,
193  const std::string & object_name,
194  std::vector<Grasp> & grasps);
195 
201 void exportGraspMetrics(const std::string & trials_out_dir,
202  const std::string & robot,
203  const std::string & object_name,
204  const std::vector<Grasp> & grasps);
205 
206 //
207 // Gazebo plugin interaction
208 //
209 
213 void setPose(gazebo::transport::PublisherPtr pub,
214  ignition::math::Pose3d pose,
215  double timeout=-1);
216 
221 void checkHandCollisions(gazebo::transport::PublisherPtr pub,
222  const std::string & hand,
223  std::vector<std::string> & targets);
224 
229 void closeFingers(gazebo::transport::PublisherPtr pub,
230  double timeout=-1);
231 
235 void liftHand(gazebo::transport::PublisherPtr pub,
236  double timeout=-1);
237 
240 void resetTarget(gazebo::transport::PublisherPtr pub);
241 
246 void tryGrasp(
247  Grasp & grasp,
248  Interface & interface,
249  std::map<std::string, gazebo::transport::PublisherPtr> & pubs,
250  const std::string & model_name);
251 
252 // Synchronisation
253 
256 void waitForTrigger(int timeout=-1);
257 
258 // Callback functions
259 
261 void onHandResponse(HandMsgPtr & _msg);
262 
265 
268 
269 
270 #endif
Protobuf message types header.
grasp::msgs::Hand HandMsg
Declaration for hand message type.
Definition: run_trials.hh:108
const boost::shared_ptr< const grasp::msgs::CameraResponse > CameraResponsePtr
Shared pointer declaration for response message type.
Definition: run_trials.hh:146
bool importGrasps(const std::string &grasp_cfg_dir, const std::string &robot, const std::string &object_name, std::vector< Grasp > &grasps)
Obtain list of grasps in yml files.
Definition: run_trials.cc:229
const boost::shared_ptr< const grasp::msgs::Hand > HandMsgPtr
Shared pointer declaration for hand message type.
Definition: run_trials.hh:111
grasp::msgs::TargetResponse TargetResponse
Declaration for response message type.
Definition: run_trials.hh:119
const boost::shared_ptr< const grasp::msgs::TargetResponse > TargetResponsePtr
Shared pointer declaration for response message type.
Definition: gen_rest_poses.hh:58
const boost::shared_ptr< const grasp::msgs::TargetRequest > TargetRequestPtr
Shared pointer declaration for request message type.
Definition: run_trials.hh:117
grasp::msgs::CameraRequest CameraRequest
Declaration for request message type.
Definition: run_trials.hh:138
grasp::msgs::ContactResponse ContactResponse
Declaration for response message type.
Definition: run_trials.hh:132
RestPose tools.
Grasp representation.
void setPose(gazebo::transport::PublisherPtr pub, ignition::math::Pose3d pose, double timeout=-1)
Sets hand pose.
grasp::msgs::TargetRequest TargetRequest
Declaration for request message type.
Definition: run_trials.hh:114
Grasp interface headers.
void exportGraspMetrics(const std::string &trials_out_dir, const std::string &robot, const std::string &object_name, const std::vector< Grasp > &grasps)
Export set of metrics to file.
Definition: run_trials.cc:246
const std::string getUsage(const char *argv_0)
Obtains usage string.
Definition: gen_renders.cc:130
void obtainTargets(std::vector< std::string > &targets, const std::string &file_name)
Obtain list of models&#39; names in dataset yml.
Definition: gen_renders.cc:212
const boost::shared_ptr< const grasp::msgs::ContactResponse > ContactResponsePtr
Shared pointer declaration for response message type.
Definition: run_trials.hh:135
Object related utilities.
const boost::shared_ptr< const grasp::msgs::CameraRequest > CameraRequestPtr
Shared pointer declaration for request message type.
Definition: run_trials.hh:141
const boost::shared_ptr< const grasp::msgs::TargetResponse > TargetResponsePtr
Shared pointer declaration for response message type.
Definition: run_trials.hh:122
grasp::msgs::CameraResponse CameraResponse
Declaration for response message type.
Definition: run_trials.hh:143
void onHandResponse(HandMsgPtr &_msg)
TODO.
Definition: run_trials.cc:374
Hand interface.
Definition: Interface.hh:42
void liftHand(gazebo::transport::PublisherPtr pub, double timeout=-1)
Lifts robotic manipulator along positive z axis.
grasp::msgs::CollisionRequest CollisionRequest
Declaration for request aux message type.
Definition: run_trials.hh:125
void setupCommunications(gazebo::transport::NodePtr &node, std::map< std::string, gazebo::transport::PublisherPtr > &pubs, std::map< std::string, gazebo::transport::SubscriberPtr > &subs)
Sets up gazebo communication pubs/subs.
Definition: gen_renders.cc:190
void closeFingers(gazebo::transport::PublisherPtr pub, double timeout=-1)
Closes manipulator fingers.
void checkHandCollisions(gazebo::transport::PublisherPtr pub, const std::string &hand, std::vector< std::string > &targets)
Requests collisions in the world.
Definition: run_trials.cc:257
void onTargetResponse(TargetResponsePtr &_msg)
TODO.
Definition: gen_rest_poses.cc:203
grasp::msgs::ContactRequest ContactRequest
Declaration for request message type.
Definition: run_trials.hh:127
void tryGrasp(Grasp &grasp, Interface &interface, std::map< std::string, gazebo::transport::PublisherPtr > &pubs, const std::string &model_name)
Attempts to grasp object.
Definition: run_trials.cc:289
const boost::shared_ptr< const grasp::msgs::ContactRequest > ContactRequestPtr
Shared pointer declaration for request message type.
Definition: run_trials.hh:130
Randomiser class.
Grasp representation class.
Definition: Grasp.hh:19
void parseArgs(int argc, char **argv, Config &config)
Parses command-line arguments.
Definition: run_trials.cc:136
void waitForTrigger(int timeout=-1)
Waits for condition variable.
Definition: run_trials.cc:360
void resetTarget(gazebo::transport::PublisherPtr pub)
Resets target object to rest pose.
Definition: run_trials.cc:281
void onContactResponse(ContactResponsePtr &_msg)
TODO.
Definition: run_trials.cc:396
std::map< std::string, std::string > Config
Config dictionary.
Definition: run_trials.hh:51