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

added assignment 1 #28

Open
wants to merge 20 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
36 changes: 36 additions & 0 deletions assignment_1/amit-patil_print_squares/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
cmake_minimum_required(VERSION 2.4.6)
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)

# Set the build type. Options are:
# Coverage : w/ debug symbols, w/o optimization, w/ code-coverage
# Debug : w/ debug symbols, w/o optimization
# Release : w/o debug symbols, w/ optimization
# RelWithDebInfo : w/ debug symbols, w/ optimization
# MinSizeRel : w/o debug symbols, w/ optimization, stripped binaries
#set(ROS_BUILD_TYPE RelWithDebInfo)

rosbuild_init()

#set the default path for built executables to the "bin" directory
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
#set the default path for built libraries to the "lib" directory
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

#uncomment if you have defined messages
rosbuild_genmsg()
#uncomment if you have defined services
rosbuild_gensrv()

#common commands for building c++ executables and libraries
#rosbuild_add_library(${PROJECT_NAME} src/amitpatil_numbers.cpp)
#target_link_libraries(${PROJECT_NAME} roscpp std_msgs)

#rosbuild_add_boost_directories()
#rosbuild_link_boost(${PROJECT_NAME} thread)
rosbuild_add_executable(amit-patil_numbers src/amitpatil_numbers.cpp)
rosbuild_add_executable(amit-patil_squares src/amitpatil_squares.cpp)
rosbuild_add_executable(amit-patil_print src/amitpatil_print.cpp)



#target_link_libraries(example ${PROJECT_NAME})
1 change: 1 addition & 0 deletions assignment_1/amit-patil_print_squares/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include $(shell rospack find mk)/cmake.mk
1 change: 1 addition & 0 deletions assignment_1/amit-patil_print_squares/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
amit-patil_print_suqares
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions assignment_1/amit-patil_print_squares/mainpage.dox
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
\mainpage
\htmlinclude manifest.html

\b amit_patil_print_squares

<!--
Provide an overview of your package.
-->

-->


*/
17 changes: 17 additions & 0 deletions assignment_1/amit-patil_print_squares/manifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<package>
<description brief="amit_patil_print_squares">

amit_patil_print_squares

</description>
<author>AMIT</author>
<license>BSD</license>
<review status="unreviewed" notes=""/>
<url>http://ros.org/wiki/amit_patil_print_squares</url>
<depend package="roscpp"/>
<depend package="std_msgs"/>


</package>


26 changes: 26 additions & 0 deletions assignment_1/amit-patil_print_squares/src/amitpatil_numbers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
includes all the necessary libraries required for common use.
*/
#include "ros/ros.h"
#include "std_msgs/Int32.h"

int main(int argc,char **argv)
{
ros::init(argc, argv, "numbers");
//initializes the ros and name the node as amit-patil_numbers
ros::NodeHandle n;
//creates handle to the node
ros::Publisher num_pub = n.advertise<std_msgs::Int32>("topic_numbers", 100);//used for publishing messages on the topic ,'topic_numbers' of length upto 100
ros::Rate loop_rate(1);//publishes messages at frequency at 1 Hz
int count = 1;//initialize counter
std_msgs::Int32 message;//message is of int 32
while (ros::ok())
{
message.data = count;//message is equal to counter
num_pub.publish(message);//message is published to topic through num_pub
ros::spinOnce();//processes callbacks
loop_rate.sleep();//sleeps for the remainimg time to get 1hz frequency
++count;//increment counter
}
return 0;
}
25 changes: 25 additions & 0 deletions assignment_1/amit-patil_print_squares/src/amitpatil_print.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
includes all the necessary libraries required for common use.
*/
#include "ros/ros.h"
#include "std_msgs/Int32.h"

void numbersCallback(const std_msgs::Int32::ConstPtr& message)
{
ROS_INFO("topic_numbers output: [%d]", message->data);
}
//output by topic_number
void squaresCallback(const std_msgs::Int32::ConstPtr& message)
{
ROS_INFO("topic_squares output: [%d]", message->data);
}
//output by topic_squares
int main(int argc, char **argv)
{
ros::init(argc, argv, "print");// initialize ros and node named amit-patil_print
ros::NodeHandle hdl;//handle is created for node
ros::Subscriber sub_numbers = hdl.subscribe("/topic_numbers", 100, numbersCallback);//subscribes to topic 'topic_numbers'
ros::Subscriber sub_squares = hdl.subscribe("/topic_squares", 100, squaresCallback);//subscribes to topic 'topic_squares'
ros::spin();
return 0;
}
38 changes: 38 additions & 0 deletions assignment_1/amit-patil_print_squares/src/amitpatil_squares.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
includes all the necessary libraries required for common use.
*/
#include <ros/ros.h>
#include "std_msgs/Int32.h"

//new class
class square
{
public:
square()
{
pub = n.advertise<std_msgs::Int32>("/topic_squares", 1);//publishes square to topic 'topic_squares'
sub = n.subscribe("/topic_numbers", 1, &square::callback, this);//subscribes to 'topic_number'
}

void callback(const std_msgs::Int32::ConstPtr& input)
{
std_msgs::Int32 output;//output of type int64
output.data = input->data*input->data;//square the input
pub.publish(output);
}

private:
ros::NodeHandle n;
ros::Publisher pub;
ros::Subscriber sub;

};


int main(int argc, char **argv)
{
ros::init(argc, argv, "squares");//initializes ros and node 'amit-patil_squares'
square new_obj;//object created from class square
ros::spin();//process when node is shut down
return 0;
}