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

Assignment 1 Submission (Amshumaan Varma) #57

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


find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
)


catkin_package(
# INCLUDE_DIRS include
# LIBRARIES print_squares
# CATKIN_DEPENDS roscpp rospy std_msgs
# DEPENDS system_lib
)


include_directories(
include
${catkin_INCLUDE_DIRS}
)

add_executable(g4gekkouga_numbers src/g4gekkouga_numbers.cpp)
target_link_libraries(g4gekkouga_numbers ${catkin_LIBRARIES})
add_dependencies(g4gekkouga_numbers beginner_tutorials_generate_messages_cpp)

add_executable(g4gekkouga_squares src/g4gekkouga_squares.cpp)
target_link_libraries(g4gekkouga_squares ${catkin_LIBRARIES})
add_dependencies(g4gekkouga_squares beginner_tutorials_generate_messages_cpp)

add_executable(g4gekkouga_print src/g4gekkouga_print.cpp)
target_link_libraries(g4gekkouga_print ${catkin_LIBRARIES})
add_dependencies(g4gekkouga_print beginner_tutorials_generate_messages_cpp)
27 changes: 27 additions & 0 deletions assignment_1/g4gekkouga_print_squares/print_squares/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0"?>
<package format="2">
<name>print_squares</name>
<version>0.1.0</version>
<description>The print_squares package</description>

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

<license>BSD</license>

<buildtool_depend>catkin</buildtool_depend>
<build_depend>roscpp</build_depend>
<build_depend>rospy</build_depend>
<build_depend>std_msgs</build_depend>
<build_depend>message_generation</build_depend>
<build_export_depend>roscpp</build_export_depend>
<build_export_depend>rospy</build_export_depend>
<build_export_depend>std_msgs</build_export_depend>
<exec_depend>roscpp</exec_depend>
<exec_depend>rospy</exec_depend>
<exec_depend>std_msgs</exec_depend>
<exec_depend>message_runtime</exec_depend>

<export>

</export>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* Publisher Node to Publish numbers from 1 onwards to the topic topic_numbers */

#include "ros/ros.h"
#include "std_msgs/Int64.h" //This is the type of message that is used for communation btw the nodes

int main(int argc, char **argv) {

ros::init(argc, argv, "g4gekkouga_numbers"); //

ros::NodeHandle n; //access point for the communation with the system

ros::Publisher topic_Numbers = n.advertise<std_msgs::Int64>("topic_numbers", 1000); // Now topic_Numbers can be used to communicate with the ROS to publish to topic_numbers

ros::Rate loop_rate(1); // Setting the number generation rate to 1HZ

int count = 0;

while (ros::ok()) { // returns false on ctrl C in the console

count++; //Starting from 1 and all following numbers

std_msgs::Int64 msg; // For publishing to the topic
msg.data = count;

topic_Numbers.publish(msg); // Publish the message to topic topic_numbers

ROS_INFO("Number Published : %d", msg.data); // Displays the number published to the topic in the correspoing console of this node

loop_rate.sleep(); // To maintain the 1Hz Frequency rate
}

return 0;
}



Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* Take the msg from topic_numbers and topic_squares and prints them accordingly */

#include "ros/ros.h"
#include "std_msgs/Int64.h" ////This is the type of message that is used for communation btw the nodes


ros::Subscriber topic_Numbers ; // to suscribe to topic_numbers

ros::Subscriber topic_Squares ; // to suscribe to topic_numbers

void getSquare(const std_msgs::Int64::ConstPtr& msgr) {

ROS_INFO("Received from topic_squares : %d \n", msgr->data); // as this fn is called when input received from topic_squares

return ;

}

void getNum(const std_msgs::Int64::ConstPtr& msgr) {

ROS_INFO("Received from topic_numbers : %d \n", msgr->data); // as this fn is called when input received from topic_numbers

return ;
}

int main(int argc, char **argv){

ros::init(argc, argv, "g4gekkouga_print");

ros::NodeHandle n; //access point for the communation with the system


topic_Numbers = n.subscribe("topic_numbers", 1000, getNum); // To receive msgs from topic_numbers

topic_Squares = n.subscribe("topic_squares", 1000, getSquare); // To receive msgs from topic_squares

ros::spin(); //required as there are callBacks to the functions

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* Computes the square of the numbers published to topic_numbers and published them to another topic topic_squares */

#include "ros/ros.h"
#include "std_msgs/Int64.h" //This is the type of message that is used for communation btw the nodes

ros::Publisher topic_Squares; // Made Global as to be used in callBack function also

void squareCalc(const std_msgs::Int64::ConstPtr& msgr) {

ROS_INFO("Number Received : %d \n", msgr->data); // Msg received from topic_numbers and displayed in corresponding terminal

std_msgs::Int64 msgp;
msgp.data = (msgr->data)*(msgr->data); //new msg type var to store the computed square of the input

topic_Squares.publish(msgp); // Publishing the computed square to topic_squares

/* Similarly here also the publishing rate is at 1Hz as the function is
called at this rate and publishes at the same rate */

ROS_INFO("Number Published : %d \n", msgp.data); // Msg Published to topic_squares and displayed in corresponding terminal

}

int main(int argc, char **argv) {

ros::init(argc, argv, "g4gekkouga_squares");

ros::NodeHandle n; //access point for the communation with the system

topic_Squares = n.advertise<std_msgs::Int64>("topic_squares", 1000); // Declared Globally and initializesd here to communicate with the ROS to publish to topic_squares

ros::Subscriber topic_Numbers = n.subscribe<std_msgs::Int64>("topic_numbers", 1000, squareCalc); //

/* There is no need for maintaing frequency manually as the publishing rate to topic_numbers is 1Hz ,
the callBack function will also take input at the rate of 1Hz */


ros::spin(); // Required as there are callBacks as long as the _numbers node is publishing or Ctrl C is encountered

return 0;
}