Go to the documentation of this file.00001
00023 #ifndef NAO_DCM_DRIVER_NAO_H
00024 #define NAO_DCM_DRIVER_NAO_H
00025
00026
00027 #include <boost/shared_ptr.hpp>
00028 #include <boost/assign.hpp>
00029 #include <boost/lexical_cast.hpp>
00030
00031
00032 #include <alcommon/almodule.h>
00033 #include <alcommon/alproxy.h>
00034 #include <alproxies/almotionproxy.h>
00035 #include <alproxies/almemoryproxy.h>
00036 #include <alproxies/dcmproxy.h>
00037 #include <qi/os.hpp>
00038
00039
00040 #include <ros/ros.h>
00041
00042 #include <geometry_msgs/Twist.h>
00043 #include <sensor_msgs/Imu.h>
00044 #include <sensor_msgs/Range.h>
00045 #include <sensor_msgs/JointState.h>
00046 #include <nao_dcm_msgs/BoolService.h>
00047 #include <std_msgs/Float32.h>
00048
00049 #include <tf/transform_broadcaster.h>
00050 #include <tf/transform_listener.h>
00051 #include <tf/transform_datatypes.h>
00052
00053 #include <hardware_interface/joint_command_interface.h>
00054 #include <hardware_interface/joint_state_interface.h>
00055 #include <hardware_interface/robot_hw.h>
00056
00057 #include <controller_manager/controller_manager.h>
00058
00059 #include <diagnostic_updater/diagnostic_updater.h>
00060
00061 using std::string;
00062 using std::vector;
00063
00064 namespace AL
00065 {
00066 class ALBroker;
00067 }
00068
00069
00070 template<typename T, size_t N>
00071 T * end(T (&ra)[N]) {
00072 return ra + N;
00073 }
00074
00075 class Nao : public AL::ALModule, public hardware_interface::RobotHW
00076 {
00077 private:
00078
00079 ros::NodeHandle node_handle_;
00080
00081
00082 ros::Subscriber cmd_vel_sub_;
00083
00084 tf::TransformBroadcaster base_footprint_broadcaster_;
00085 tf::TransformListener base_footprint_listener_;
00086
00087 ros::Publisher stiffness_pub_;
00088 std_msgs::Float32 stiffness_;
00089 ros::ServiceServer stiffness_switch_;
00090
00091 controller_manager::ControllerManager* manager_;
00092
00093
00094 AL::ALValue commands_;
00095
00096
00097 bool is_connected_;
00098
00099
00100 string version_, body_type_;
00101 bool stiffnesses_enabled_;
00102 int topic_queue_;
00103 string prefix_, odom_frame_;
00104 double low_freq_, high_freq_, controller_freq_, joint_precision_;
00105
00106
00107 AL::ALMemoryProxy memory_proxy_;
00108 AL::DCMProxy dcm_proxy_;
00109
00110
00111 vector<string> joints_names_;
00112 vector<string> joint_temperature_names_;
00113
00114 hardware_interface::JointStateInterface jnt_state_interface_;
00115 hardware_interface::PositionJointInterface jnt_pos_interface_;
00116
00117 int number_of_joints_;
00118 vector<string> joint_names_;
00119 vector<double> joint_commands_;
00120 vector<double> joint_angles_;
00121 vector<double> joint_velocities_;
00122 vector<double> joint_efforts_;
00123 public:
00124
00125 Nao(boost::shared_ptr<AL::ALBroker> broker, const std::string& name);
00126 ~Nao();
00127
00128 bool initialize();
00129 bool initializeControllers(controller_manager::ControllerManager& cm);
00130
00131
00132 bool connect(const ros::NodeHandle nh);
00133 void disconnect();
00134
00135
00136 void subscribe();
00137
00138
00139 void loadParams();
00140
00141
00142 void brokerDisconnected(const string& event_name, const string &broker_name, const string& subscriber_identifier);
00143
00144
00145 void DCMTimedCommand(const string& key, const AL::ALValue& value, const int& timeOffset,
00146 const string& type="Merge");
00147 void DCMAliasTimedCommand(const string& alias, const vector<float>& values, const vector<int>& timeOffsets,
00148 const string& type="Merge", const string& type2="time-mixed");
00149
00150
00151 void insertDataToMemory(const string& key, const AL::ALValue& value);
00152 AL::ALValue getDataFromMemory(const string& key);
00153 void subscribeToEvent(const std::string& name, const std::string& callback_module,
00154 const std::string& callback_method);
00155 void subscribeToMicroEvent(const std::string& name, const std::string& callback_module,
00156 const std::string& callback_method, const string& callback_message="");
00157 void unsubscribeFromEvent(const string& name, const string& callback_module);
00158 void unsubscribeFromMicroEvent(const string& name, const string& callback_module);
00159 void raiseEvent(const string& name, const AL::ALValue& value);
00160 void raiseMicroEvent(const string& name, const AL::ALValue& value);
00161 void declareEvent(const string& name);
00162
00163
00164 void controllerLoop();
00165 void lowCommunicationLoop();
00166 void highCommunicationLoop();
00167
00168 bool connected();
00169
00170
00171 void commandVelocity(const geometry_msgs::TwistConstPtr &msg);
00172
00173 void publishBaseFootprint(const ros::Time &ts);
00174
00175 void readJoints();
00176
00177 void writeJoints();
00178
00179 bool switchStiffnesses(nao_dcm_msgs::BoolService::Request &req, nao_dcm_msgs::BoolService::Response &res);
00180
00181 void run();
00182
00183 };
00184
00185 #endif // NAO_H