Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auv task basher666 #41

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions assignment_1/basher666_print_squares/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
20 changes: 20 additions & 0 deletions assignment_1/basher666_print_squares/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<package>
<name>basher666_print_squares</name>
<version>0.0.0</version>
<description>The basher666_print_squares package</description>

<maintainer email="[email protected]">swastik</maintainer>

<license>MIT</license>

<buildtool_depend>catkin</buildtool_depend>
<build_depend>roscpp</build_depend>
<build_depend>std_msgs</build_depend>
<run_depend>roscpp</run_depend>
<run_depend>std_msgs</run_depend>

<export>

</export>
</package>
24 changes: 24 additions & 0 deletions assignment_1/basher666_print_squares/src/basher666_numbers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "ros/ros.h"
#include "std_msgs/Int64.h"

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<std_msgs::Int64>("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;
}
27 changes: 27 additions & 0 deletions assignment_1/basher666_print_squares/src/basher666_print.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "ros/ros.h"
#include "std_msgs/Int64.h"

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;
}
31 changes: 31 additions & 0 deletions assignment_1/basher666_print_squares/src/basher666_squares.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "ros/ros.h"
#include "std_msgs/Int64.h"

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<std_msgs::Int64>("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::spin();

return 0;
}