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

shubhamjena_assignment1 #38

Open
wants to merge 4 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
26 changes: 26 additions & 0 deletions assignment_1/shubhamjena_print_squares/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
cmake_minimum_required(VERSION 2.8.3)
project(shubhamjena_print_squares)


find_package(catkin REQUIRED COMPONENTS roscpp rospy std_msgs genmsg)

## Generate added messages and services with any dependencies listed here
generate_messages(DEPENDENCIES std_msgs)

catkin_package()

include_directories(${catkin_INCLUDE_DIRS})

add_executable(numbers_shubhamjena src/numbers_shubhamjena.cpp)
target_link_libraries(numbers_shubhamjena ${catkin_LIBRARIES})
add_dependencies(numbers_shubhamjena shubhamjena_print_squares_generate_messages_cpp)

add_executable(squares_shubhamjena src/squares_shubhamjena.cpp)
target_link_libraries(squares_shubhamjena ${catkin_LIBRARIES})
add_dependencies(squares_shubhamjena shubhamjena_print_squares_generate_messages_cpp)

add_executable(print_shubhamjena src/print_shubhamjena.cpp)
target_link_libraries(print_shubhamjena ${catkin_LIBRARIES})
add_dependencies(print_shubhamjena shubhamjena_print_squares_generate_messages_cpp)


56 changes: 56 additions & 0 deletions assignment_1/shubhamjena_print_squares/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0"?>
<package>
<name>shubhamjena_print_squares</name>
<version>0.0.0</version>
<description>The shubhamjena_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]">shubham</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>TODO</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/shubhamjena_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> -->
<!-- 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>rospy</build_depend>
<build_depend>std_msgs</build_depend>
<run_depend>roscpp</run_depend>
<run_depend>rospy</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>
33 changes: 33 additions & 0 deletions assignment_1/shubhamjena_print_squares/src/numbers_shubhamjena.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "ros/ros.h"
#include "std_msgs/String.h"

#include <sstream>

int main(int argc, char **argv)
{
ros::init(argc, argv, "numbers_shubhamjena");
ros::NodeHandle n;
ros::Publisher num_pub = n.advertise<std_msgs::String>("topic_numbers", 1000);
ros::Rate loop_rate(1);

int count = 0;
while (ros::ok())
{
std_msgs::String msg;
std::stringstream ss;
ss<<count;
msg.data = ss.str();

num_pub.publish(msg);

ros::spinOnce();

loop_rate.sleep();
++count;
}


return 0;
}


28 changes: 28 additions & 0 deletions assignment_1/shubhamjena_print_squares/src/print_shubhamjena.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "ros/ros.h"
#include "std_msgs/String.h"


void topic_numbersCallback(const std_msgs::String::ConstPtr& msg)
{
ROS_INFO("topic_numbers [%s]", msg->data.c_str());
}

void topic_squaresCallback(const std_msgs::String::ConstPtr& msg)
{
ROS_INFO("topic_squares [%s]", msg->data.c_str());
}


int main(int argc, char **argv)
{
ros::init(argc, argv, "print_shubamjena");

ros::NodeHandle n;
ros::Subscriber sub1 = n.subscribe("topic_numbers", 1000, topic_numbersCallback);
ros::Subscriber sub2 = n.subscribe("topic_squares", 1000, topic_squaresCallback);

ros::spin();

return 0;
}

45 changes: 45 additions & 0 deletions assignment_1/shubhamjena_print_squares/src/squares_shubhamjena.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "ros/ros.h"
#include "std_msgs/String.h"
#include <sstream>

int a=0;

void topic_numbersCallback(const std_msgs::String::ConstPtr& msg)
{
a =atoi(msg->data.c_str());
a=a*a;

}



int main(int argc, char **argv)
{
ros::init(argc, argv, "squares_shubhamjena");

ros::NodeHandle n;
ros::Subscriber sub = n.subscribe("topic_numbers", 1000, topic_numbersCallback);

ros::Publisher sq_num_pub = n.advertise<std_msgs::String>("topic_squares",1000);


ros::Rate loop_rate(1);
while (ros::ok())
{
std_msgs::String msg;
std::stringstream ss;
ss<<a;
msg.data = ss.str();
sq_num_pub.publish(msg);
ros::spinOnce();
loop_rate.sleep();

}


ros::spin();

return 0;
}