Everything about Drone
  • Drone (Dynamic Remotely Operated Navigation Equipment)
  • About Me
  • Types of Drones
  • Applications of Drone
  • Categories of Drones in India
  • Motor Configuration and Controls for Quadcopter
  • Assembling Pluto Drone
  • Dynamics of DRONEs
    • Force and Moments
    • Orientation and position
    • Moving in z, x & y direction
  • Sensors which are used on a Drone
  • Rules & Regulations
  • Testing & Executing codes
    • Acro Mode
    • Blow to Take Off
    • App Heading
    • Monitoring the Pressure Difference
    • Throw and Go
    • Flipping
  • Laser Cutting
  • Laser Cutting Procedure
  • 3D Printing Drone case
  • Table Tennis Game
  • ROS (Robotic Operating System)
    • ROS Master
    • ROS Nodes
    • ROS Topics
    • ROS Message
    • Workspace (catkin)
    • Examples
      • Creating ROS Workspace
      • Publisher in ROS
      • Subscriber in ROS
      • Testing Publisher and Subscriber nodes
      • Add two int in ROS
      • Building Nodes
      • Pluto Node
Powered by GitBook
On this page

Was this helpful?

  1. ROS (Robotic Operating System)
  2. Examples

Add two int in ROS

#!/usr/bin/env python

import sys
import rospy
from beginner_tutorials.srv import *

def add_two_ints_client(x, y):
    rospy.wait_for_service('add_two_ints')
    try:
        add_two_ints = rospy.ServiceProxy('add_two_ints', AddTwoInts)
        resp1 = add_two_ints(x, y)
        return resp1.sum
    except rospy.ServiceException, e:
        print "Service call failed: %s"%e

def usage():
    return "%s [x y]"%sys.argv[0]

if __name__ == "__main__":
    if len(sys.argv) == 3:
        x = int(sys.argv[1])
        y = int(sys.argv[2])
    else:
        print usage()
        sys.exit(1)
    print "Requesting %s+%s"%(x, y)
    print "%s + %s = %s"%(x, y, add_two_ints_client(x, y))

make the file executable by $ chmod +x add_two_ints_client.py

PreviousTesting Publisher and Subscriber nodesNextBuilding Nodes

Last updated 5 years ago

Was this helpful?

Here we add two ints which are single digit
We had tried adding 3 digit as well and it worked