00001 /* 00002 * Copyright (c) 2013, Shadow Robot Company, All rights reserved. 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Lesser General Public 00006 * License as published by the Free Software Foundation; either 00007 * version 3.0 of the License, or (at your option) any later version. 00008 * 00009 * This library is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Lesser General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public 00015 * License along with this library. 00016 */ 00017 00024 #ifndef _SPI_BASE_CONTROLLER_H_ 00025 #define _SPI_BASE_CONTROLLER_H_ 00026 00027 #include <ros/node_handle.h> 00028 00029 #include <controller_interface/controller.h> 00030 #include <ros_ethercat_model/robot_state.hpp> 00031 #include <sr_ronex_hardware_interface/spi_hardware_interface.hpp> 00032 #include <realtime_tools/realtime_publisher.h> 00033 #include <sr_ronex_utilities/sr_ronex_utilities.hpp> 00034 #include <queue> 00035 00036 namespace ronex 00037 { 00038 struct SplittedSPICommand 00039 { 00040 SPI_PACKET_OUT packet; 00041 00042 SplittedSPICommand() : packet() 00043 {} 00044 00045 SplittedSPICommand(SplittedSPICommand* copy_me) 00046 { 00047 this->packet = copy_me->packet; 00048 } 00049 }; 00050 00051 class SPIBaseController 00052 : public controller_interface::Controller<ros_ethercat_model::RobotState> 00053 { 00054 public: 00055 SPIBaseController(); 00056 00057 virtual bool init(ros_ethercat_model::RobotState* robot, ros::NodeHandle &n); 00058 00059 virtual void starting(const ros::Time&); 00060 00064 virtual void update(const ros::Time&, const ros::Duration&); 00065 00066 protected: 00067 ros::NodeHandle node_; 00068 00070 std::string topic_prefix_; 00071 00072 int loop_count_; 00073 00074 ronex::SPI* spi_; 00075 00076 std::vector<std::queue<SplittedSPICommand*> > command_queue_; 00077 std::vector<std::queue<std::pair<SplittedSPICommand*, SPI_PACKET_IN* > > > status_queue_; 00078 00079 uint16_t cmd_pin_output_states_pre_; 00080 uint16_t cmd_pin_output_states_post_; 00081 00082 bool pre_init_(ros_ethercat_model::RobotState* robot, ros::NodeHandle &n); 00083 00084 void copy_splitted_to_cmd_(uint16_t spi_index); 00085 private: 00086 bool new_command; 00087 }; 00088 } 00089 00090 /* For the emacs weenies in the crowd. 00091 Local Variables: 00092 c-basic-offset: 2 00093 End: 00094 */ 00095 00096 #endif /* _SPI_BASE_CONTROLLER_H_ */