youbot_oodl.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002  * Copyright (c) 2011
00003  * Locomotec
00004  *
00005  * Author:
00006  * Sebastian Blumenthal
00007  *
00008  *
00009  * This software is published under a dual-license: GNU Lesser General Public
00010  * License LGPL 2.1 and BSD license. The dual-license implies that users of this
00011  * code may choose which terms they prefer.
00012  *
00013  * Redistribution and use in source and binary forms, with or without
00014  * modification, are permitted provided that the following conditions are met:
00015  *
00016  * * Redistributions of source code must retain the above copyright
00017  * notice, this list of conditions and the following disclaimer.
00018  * * Redistributions in binary form must reproduce the above copyright
00019  * notice, this list of conditions and the following disclaimer in the
00020  * documentation and/or other materials provided with the distribution.
00021  * * Neither the name of Locomotec nor the names of its
00022  * contributors may be used to endorse or promote products derived from
00023  * this software without specific prior written permission.
00024  *
00025  * This program is free software: you can redistribute it and/or modify
00026  * it under the terms of the GNU Lesser General Public License LGPL as
00027  * published by the Free Software Foundation, either version 2.1 of the
00028  * License, or (at your option) any later version or the BSD license.
00029  *
00030  * This program is distributed in the hope that it will be useful,
00031  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00032  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00033  * GNU Lesser General Public License LGPL and the BSD license for more details.
00034  *
00035  * You should have received a copy of the GNU Lesser General Public
00036  * License LGPL and BSD license along with this program.
00037  *
00038  ******************************************************************************/
00039 
00040 #include "youbot_driver_ros_interface/YouBotOODLWrapper.h"
00041 
00042 int main(int argc, char **argv)
00043 {
00044 
00045         youbot::Logger::toConsole = false;
00046         youbot::Logger::toFile = false;
00047         youbot::Logger::toROS = true;
00048         ros::init(argc, argv, "youbot_oodl_driver");
00049         ros::NodeHandle n;
00050         youBot::YouBotOODLWrapper youBot(n);
00051         std::vector<std::string> armNames;
00052 
00053 
00054         /* configuration */
00055         bool youBotHasBase;
00056         bool youBotHasArms;
00057         double youBotDriverCycleFrequencyInHz;  //the driver recives commands and publishes them with a fixed frequency
00058         n.param("youBotHasBase", youBotHasBase, true);
00059         n.param("youBotHasArms", youBotHasArms, true);
00060         n.param("youBotDriverCycleFrequencyInHz", youBotDriverCycleFrequencyInHz, 50.0);
00061         n.param<std::string>("youBotConfigurationFilePath", youBot.youBotConfiguration.configurationFilePath, mkstr(YOUBOT_CONFIGURATIONS_DIR));
00062         n.param<std::string>("youBotBaseName", youBot.youBotConfiguration.baseConfiguration.baseID, "youbot-base");
00063 
00064 
00065         // Retrieve all defined arm names from the launch file params
00066         int i = 1;
00067         std::stringstream armNameParam;
00068         armNameParam << "youBotArmName" << i; // youBotArmName1 is first checked param... then youBotArmName2, etc.
00069         while (n.hasParam(armNameParam.str())) {
00070                 std::string armName;
00071                 n.getParam(armNameParam.str(), armName);
00072                 armNames.push_back(armName);
00073                 armNameParam.str("");
00074                 armNameParam << "youBotArmName" <<  (++i);
00075         }
00076 
00077     ros::ServiceServer reconnectService = n.advertiseService("reconnect", &youBot::YouBotOODLWrapper::reconnectCallback, &youBot);
00078 
00079         ROS_INFO("Configuration file path: %s", youBot.youBotConfiguration.configurationFilePath.c_str());
00080         try {
00081                 youbot::EthercatMaster::getInstance("youbot-ethercat.cfg", youBot.youBotConfiguration.configurationFilePath);
00082         } catch (std::exception& e)     {
00083                 ROS_ERROR("No EtherCAT connection:");
00084                 ROS_FATAL("%s", e.what());
00085                 return 0;
00086         }
00087 
00088     ROS_ASSERT((youBotHasBase == true) || (youBotHasArms == true)); // At least one should be true, otherwise nothing to be started.
00089     if (youBotHasBase == true)
00090     {
00091         youBot.initializeBase(youBot.youBotConfiguration.baseConfiguration.baseID);
00092     }
00093 
00094         if (youBotHasArms == true) {
00095                 std::vector<std::string>::iterator armNameIter;
00096                 for (armNameIter = armNames.begin(); armNameIter != armNames.end(); ++armNameIter) {
00097                         youBot.initializeArm(*armNameIter);
00098                 }
00099         }
00100  
00101 
00102     /* coordination */
00103     ros::Rate rate(youBotDriverCycleFrequencyInHz); //Input and output at the same time... (in Hz)
00104     while (n.ok())
00105     {
00106         ros::spinOnce();
00107         youBot.computeOODLSensorReadings();
00108         youBot.publishOODLSensorReadings();
00109         youBot.publishArmAndBaseDiagnostics(2.0);    //publish only every 2 seconds
00110         rate.sleep();
00111     }
00112 
00113     youBot.stop();
00114 
00115     return 0;
00116 }
00117 


youbot_driver_ros_interface
Author(s): Sebastian Blumenthal
autogenerated on Thu Jun 6 2019 20:43:35