md49_base_controller_node.cpp
Go to the documentation of this file.
1 
34 #include <ros/ros.h>
35 #include <geometry_msgs/Twist.h>
37 #include <md49_messages/md49_data.h>
38 #include <md49_messages/md49_encoders.h>
40 
41 int main( int argc, char* argv[] ){
42 
43  // *****************
44  // * Init as ROS node *
45  // *****************
46  ros::init(argc, argv, "base_controller" );
47  BaseController myBaseController;
48  ros::Rate loop_rate(10);
49  ROS_INFO("base_controller: base_controller running...");
50 
51  // *******************
52  // * Open serialport *
53  // *******************
54  myBaseController.open_serialport();
55 
56  // *****************************
57  // * Set initial MD49 settings *
58  // *****************************
59  myBaseController.init_md49(myBaseController.get_requested_speed_l(), myBaseController.get_requested_speed_r(), myBaseController.get_initial_md49_mode(), \
60  myBaseController.get_initial_md49_acceleration(), myBaseController.get_initial_md49_timeout(), myBaseController.get_initial_md49_regulator());
61 
62  // ************
63  // * Mainloop *
64  // ************
65  while(myBaseController.n.ok())
66  {
67  // set speed on MD49 via UART as set through /cmd_vel if speed_l or speed_r changed since last cycle
68  if ((myBaseController.get_requested_speed_l() != myBaseController.get_actual_speed_l()) || (myBaseController.get_requested_speed_r() != myBaseController.get_actual_speed_r()))
69  {
70  myBaseController.set_speed(myBaseController.get_requested_speed_l(),myBaseController.get_requested_speed_r());
71  myBaseController.set_actual_speed_l(myBaseController.get_requested_speed_l());
72  myBaseController.set_actual_speed_r(myBaseController.get_requested_speed_r());
73  ROS_INFO("base_controller: Set speed_l=%i and speed_r=%i on MD49", myBaseController.get_requested_speed_l(), myBaseController.get_requested_speed_r());
74  }
75  // Read encoder- data from MD49 via UART and publish encoder values as read to topic /md49_encoders
76  myBaseController.publish_encoders();
77  // Read other- data from MD49 via UART and publish MD49 data as read to topic /md49_data
78  myBaseController.publish_md49_data();
79  // Loop
80  ros::spinOnce();
81  loop_rate.sleep();
82  }// end.mainloop
83  return 1;
84 } // end.main
85 
int get_initial_md49_timeout()
get_initial_md49_timeout
int get_actual_speed_r()
get_actual_speed_r
int main(int argc, char *argv[])
void publish_md49_data()
This function reads data and parameters from MD49 and publishes them as topic /md49_data.
void publish_encoders()
This function reads encodervalues from MD49 and publishes them as topic /md49_encoders.
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void init_md49(int speed_l, int speed_r, int mode, int acceleration, bool timeout, bool regulator)
This function sets parameters for MD49 as read from config file or as set as defaults.
int get_initial_md49_mode()
get_initial_md49_mode
int get_actual_speed_l()
get_actual_speed_l
int get_requested_speed_l()
get_requested_speed_l
void set_actual_speed_r(int speed_r)
set_actual_speed_r
int get_initial_md49_regulator()
get_initial_md49_regulator
void open_serialport()
This function opens serial port MD49 is connected to.
#define ROS_INFO(...)
int get_requested_speed_r()
get_requested_speed_r
bool sleep()
void set_speed(int speed_l, int speed_r)
This function sets speed for left and right drive on MD49.
void set_actual_speed_l(int speed_l)
set_actual_speed_l
bool ok() const
ROSCPP_DECL void spinOnce()


md49_base_controller
Author(s): Fabian Prinzing
autogenerated on Mon Jun 10 2019 13:54:49