Go to the documentation of this file.00001
00002 #include <sys/mman.h>
00003 #include <cmath>
00004 #include <time.h>
00005 #include <signal.h>
00006 #include <stdexcept>
00007
00008
00009 #include <ros/ros.h>
00010 #include <controller_manager/controller_manager.h>
00011
00012
00013 #include "yumi_hw/yumi_hw_rapid.h"
00014
00015 bool g_quit = false;
00016
00017 void quitRequested(int sig)
00018 {
00019 g_quit = true;
00020 }
00021
00022
00023 std::string getURDF(ros::NodeHandle &model_nh_, std::string param_name)
00024 {
00025 std::string urdf_string;
00026 std::string robot_description = "/robot_description";
00027
00028
00029 while (urdf_string.empty())
00030 {
00031 std::string search_param_name;
00032 if (model_nh_.searchParam(param_name, search_param_name))
00033 {
00034 ROS_INFO_ONCE_NAMED("LWRHWFRI", "LWRHWFRI node is waiting for model"
00035 " URDF in parameter [%s] on the ROS param server.", search_param_name.c_str());
00036
00037 model_nh_.getParam(search_param_name, urdf_string);
00038 }
00039 else
00040 {
00041 ROS_INFO_ONCE_NAMED("LWRHWFRI", "LWRHWFRI node is waiting for model"
00042 " URDF in parameter [%s] on the ROS param server.", robot_description.c_str());
00043
00044 model_nh_.getParam(param_name, urdf_string);
00045 }
00046
00047 usleep(100000);
00048 }
00049 ROS_DEBUG_STREAM_NAMED("LWRHWFRI", "Received URDF from param server, parsing...");
00050
00051 return urdf_string;
00052 }
00053
00054 int main( int argc, char** argv )
00055 {
00056
00057 ros::init(argc, argv, "yumi_hw_interface", ros::init_options::NoSigintHandler);
00058
00059
00060 ros::AsyncSpinner spinner(4);
00061 spinner.start();
00062
00063
00064 signal(SIGTERM, quitRequested);
00065 signal(SIGINT, quitRequested);
00066 signal(SIGHUP, quitRequested);
00067
00068
00069 ros::NodeHandle yumi_nh ("~");
00070
00071
00072 int port;
00073 std::string hintToRemoteHost;
00074 std::string name;
00075
00076 yumi_nh.param("ip", hintToRemoteHost, std::string("192.168.125.1") );
00077 yumi_nh.param("name", name, std::string("yumi"));
00078
00079
00080 std::string urdf_string = getURDF(yumi_nh, "/robot_description");
00081
00082 YumiHWRapid yumi_robot;
00083 yumi_robot.create(name, urdf_string);
00084 yumi_robot.setup(hintToRemoteHost);
00085
00086 if(!yumi_robot.init())
00087 {
00088 ROS_FATAL_NAMED("yumi_hw","Could not initialize robot real interface");
00089 return -1;
00090 }
00091
00092
00093 struct timespec ts = {0, 0};
00094 ros::Time last(ts.tv_sec, ts.tv_nsec), now(ts.tv_sec, ts.tv_nsec);
00095 ros::Duration period(1.0);
00096
00097 float sampling_time = yumi_robot.getSampleTime();
00098 ROS_INFO("Sampling time on robot: %f", sampling_time);
00099
00100
00101 controller_manager::ControllerManager manager(&yumi_robot);
00102
00103
00104 while( !g_quit )
00105 {
00106
00107
00108
00109 now = ros::Time::now();
00110
00111
00112 period = now - last;
00113 last = now;
00114
00115
00116
00117
00118
00119
00120
00121
00122 yumi_robot.read(now, period);
00123
00124
00125 manager.update(now, period);
00126
00127
00128 yumi_robot.write(now, period);
00129
00130
00131
00132 }
00133
00134 std::cerr<<"Stopping spinner..."<<std::endl;
00135 spinner.stop();
00136
00137 std::cerr<<"Bye!"<<std::endl;
00138
00139 return 0;
00140 }