From 4c39fba183a66b7da1955f5cef26d93272f7d21e Mon Sep 17 00:00:00 2001 From: FIRST_NAME LAST_NAMEKavyashree Date: Mon, 1 Nov 2021 13:46:29 -0400 Subject: [PATCH 1/2] Add custom string message to publisher --- src/talker.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/talker.cpp b/src/talker.cpp index 2b3dda2..ac6a900 100644 --- a/src/talker.cpp +++ b/src/talker.cpp @@ -100,7 +100,7 @@ int main(int argc, char **argv) { std_msgs::String msg; std::stringstream ss; - ss << "hello world " << count; + ss << " Fear the turtle " << count; msg.data = ss.str(); // %EndTag(FILL_MESSAGE)% From 96dd0ec9bf291431443990fd585d8627357afdc1 Mon Sep 17 00:00:00 2001 From: FIRST_NAME LAST_NAMEKavyashree Date: Mon, 1 Nov 2021 14:04:42 -0400 Subject: [PATCH 2/2] Check and fix Cppcheck cpplint errors, add results --- Results/cppcheckoutput.txt | 4 ++++ Results/cpplintoutput.txt | 2 ++ src/listener.cpp | 42 +++++++++++++++++++------------------- src/talker.cpp | 35 ++++--------------------------- 4 files changed, 31 insertions(+), 52 deletions(-) create mode 100644 Results/cppcheckoutput.txt create mode 100644 Results/cpplintoutput.txt diff --git a/Results/cppcheckoutput.txt b/Results/cppcheckoutput.txt new file mode 100644 index 0000000..b1b99e4 --- /dev/null +++ b/Results/cppcheckoutput.txt @@ -0,0 +1,4 @@ +Checking src/listener.cpp ... +1/2 files checked 47% done +Checking src/talker.cpp ... +2/2 files checked 100% done diff --git a/Results/cpplintoutput.txt b/Results/cpplintoutput.txt new file mode 100644 index 0000000..20dd80c --- /dev/null +++ b/Results/cpplintoutput.txt @@ -0,0 +1,2 @@ +Done processing ./src/listener.cpp +Done processing ./src/talker.cpp diff --git a/src/listener.cpp b/src/listener.cpp index 22898e0..a12ec7c 100644 --- a/src/listener.cpp +++ b/src/listener.cpp @@ -33,20 +33,19 @@ * This tutorial demonstrates simple receipt of messages over the ROS system. */ // %Tag(CALLBACK)% -void chatterCallback(const std_msgs::String::ConstPtr& msg) -{ +void chatterCallback(const std_msgs::String::ConstPtr& msg) { ROS_INFO("I heard: [%s]", msg->data.c_str()); } // %EndTag(CALLBACK)% -int main(int argc, char **argv) -{ +int main(int argc, char** argv) { /** * The ros::init() function needs to see argc and argv so that it can perform - * any ROS arguments and name remapping that were provided at the command line. - * For programmatic remappings you can use a different version of init() which takes - * remappings directly, but for most command-line programs, passing argc and argv is - * the easiest way to do it. The third argument to init() is the name of the node. + * any ROS arguments and name remapping that were provided at the command + * line. For programmatic remappings you can use a different version of init() + * which takes remappings directly, but for most command-line programs, + * passing argc and argv is the easiest way to do it. The third argument to + * init() is the name of the node. * * You must call one of the versions of ros::init() before using any other * part of the ROS system. @@ -55,8 +54,8 @@ int main(int argc, char **argv) /** * NodeHandle is the main access point to communications with the ROS system. - * The first NodeHandle constructed will fully initialize this node, and the last - * NodeHandle destructed will close down the node. + * The first NodeHandle constructed will fully initialize this node, and the + * last NodeHandle destructed will close down the node. */ ros::NodeHandle n; @@ -66,27 +65,28 @@ int main(int argc, char **argv) * master node, which keeps a registry of who is publishing and who * is subscribing. Messages are passed to a callback function, here * called chatterCallback. subscribe() returns a Subscriber object that you - * must hold on to until you want to unsubscribe. When all copies of the Subscriber - * object go out of scope, this callback will automatically be unsubscribed from - * this topic. + * must hold on to until you want to unsubscribe. When all copies of the + * Subscriber object go out of scope, this callback will automatically be + * unsubscribed from this topic. * * The second parameter to the subscribe() function is the size of the message * queue. If messages are arriving faster than they are being processed, this - * is the number of messages that will be buffered up before beginning to throw - * away the oldest ones. + * is the number of messages that will be buffered up before beginning to + * throw away the oldest ones. */ -// %Tag(SUBSCRIBER)% + // %Tag(SUBSCRIBER)% ros::Subscriber sub = n.subscribe("chatter", 1000, chatterCallback); -// %EndTag(SUBSCRIBER)% + // %EndTag(SUBSCRIBER)% /** * ros::spin() will enter a loop, pumping callbacks. With this version, all - * callbacks will be called from within this thread (the main one). ros::spin() - * will exit when Ctrl-C is pressed, or the node is shutdown by the master. + * callbacks will be called from within this thread (the main one). + * ros::spin() will exit when Ctrl-C is pressed, or the node is shutdown by + * the master. */ -// %Tag(SPIN)% + // %Tag(SPIN)% ros::spin(); -// %EndTag(SPIN)% + // %EndTag(SPIN)% return 0; } diff --git a/src/talker.cpp b/src/talker.cpp index ac6a900..4461b3b 100644 --- a/src/talker.cpp +++ b/src/talker.cpp @@ -25,15 +25,11 @@ * @brief Demonstrates simple sending of messages over the ROS system. */ -// %Tag(FULLTEXT)% -// %Tag(ROS_HEADER)% +// Include required headers +#include + #include "ros/ros.h" -// %EndTag(ROS_HEADER)% -// %Tag(MSG_HEADER)% #include "std_msgs/String.h" -// %EndTag(MSG_HEADER)% - -#include int main(int argc, char **argv) { /** @@ -47,18 +43,14 @@ int main(int argc, char **argv) { * You must call one of the versions of ros::init() before using any other * part of the ROS system. */ - // %Tag(INIT)% ros::init(argc, argv, "talker"); - // %EndTag(INIT)% /** * NodeHandle is the main access point to communications with the ROS system. * The first NodeHandle constructed will fully initialize this node, and the * last NodeHandle destructed will close down the node. */ - // %Tag(NODEHANDLE)% ros::NodeHandle n; - // %EndTag(NODEHANDLE)% /** * The advertise() function is how you tell ROS that you want to @@ -77,36 +69,25 @@ int main(int argc, char **argv) { * than we can send them, the number here specifies how many messages to * buffer up before throwing some away. */ - // %Tag(PUBLISHER)% ros::Publisher chatter_pub = n.advertise("chatter", 1000); - // %EndTag(PUBLISHER)% - - // %Tag(LOOP_RATE)% ros::Rate loop_rate(10); - // %EndTag(LOOP_RATE)% /** * A count of how many messages we have sent. This is used to create * a unique string for each message. */ - // %Tag(ROS_OK)% int count = 0; while (ros::ok()) { - // %EndTag(ROS_OK)% /** * This is a message object. You stuff it with data, and then publish it. */ - // %Tag(FILL_MESSAGE)% std_msgs::String msg; std::stringstream ss; - ss << " Fear the turtle " << count; + ss << " The counter is set to : " << count << ". \tFear the turtle"; msg.data = ss.str(); - // %EndTag(FILL_MESSAGE)% - // %Tag(ROSCONSOLE)% ROS_INFO("%s", msg.data.c_str()); - // %EndTag(ROSCONSOLE)% /** * The publish() function is how you send messages. The parameter @@ -114,21 +95,13 @@ int main(int argc, char **argv) { * given as a template parameter to the advertise<>() call, as was done * in the constructor above. */ - // %Tag(PUBLISH)% chatter_pub.publish(msg); - // %EndTag(PUBLISH)% - // %Tag(SPINONCE)% ros::spinOnce(); - // %EndTag(SPINONCE)% - - // %Tag(RATE_SLEEP)% loop_rate.sleep(); - // %EndTag(RATE_SLEEP)% ++count; } return 0; } // %EndTag(FULLTEXT)% -