00001 /* 00002 * Copyright (c) 2016, 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 00023 #ifndef SR_RONEX_CONTROLLERS_SPI_SENSOR_READ_CONTROLLER_H 00024 #define SR_RONEX_CONTROLLERS_SPI_SENSOR_READ_CONTROLLER_H 00025 00026 #include <ros/node_handle.h> 00027 #include <boost/ptr_container/ptr_vector.hpp> 00028 #include <utility> 00029 #include <vector> 00030 00031 #include "sr_ronex_controllers/spi_base_controller.hpp" 00032 #include <sr_ronex_msgs/SPI.h> 00033 00034 #include <dynamic_reconfigure/server.h> 00035 #include "sr_ronex_drivers/SPIConfig.h" 00036 #include "std_msgs/Float64MultiArray.h" 00037 00038 namespace ronex 00039 { 00040 class SPISensorReadController 00041 : public SPIBaseController 00042 { 00043 public: 00044 virtual bool init(ros_ethercat_model::RobotStateInterface* robot, ros::NodeHandle &n); 00045 00046 void update(const ros::Time&, const ros::Duration&); 00047 std::vector<double> get_sensor_value(); 00048 std::vector<int> get_spi_channel(); 00049 00050 protected: 00051 ros::Time last_publish_time_; 00052 static const double publish_rate_; 00053 00054 private: 00055 std::vector<int> spi_channel_; 00056 static const int default_spi_channel_; 00057 static const size_t sensor_message_length_; 00058 static const size_t spi_mode_; 00059 00060 00061 std_msgs::Float64MultiArray sensor_msg_; 00062 std::vector<ros::ServiceServer> command_srv_; 00063 realtime_tools::RealtimePublisher<std_msgs::Float64MultiArray> sensor_data_publisher_; 00064 // vector containing one command per spi output. 00065 // Some parameters of these commands are updated through the dynamic reconfigure interface 00066 // The data packet is updated from the service. 00067 std::vector<SplittedSPICommand> standard_commands_; 00068 00069 std::vector<uint16_t> chip_select_masks_; 00070 bool first_run_; 00071 }; 00072 } // namespace ronex 00073 00074 /* For the emacs weenies in the crowd. 00075 Local Variables: 00076 c-basic-offset: 2 00077 End: 00078 */ 00079 00080 #endif // SR_RONEX_CONTROLLERS_SPI_SENSOR_READ_CONTROLLER_H