Go to the documentation of this file.00001
00002 #include <ros/ros.h>
00003 #include <actionlib/server/simple_action_server.h>
00004 #include <dynamic_reconfigure/server.h>
00005 #include <ipa_canopen_ros_simple/canopen_rosConfig.h>
00006
00007
00008 #include <control_msgs/JointTrajectoryControllerState.h>
00009 #include <sensor_msgs/JointState.h>
00010 #include <diagnostic_msgs/DiagnosticArray.h>
00011 #include <std_msgs/String.h>
00012 #include <brics_actuator/JointVelocities.h>
00013 #include <cob_srvs/Trigger.h>
00014 #include <cob_srvs/Trigger.h>
00015
00016
00017
00018
00019 #include <canopen_ros_common.cpp>
00020
00021
00022 class canopen_ros_ros
00023 {
00024 public:
00025 ros::NodeHandle n_;
00026
00027 dynamic_reconfigure::Server<ipa_canopen_ros_simple::canopen_rosConfig> server;
00028 dynamic_reconfigure::Server<ipa_canopen_ros_simple::canopen_rosConfig>::CallbackType f;
00029
00030
00031 ros::Publisher state_;
00032 ros::Publisher joint_states_;
00033 ros::Publisher diagnostics_;
00034 ros::Publisher current_operationmode_;
00035
00036
00037 ros::Subscriber command_vel_;
00038 ros::ServiceServer init_;
00039 ros::ServiceServer recover_;
00040
00041
00042 canopen_ros_data component_data_;
00043 canopen_ros_config component_config_;
00044 canopen_ros_impl component_implementation_;
00045
00046 canopen_ros_ros()
00047 {
00048
00049 f = boost::bind(&canopen_ros_ros::configure_callback, this, _1, _2);
00050 server.setCallback(f);
00051
00052 std::string init_remap;
00053 n_.param("init_remap", init_remap, (std::string)"init");
00054 init_ = n_.advertiseService<cob_srvs::Trigger::Request , cob_srvs::Trigger::Response>(init_remap, boost::bind(&canopen_ros_impl::callback_init, &component_implementation_,_1,_2,component_config_));
00055 std::string recover_remap;
00056 n_.param("recover_remap", recover_remap, (std::string)"recover");
00057 recover_ = n_.advertiseService<cob_srvs::Trigger::Request , cob_srvs::Trigger::Response>(recover_remap, boost::bind(&canopen_ros_impl::callback_recover, &component_implementation_,_1,_2,component_config_));
00058
00059 state_ = n_.advertise<control_msgs::JointTrajectoryControllerState>("state", 1);
00060 joint_states_ = n_.advertise<sensor_msgs::JointState>("joint_states", 1);
00061 diagnostics_ = n_.advertise<diagnostic_msgs::DiagnosticArray>("diagnostics", 1);
00062 current_operationmode_ = n_.advertise<std_msgs::String>("current_operationmode", 1);
00063 command_vel_ = n_.subscribe("command_vel", 1, &canopen_ros_ros::topicCallback_command_vel, this);
00064
00065
00066 n_.param("can_device", component_config_.can_device, (std::string)"");
00067 n_.param("can_baudrate", component_config_.can_baudrate, (std::string)"500K");
00068 n_.param("modul_ids", component_config_.modul_ids, (std::string)"");
00069 n_.param("joint_names", component_config_.joint_names, (std::string)"[torso_1_joint, torso_2_joint, torso_3_joint]");
00070 n_.param("robot_description", component_config_.robot_description, (std::string)"");
00071
00072 }
00073
00074
00075
00076 void topicCallback_command_vel(const brics_actuator::JointVelocities::ConstPtr& msg)
00077 {
00078 component_data_.in_command_vel = *msg;
00079
00080 }
00081
00082 void configure_callback(ipa_canopen_ros_simple::canopen_rosConfig &config, uint32_t level)
00083 {
00084 component_config_.can_device = config.can_device;
00085 component_config_.can_baudrate = config.can_baudrate;
00086 component_config_.modul_ids = config.modul_ids;
00087 component_config_.joint_names = config.joint_names;
00088 component_config_.robot_description = config.robot_description;
00089 }
00090
00091 void configure()
00092 {
00093 component_implementation_.configure(component_config_);
00094 }
00095
00096 void update()
00097 {
00098 component_implementation_.update(component_data_, component_config_);
00099 state_.publish(component_data_.out_state);
00100 joint_states_.publish(component_data_.out_joint_states);
00101 diagnostics_.publish(component_data_.out_diagnostics);
00102 current_operationmode_.publish(component_data_.out_current_operationmode);
00103
00104 }
00105
00106 };
00107
00108 int main(int argc, char** argv)
00109 {
00110
00111 ros::init(argc, argv, "canopen_ros");
00112
00113 canopen_ros_ros node;
00114 node.configure();
00115
00116
00117 ros::Rate loop_rate(100.0);
00118
00119 while(node.n_.ok())
00120 {
00121 node.update();
00122 loop_rate.sleep();
00123 ros::spinOnce();
00124 }
00125
00126 return 0;
00127 }