Interface.hh
Go to the documentation of this file.
1 
8 #ifndef _INTERFACE_HH_
9 #define _INTERFACE_HH_
10 
11 #include <vector>
12 #include <map>
13 // Open YAML config files
14 #include "yaml-cpp/yaml.h"
15 
16 // Gazebo
17 #include <gazebo/gazebo_client.hh>
18 #include <gazebo/gazebo_config.h>
19 #include <gazebo/transport/transport.hh>
20 #include <gazebo/msgs/msgs.hh>
21 
22 // Custom utilities
23 #include "utils.hh"
24 // Debug streams
25 #include "debug.hh"
26 // Grasp shape representation
27 #include "GraspShape.hh"
28 // Custom messages
29 #include "target.pb.h"
30 #include "hand.pb.h"
31 
32 // DEBUG
33 #include <iostream>
34 
36 #define HAND_PLUGIN_TOPIC "~/hand"
37 
38 // Key for exiting program (Esc)
39 #define KEY_EXIT 27
40 
42 class Interface
43 {
45  public: static const grasp::msgs::Target_Type FORCE =
48  public: static const grasp::msgs::Target_Type POSITION =
51  public: static const grasp::msgs::Target_Type VELOCITY =
53 
55  private: std::string robot_name;
57  private: gazebo::transport::NodePtr node;
59  private: gazebo::transport::PublisherPtr pub;
61  private: std::vector<std::string> joints;
63  private: std::map<std::string, double> state;
65  private: std::vector<GraspShape> grasps;
67  private: ignition::math::Matrix4d t_base_gripper;
68 
70  public: Interface();
71 
74  public: bool init(
75  const std::string & config_file,
76  const std::string & robot);
77 
78  // Getters
79 
82  public: std::string getRobotName();
83 
86  public: ignition::math::Matrix4d getTransformBaseGripper();
87 
88  // API
89 
94  void setPose(ignition::math::Pose3d pose, double timeout=-1);
95 
97  public: void reset(void);
98 
102  void openFingers(double timeout=-1,
103  bool set_position=false);
104 
108  void closeFingers(double timeout=-1,
109  bool apply_force=false);
110 
113  void raiseHand(double timeout=-1);
114 
116  public: void loop(void);
117 
119  private: int processKeypress(char key);
120 
122  private: void moveJoint(
123  const char *joint, double value);
124 
126  private: void moveFingers(double value);
127 
129  private: void setJoints(
130  std::vector<std::string> & joints,
131  std::vector<double> & values);
132 };
133 
134 #endif
static const grasp::msgs::Target_Type POSITION
Position controller target.
Definition: Interface.hh:48
std::string getRobotName()
Gets robot name.
Definition: Interface.cc:92
void openFingers(double timeout=-1, bool set_position=false)
Releases fingers and opens hand.
Definition: Interface.cc:120
std::vector< std::string > joints
Name of actuated robot joints.
Definition: Interface.hh:61
static const grasp::msgs::Target_Type FORCE
Direct force/torque application.
Definition: Interface.hh:45
void moveJoint(const char *joint, double value)
TODO.
Definition: Interface.cc:263
void reset(void)
Sends reset signal to hand plugin.
Definition: Interface.cc:112
static const grasp::msgs::Target_Type VELOCITY
Velocity controller target.
Definition: Interface.hh:51
void moveFingers(double value)
TODO.
std::map< std::string, double > state
Map with (name: value) states of each actuated joint.
Definition: Interface.hh:63
std::vector< GraspShape > grasps
Set of grasp shapes.
Definition: Interface.hh:65
#define POSITION
Position control.
Definition: run_trials.hh:101
bool init(const std::string &config_file, const std::string &robot)
Initalizes interface with config file.
Definition: Interface.cc:35
void setJoints(std::vector< std::string > &joints, std::vector< double > &values)
TODO.
Definition: Interface.cc:275
#define FORCE
Apply force/torque directly.
Definition: HandPlugin.hh:54
Hand interface.
Definition: Interface.hh:42
void setPose(ignition::math::Pose3d pose, double timeout=-1)
Sets hand pose.
Definition: Interface.cc:98
ignition::math::Matrix4d getTransformBaseGripper()
Get T base to gripper frame.
Definition: Interface.cc:86
void raiseHand(double timeout=-1)
Raises hand.
Definition: Interface.cc:174
void loop(void)
TODO.
Definition: Interface.cc:199
ignition::math::Matrix4d t_base_gripper
Rigid transform from base link to gripper frame.
Definition: Interface.hh:67
Interface()
Constructor.
Definition: Interface.cc:11
void closeFingers(double timeout=-1, bool apply_force=false)
Clenches fingers and closes hand.
Definition: Interface.cc:138
int processKeypress(char key)
TODO.
Definition: Interface.cc:221
Grasp shape representation.
std::string robot_name
Name of robot instance in Gazebo.
Definition: Interface.hh:55
gazebo::transport::PublisherPtr pub
Gazebo publisher.
Definition: Interface.hh:59
Useful 3rd party functions.
#define VELOCITY
Velocity control.
Definition: run_trials.hh:103
gazebo::transport::NodePtr node
Gazebo communication node.
Definition: Interface.hh:57