kuka_hardware_interface_node.cpp
Go to the documentation of this file.
00001 /*********************************************************************
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2014 Norwegian University of Science and Technology
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of the Norwegian University of Science and
00018  *     Technology, nor the names of its contributors may be used to
00019  *     endorse or promote products derived from this software without
00020  *     specific prior written permission.
00021  *
00022  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033  *  POSSIBILITY OF SUCH DAMAGE.
00034  *********************************************************************/
00035 
00036 /*
00037  * Author: Lars Tingelstad <lars.tingelstad@ntnu.no>
00038  */
00039 
00040 #include <kuka_rsi_hw_interface/kuka_hardware_interface.h>
00041 
00042 int main(int argc, char** argv)
00043 {
00044   ROS_INFO_STREAM_NAMED("hardware_interface", "Starting hardware interface...");
00045 
00046   ros::init(argc, argv, "kuka_rsi_hardware_interface");
00047 
00048   ros::AsyncSpinner spinner(2);
00049   spinner.start();
00050 
00051   ros::NodeHandle nh;
00052 
00053   kuka_rsi_hw_interface::KukaHardwareInterface kuka_rsi_hw_interface;
00054   kuka_rsi_hw_interface.configure();
00055 
00056   // Set up timers
00057   ros::Time timestamp;
00058   ros::Duration period;
00059   auto stopwatch_last = std::chrono::steady_clock::now();
00060   auto stopwatch_now = stopwatch_last;
00061 
00062   controller_manager::ControllerManager controller_manager(&kuka_rsi_hw_interface, nh);
00063 
00064   kuka_rsi_hw_interface.start();
00065 
00066   // Get current time and elapsed time since last read
00067   timestamp = ros::Time::now();
00068   stopwatch_now = std::chrono::steady_clock::now();
00069   period.fromSec(std::chrono::duration_cast<std::chrono::duration<double>>(stopwatch_now - stopwatch_last).count());
00070   stopwatch_last = stopwatch_now;
00071 
00072   // Run as fast as possible
00073   while (ros::ok())
00074   //while (!g_quit)
00075   {
00076     // Receive current state from robot
00077     if (!kuka_rsi_hw_interface.read(timestamp, period))
00078     {
00079       ROS_FATAL_NAMED("kuka_hardware_interface", "Failed to read state from robot. Shutting down!");
00080       ros::shutdown();
00081     }
00082 
00083     // Get current time and elapsed time since last read
00084     timestamp = ros::Time::now();
00085     stopwatch_now = std::chrono::steady_clock::now();
00086     period.fromSec(std::chrono::duration_cast<std::chrono::duration<double>>(stopwatch_now - stopwatch_last).count());
00087     stopwatch_last = stopwatch_now;
00088 
00089     // Update the controllers
00090     controller_manager.update(timestamp, period);
00091 
00092     // Send new setpoint to robot
00093     kuka_rsi_hw_interface.write(timestamp, period);
00094   }
00095 
00096   spinner.stop();
00097   ROS_INFO_STREAM_NAMED("hardware_interface", "Shutting down.");
00098 
00099   return 0;
00100 
00101 }


kuka_rsi_hw_interface
Author(s): Lars Tingelstad
autogenerated on Thu Jun 6 2019 17:56:48