RobotController.h
Go to the documentation of this file.
00001 #ifndef ROBOTCONTROLLER_H
00002 #define ROBOTCONTROLLER_H
00003 
00004 #include <gazebo/common/PID.hh>
00005 #include <gazebo/common/Time.hh>
00006 #include <r2_gazebo_interface/JointController.h>
00007 #include <r2_msgs/JointStatusArray.h>
00008 #include <gazebo/physics/Joint.hh>
00009 #include <gazebo/physics/Link.hh>
00010 #include <gazebo/physics/Model.hh>
00011 #include <gazebo/physics/PhysicsTypes.hh>
00012 #include <gazebo/physics/World.hh>
00013 #include <boost/thread.hpp>
00014 #include <map>
00015 #include <ros/console.h>
00016 #include <ros/ros.h>
00017 #include <string>
00018 #include <vector>
00019 
00020 namespace gazebo
00021 {
00022     class RobotController
00023     {
00024     public:
00025         struct JointState
00026         {
00027             double position;
00028             double velocity;
00029             double effort;
00030         };
00031 
00032         RobotController(physics::ModelPtr _modelPtr);
00033         ~RobotController();
00034 
00035         // add/modify joints
00036         void addJoint(physics::JointPtr _jointPtr, bool advancedMode = false);
00037         // child pos/vel/effort scaled to factor * parent
00038         // if child and parent are the same joint, this effectively scales the input for that joint
00039         void addJointDependency(std::string _childName, std::string _parentName, double factor);
00040         void setPosPid(const std::string& name, double _p = 0.0, double _i = 0.0, double _d = 0.0,
00041                        double _imax = 0.0, double _imin = 0.0,
00042                        double _cmdMax = 0.0, double _cmdMin = 0.0);
00043         void setVelPid(const std::string& name, double _p = 0.0, double _i = 0.0, double _d = 0.0,
00044                        double _imax = 0.0, double _imin = 0.0,
00045                        double _cmdMax = 0.0, double _cmdMin = 0.0);
00046 
00047         // move the robot to the specified positions while taking dependencies into account
00048         void setJointPositions(std::map<std::string, double> posMap);
00049         // get states
00050         // if map is empty, get all, ignoring dependent joints
00051         void getJointStates(std::map<std::string, JointState>& posMap);
00052         // get joint targets
00053         // if map is empty, get all, ignoring dependent joints
00054         void getJointTargets(std::map<std::string, JointState>& posMap);
00055 
00056         // get joint limits
00057         // if map is empty, get all, ignoring dependent joints
00058         void getJointLimits(std::map<std::string, std::pair<double, double> >& limitsMap);
00059 
00060         // set targets
00061         void setJointPosTarget(const std::string& name, double target);
00062         void setJointVelTarget(const std::string& name, double target);
00063         void setJointEffortTarget(const std::string& name, double target);
00064 
00065         // joint state management
00066         void setJointControl(const r2_msgs::JointControl::ConstPtr& msg);
00067         const r2_msgs::JointStatus& getJointStatus(const std::string& name) const;
00068         void publishJointStatuses(ros::Publisher& rosPub) const;
00069 
00070         // update PIDs and send forces to joints
00071         void update();
00072 
00073     private:
00074         physics::ModelPtr modelPtr;
00075         std::map<std::string, JointControllerPtr> joints;
00076 
00077         typedef std::multimap<std::string, std::pair<std::string, double> > dependenciesType;
00078         dependenciesType dependencies;
00079 
00080         common::Time prevUpdateTime;
00081     };
00082 }
00083 #endif


r2_gazebo_interface
Author(s):
autogenerated on Fri Jun 21 2019 20:03:41