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 1 commit
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})
54 changes: 54 additions & 0 deletions assignment_1/basher666_print_squares/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0"?>
<package>
<name>basher666_print_squares</name>
<version>0.0.0</version>
<description>The basher666_print_squares package</description>

<!-- One maintainer tag required, multiple allowed, one person per tag -->
<!-- Example: -->
<!-- <maintainer email="[email protected]">Jane Doe</maintainer> -->
<maintainer email="[email protected]">swastik</maintainer>


<!-- One license tag required, multiple allowed, one license per tag -->
<!-- Commonly used license strings: -->
<!-- BSD, MIT, Boost Software License, GPLv2, GPLv3, LGPLv2.1, LGPLv3 -->
<license>MIT</license>


<!-- Url tags are optional, but mutiple are allowed, one per tag -->
<!-- Optional attribute type can be: website, bugtracker, or repository -->
<!-- Example: -->
<!-- <url type="website">http://wiki.ros.org/basher666_print_squares</url> -->


<!-- Author tags are optional, mutiple are allowed, one per tag -->
<!-- Authors do not have to be maintianers, but could be -->
<!-- Example: -->
<!-- <author email="[email protected]">Jane Doe</author> -->


<!-- The *_depend tags are used to specify dependencies -->
<!-- Dependencies can be catkin packages or system dependencies -->
<!-- Examples: -->
<!-- Use build_depend for packages you need at compile time: -->
<!-- <build_depend>message_generation</build_depend> -->
<!-- Use buildtool_depend for build tool packages: -->
<!-- <buildtool_depend>catkin</buildtool_depend> -->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please clean up this file so that only the required lines are visible. Tag explanation is not required. 🙂

<!-- Use run_depend for packages you need at runtime: -->
<!-- <run_depend>message_runtime</run_depend> -->
<!-- Use test_depend for packages you need only for testing: -->
<!-- <test_depend>gtest</test_depend> -->
<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>


<!-- The export tag contains other, unspecified, tags -->
<export>
<!-- Other tools can request additional information be placed here -->

</export>
</package>
28 changes: 28 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,28 @@
#include "ros/ros.h"
#include "std_msgs/Int64.h"
#include <sstream>
#include <bits/stdc++.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need not import everything. Very few functions are required for this node, and it makes sense to import only those header files which are actually required.


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<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;
}
30 changes: 30 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,30 @@
#include "ros/ros.h"
#include "std_msgs/Int64.h"
#include <bits/stdc++.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the above comment.


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;
}
34 changes: 34 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,34 @@
#include "ros/ros.h"
#include "std_msgs/Int64.h"
#include <bits/stdc++.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

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<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_INFO("hahahaha \n");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove debug print statements from the submission 😄

ros::spin();

return 0;
}