mirror of
https://github.com/nasa/trick.git
synced 2024-12-25 07:41:08 +00:00
4c471eb32d
Introducing a pubish and subscribe example sim. The publisher includes a ROS msg file that is processed by ROS into a header file. refs #190
35 lines
727 B
C++
35 lines
727 B
C++
|
|
#include "std_msgs/String.h"
|
|
#include "trick/exec_proto.h"
|
|
#include "ros_publish.hh"
|
|
|
|
#include "Num.h"
|
|
|
|
RosPublish::RosPublish() : count(0) {}
|
|
|
|
int RosPublish::init() {
|
|
msg_pub = n.advertise<trick_msgs::Num>("num_chatter", 1000) ;
|
|
return 0 ;
|
|
}
|
|
|
|
int RosPublish::publish() {
|
|
if ( ros::ok() ) {
|
|
trick_msgs::Num tn ;
|
|
tn.first_name = "Hakeem" ;
|
|
tn.last_name = "Olajuwon" ;
|
|
tn.date = "March 29, 1990" ;
|
|
tn.points = 18 ;
|
|
tn.rebounds = 16 ;
|
|
tn.blocks = 11 ;
|
|
tn.assists = 10 ;
|
|
std::cout << tn << std::endl ;
|
|
msg_pub.publish(tn) ;
|
|
|
|
ros::spinOnce() ;
|
|
} else {
|
|
exec_terminate(__FILE__, "ros not ok") ;
|
|
}
|
|
return 0 ;
|
|
}
|
|
|