From fd01c2271a2aaff47010b219231aceb72a2e37e6 Mon Sep 17 00:00:00 2001 From: Swastik Haldar Date: Tue, 21 Feb 2017 18:19:12 +0530 Subject: [PATCH 1/2] auv task for basher666 --- .../basher666_print_squares/CMakeLists.txt | 27 ++++++++++ .../basher666_print_squares/package.xml | 54 +++++++++++++++++++ .../src/basher666_numbers.cpp | 28 ++++++++++ .../src/basher666_print.cpp | 30 +++++++++++ .../src/basher666_squares.cpp | 34 ++++++++++++ 5 files changed, 173 insertions(+) create mode 100644 assignment_1/basher666_print_squares/CMakeLists.txt create mode 100644 assignment_1/basher666_print_squares/package.xml create mode 100644 assignment_1/basher666_print_squares/src/basher666_numbers.cpp create mode 100644 assignment_1/basher666_print_squares/src/basher666_print.cpp create mode 100644 assignment_1/basher666_print_squares/src/basher666_squares.cpp diff --git a/assignment_1/basher666_print_squares/CMakeLists.txt b/assignment_1/basher666_print_squares/CMakeLists.txt new file mode 100644 index 0000000..0ff347f --- /dev/null +++ b/assignment_1/basher666_print_squares/CMakeLists.txt @@ -0,0 +1,27 @@ +cmake_minimum_required(VERSION 2.8.3) +project(basher666_print_squares) + + +find_package(catkin REQUIRED COMPONENTS + roscpp + std_msgs +) + + +catkin_package() + +include_directories( + ${catkin_INCLUDE_DIRS} +) + + +include_directories(include ${catkin_INCLUDE_DIRS}) + +add_executable(basher666_numbers src/basher666_numbers.cpp) +target_link_libraries(basher666_numbers ${catkin_LIBRARIES}) + +add_executable(basher666_squares src/basher666_squares.cpp) +target_link_libraries(basher666_squares ${catkin_LIBRARIES}) + +add_executable(basher666_print src/basher666_print.cpp) +target_link_libraries(basher666_print ${catkin_LIBRARIES}) diff --git a/assignment_1/basher666_print_squares/package.xml b/assignment_1/basher666_print_squares/package.xml new file mode 100644 index 0000000..c748105 --- /dev/null +++ b/assignment_1/basher666_print_squares/package.xml @@ -0,0 +1,54 @@ + + + basher666_print_squares + 0.0.0 + The basher666_print_squares package + + + + + swastik + + + + + + MIT + + + + + + + + + + + + + + + + + + + + + + + + + + catkin + roscpp + std_msgs + roscpp + std_msgs + + + + + + + + diff --git a/assignment_1/basher666_print_squares/src/basher666_numbers.cpp b/assignment_1/basher666_print_squares/src/basher666_numbers.cpp new file mode 100644 index 0000000..c9f5682 --- /dev/null +++ b/assignment_1/basher666_print_squares/src/basher666_numbers.cpp @@ -0,0 +1,28 @@ +#include "ros/ros.h" +#include "std_msgs/Int64.h" +#include +#include + +using namespace std; + +int main(int argc,char **argv) +{ + ros::init(argc,argv,"basher666_numbers"); //initializing the node basher666_numbers + + ros::NodeHandle n; + + ros::Publisher num_pub=n.advertise("topic_numbers",1000); //setting the topic_numbers as the topic + ros::Rate loop_rate(1); //setting loop_rate as 1 hz + int count=1; + while(ros::ok()) + { + std_msgs::Int64 x; + x.data=count; + num_pub.publish(x); //publishing the data to the topic + ROS_INFO("%ld sent to topic_numbers\n",x.data); + ros::spinOnce(); + loop_rate.sleep(); + count++; + } + return 0; +} diff --git a/assignment_1/basher666_print_squares/src/basher666_print.cpp b/assignment_1/basher666_print_squares/src/basher666_print.cpp new file mode 100644 index 0000000..ac1e5ad --- /dev/null +++ b/assignment_1/basher666_print_squares/src/basher666_print.cpp @@ -0,0 +1,30 @@ +#include "ros/ros.h" +#include "std_msgs/Int64.h" +#include + +using namespace std; + +void sqcallback(const std_msgs::Int64::ConstPtr& sqr) //callback function for topic_squares +{ + ROS_INFO("%ld received from topic_squares",sqr->data); + return; +} + +void numcallback(const std_msgs::Int64::ConstPtr& num) //callback function for topic_numbers +{ + ROS_INFO("%ld received from topic_numbers",num->data); + return; +} + +int main(int argc,char **argv) +{ + ros::init(argc,argv,"basher666_print"); + ros::NodeHandle n; + ros::Rate loop_rate(1); //for 1 hz rate + + ros::Subscriber sub1=n.subscribe("topic_numbers",1000,numcallback); //subscribing to the topic_numbers + ros::Subscriber sub2=n.subscribe("topic_squares",1000,sqcallback); // subscribing to the topic_squares + ros::spin(); + loop_rate.sleep(); + return 0; +} diff --git a/assignment_1/basher666_print_squares/src/basher666_squares.cpp b/assignment_1/basher666_print_squares/src/basher666_squares.cpp new file mode 100644 index 0000000..02e41fa --- /dev/null +++ b/assignment_1/basher666_print_squares/src/basher666_squares.cpp @@ -0,0 +1,34 @@ +#include "ros/ros.h" +#include "std_msgs/Int64.h" +#include +using namespace std; + +ros::Publisher sq_pub; //creating the publisher object globally for convenience +void numberscallback(const std_msgs::Int64::ConstPtr& num) +{ + ROS_INFO("heard %ld from topic_numbers \n",num->data); + std_msgs::Int64 sq; + sq.data=(num->data)*(num->data); + + if(ros::ok()) //publishing the square only once for each number from topic_numbers + { + sq_pub.publish(sq); + ROS_INFO("sent %ld to topic_squares\n",sq.data); + ros::spinOnce(); + //loop_rate.sleep(); + } + +} +int main(int argc,char **argv) +{ + ros::init(argc,argv,"basher666_squares"); + ros::NodeHandle n; + ros::NodeHandle n2; + ros::Rate loop_rate(1); + sq_pub=n2.advertise("topic_squares",1000); //selecting topic_squares as the topic to publish + ros::Subscriber square=n.subscribe("topic_numbers",1000,numberscallback); //selecting topic_numbers as the topic to subscribe + ROS_INFO("hahahaha \n"); + ros::spin(); + + return 0; +} From 0afcd58e4423f19b657cf719490e4d47f7c5c32e Mon Sep 17 00:00:00 2001 From: Swastik Haldar Date: Wed, 22 Feb 2017 14:14:38 +0530 Subject: [PATCH 2/2] removed unnecessary tags and header files --- .../basher666_print_squares/package.xml | 34 ------------------- .../src/basher666_numbers.cpp | 4 --- .../src/basher666_print.cpp | 3 -- .../src/basher666_squares.cpp | 3 -- 4 files changed, 44 deletions(-) diff --git a/assignment_1/basher666_print_squares/package.xml b/assignment_1/basher666_print_squares/package.xml index c748105..2044e04 100644 --- a/assignment_1/basher666_print_squares/package.xml +++ b/assignment_1/basher666_print_squares/package.xml @@ -4,51 +4,17 @@ 0.0.0 The basher666_print_squares package - - - swastik - - - - MIT - - - - - - - - - - - - - - - - - - - - - - - - catkin roscpp std_msgs roscpp std_msgs - - - diff --git a/assignment_1/basher666_print_squares/src/basher666_numbers.cpp b/assignment_1/basher666_print_squares/src/basher666_numbers.cpp index c9f5682..ffdacb7 100644 --- a/assignment_1/basher666_print_squares/src/basher666_numbers.cpp +++ b/assignment_1/basher666_print_squares/src/basher666_numbers.cpp @@ -1,9 +1,5 @@ #include "ros/ros.h" #include "std_msgs/Int64.h" -#include -#include - -using namespace std; int main(int argc,char **argv) { diff --git a/assignment_1/basher666_print_squares/src/basher666_print.cpp b/assignment_1/basher666_print_squares/src/basher666_print.cpp index ac1e5ad..92b682b 100644 --- a/assignment_1/basher666_print_squares/src/basher666_print.cpp +++ b/assignment_1/basher666_print_squares/src/basher666_print.cpp @@ -1,8 +1,5 @@ #include "ros/ros.h" #include "std_msgs/Int64.h" -#include - -using namespace std; void sqcallback(const std_msgs::Int64::ConstPtr& sqr) //callback function for topic_squares { diff --git a/assignment_1/basher666_print_squares/src/basher666_squares.cpp b/assignment_1/basher666_print_squares/src/basher666_squares.cpp index 02e41fa..21e1fd2 100644 --- a/assignment_1/basher666_print_squares/src/basher666_squares.cpp +++ b/assignment_1/basher666_print_squares/src/basher666_squares.cpp @@ -1,7 +1,5 @@ #include "ros/ros.h" #include "std_msgs/Int64.h" -#include -using namespace std; ros::Publisher sq_pub; //creating the publisher object globally for convenience void numberscallback(const std_msgs::Int64::ConstPtr& num) @@ -27,7 +25,6 @@ int main(int argc,char **argv) ros::Rate loop_rate(1); sq_pub=n2.advertise("topic_squares",1000); //selecting topic_squares as the topic to publish ros::Subscriber square=n.subscribe("topic_numbers",1000,numberscallback); //selecting topic_numbers as the topic to subscribe - ROS_INFO("hahahaha \n"); ros::spin(); return 0;