Skip to content
This repository has been archived by the owner on Sep 4, 2022. It is now read-only.

ROS CPP Publisher Scaffold

sbt-tbs edited this page May 10, 2014 · 1 revision

`

/*
* ROS C++ Scaffold
* Author: Sean Thompson for BlueSat
* Date: 10/05/2014
*/

//include the ros package and the we need
#include "ros/ros.h"
// include the .h file for the msgType(s) you need to use
// #include "*msgPackage*/*msgType*.h"
#include "geometry_msgs/Twist.h"


int main(int argc, char **argv) {

   //initialise the ros package
   // ros::init(argc, argv, "*programName*");
   ros::init(argc, argv, "navigator");

   //a nodehandle is used to communiate with the rest of ros
   ros::NodeHandle n;


   //this tells ros you want to publish to the robot
   // replace the **genericNames** with actual types and packages in the line below for concrete/actual use
   //ros::Publisher **topicName = n.advertise<**msgPackage**::**msgType**>("/husky/cmd_vel", **topicBufferSize**);


   ros::Rate loop_rate(10);

   while(ros::ok()) { //loop whilst ros is running
     
       //create a twist message type
       // replace the *genericNames* with actual types and packages in the line below for concrete/actual use
       //*msgPackage*::*msgType* *msgVariable*;
       geometry_msgs::Twist msg;
       // Set msg values, the values will vary message to message
       msg.linear.x = 1.0;
       msg.linear.y = 1.0;
       msg.linear.z = 1.0;
    
       msg.angular.x = 0.0;
       msg.angular.y = 0.0;
       msg.angular.x = 0.0;
    
    
       //indicate we are sending
       ROS_INFO("Sending\n"); 
    
       //*topicName*.publish(*msgVariable*);        
       vel_pub.publish(msg);

       ros::spinOnce();
       loop_rate.sleep();
   }

   return 0;

}

`