00001 /**************************************************************** 00002 * 00003 * Copyright (c) 2010 00004 * 00005 * Fraunhofer Institute for Manufacturing Engineering 00006 * and Automation (IPA) 00007 * 00008 * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00009 * 00010 * Project name: 00011 * ROS stack name: 00012 * ROS package name: 00013 * Description: 00014 * 00015 * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00016 * 00017 * Author: 00018 * Supervised by: 00019 * 00020 * Date of creation: Jan 2010 00021 * ToDo: 00022 * 00023 * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00024 * 00025 * Redistribution and use in source and binary forms, with or without 00026 * modification, are permitted provided that the following conditions are met: 00027 * 00028 * * Redistributions of source code must retain the above copyright 00029 * notice, this list of conditions and the following disclaimer. 00030 * * Redistributions in binary form must reproduce the above copyright 00031 * notice, this list of conditions and the following disclaimer in the 00032 * documentation and/or other materials provided with the distribution. 00033 * * Neither the name of the Fraunhofer Institute for Manufacturing 00034 * Engineering and Automation (IPA) nor the names of its 00035 * contributors may be used to endorse or promote products derived from 00036 * this software without specific prior written permission. 00037 * 00038 * This program is free software: you can redistribute it and/or modify 00039 * it under the terms of the GNU Lesser General Public License LGPL as 00040 * published by the Free Software Foundation, either version 3 of the 00041 * License, or (at your option) any later version. 00042 * 00043 * This program is distributed in the hope that it will be useful, 00044 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00045 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00046 * GNU Lesser General Public License LGPL for more details. 00047 * 00048 * You should have received a copy of the GNU Lesser General Public 00049 * License LGPL along with this program. 00050 * If not, see <http://www.gnu.org/licenses/>. 00051 * 00052 ****************************************************************/ 00053 00054 //################## 00055 //#### includes #### 00056 00057 // standard includes 00058 #include <stdlib.h> 00059 //#include <MathSup.h> 00060 #include <cob_utilities/Mutex.h> 00061 00062 00063 // ROS includes 00064 #include <ros/ros.h> 00065 00066 // ROS message includes 00067 #include <diagnostic_msgs/DiagnosticStatus.h> 00068 00069 // ROS service includes 00070 //-- 00071 00072 // external includes 00073 //#include <CANOpen_driver.h> 00074 #include <CANOpenMaster.h> 00075 #include <pthread.h> 00076 00077 //#################### 00078 //#### node class #### 00079 class NodeClass 00080 { 00081 // 00082 public: 00083 00084 ros::NodeHandle n; 00085 00086 00087 // TODO Namen der Klasse ändern 00088 // create Axis handle 00089 //CANOpenMaster* Axis; 00090 00091 // topics to publish 00092 ros::Publisher topicPub_CANError; 00093 00094 // topics to subscribe, callback is called for new messages arriving 00095 00096 // service servers 00097 //-- 00098 00099 // service clients 00100 //-- 00101 00102 // global variables 00103 int SYNC_Freq_HZ; 00104 00105 // msg containers 00106 diagnostic_msgs::DiagnosticStatus msg_Error; 00107 00108 00109 // Constructor 00110 NodeClass() 00111 { 00112 // create a handle for this node, initialize node 00113 ros::NodeHandle private_nh_("~"); 00114 00115 // fill Axis handle 00116 //Axis = new CANOpenMaster(); 00117 00118 // global variables 00119 SYNC_Freq_HZ = 100; //Looprate for SYNC commands in Hz 00120 00121 // msg 00122 msg_Error.name = "CANError"; 00123 00124 // init topic publisher 00125 topicPub_CANError = n.advertise<diagnostic_msgs::DiagnosticStatus>("CANError",1); 00126 00127 // init topic subscriber 00128 00129 } 00130 00131 00132 // Destructor 00133 ~NodeClass() 00134 { 00135 exit(0); 00136 } 00137 00138 // topic callback functions 00139 // function will be called when a new message arrives on a topic 00140 00141 // service callback functions 00142 // function will be called when a service is querried 00143 //-- 00144 00145 // TODO callbacks for timingdemands 00146 00147 // other function declarations 00148 00149 }; 00150 00151 /*---------------------------------------------------------------*/ 00152 //####################### 00153 //#### main programm #### 00154 int main(int argc, char** argv) 00155 { 00156 // initialize ROS, spezify name of node 00157 ros::init(argc, argv, "CANOpenMaster"); 00158 NodeClass nodeClass; 00159 00160 int err; 00161 00162 InitMaster(); 00163 00164 //StartMasterThread(100, nodeClass.Axis); 00165 00166 // TODO init als funktion für API bereitstellen 00167 // init of axis 00168 /* err = nodeClass.Axis->Init(); 00169 if (err!=0) 00170 { ROS_INFO("Init of CAN-Master failed. Error: %i",err); return -1;} 00171 else 00172 { ROS_INFO("Init of CAN-Master successfully."); } 00173 00174 // TODO homing als funktion für API bereitstellen 00175 //homing 00176 err = nodeClass.Axis->Homing(); 00177 if (err!=0) 00178 { ROS_INFO("Homing of axis failed. Code: %i", err); } 00179 else 00180 { ROS_INFO("Homing of axis complete."); } 00181 */ 00182 int counter = 0; 00183 00184 // main loop 00185 ros::Rate loop_rate(100); // Hz 00186 while(nodeClass.n.ok()) 00187 { 00188 00189 //nodeClass.Axis->SendSYNC(); 00190 // motorcontroller stat | enalbe IP-mode 00191 //nodeClass.Axis->WritePDO((0x011F),counter); 00192 00193 counter++; 00194 ros::spinOnce(); 00195 loop_rate.sleep(); 00196 } 00197 00198 // terminate all threads 00199 exit(0); 00200 00201 return 0; 00202 } 00203 00204