jackal_base.cpp
Go to the documentation of this file.
00001 
00034 #include <string>
00035 #include <boost/asio/io_service.hpp>
00036 #include <boost/thread.hpp>
00037 #include <boost/chrono.hpp>
00038 
00039 #include "controller_manager/controller_manager.h"
00040 #include "jackal_base/jackal_diagnostic_updater.h"
00041 #include "jackal_base/jackal_hardware.h"
00042 #include "ros/ros.h"
00043 #include "rosserial_server/serial_session.h"
00044 
00045 typedef boost::chrono::steady_clock time_source;
00046 
00047 void controlThread(ros::Rate rate, jackal_base::JackalHardware* robot, controller_manager::ControllerManager* cm)
00048 {
00049   time_source::time_point last_time = time_source::now();
00050 
00051   while (1)
00052   {
00053     // Calculate monotonic time elapsed
00054     time_source::time_point this_time = time_source::now();
00055     boost::chrono::duration<double> elapsed_duration = this_time - last_time;
00056     ros::Duration elapsed(elapsed_duration.count());
00057     last_time = this_time;
00058 
00059     robot->copyJointsFromHardware();
00060     cm->update(ros::Time::now(), elapsed);
00061     robot->publishDriveFromController();
00062     rate.sleep();
00063   }
00064 }
00065 
00066 int main(int argc, char* argv[])
00067 {
00068   // Initialize ROS node.
00069   ros::init(argc, argv, "jackal_node");
00070   jackal_base::JackalHardware jackal;
00071 
00072   // Create the serial rosserial server in a background ASIO event loop.
00073   std::string port;
00074   ros::param::param<std::string>("~port", port, "/dev/jackal");
00075   boost::asio::io_service io_service;
00076   new rosserial_server::SerialSession(io_service, port, 115200);
00077   boost::thread(boost::bind(&boost::asio::io_service::run, &io_service));
00078 
00079   // Background thread for the controls callback.
00080   ros::NodeHandle controller_nh("");
00081   controller_manager::ControllerManager cm(&jackal, controller_nh);
00082   boost::thread(boost::bind(controlThread, ros::Rate(50), &jackal, &cm));
00083 
00084   // Create diagnostic updater, to update itself on the ROS thread.
00085   jackal_base::JackalDiagnosticUpdater jackal_diagnostic_updater;
00086 
00087   // Foreground ROS spinner for ROS callbacks, including rosserial, diagnostics
00088   ros::spin();
00089 
00090   return 0;
00091 }


jackal_base
Author(s): Mike Purvis
autogenerated on Thu Jul 4 2019 19:48:56