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

Testing Publisher and Subscriber nodes

$ cd catkin_ws $ catkin_make $ source devel/setup.bash

$ roscore $ rosrun beginner_tutorials talker.py $ rosrun beginner_tutorials listener.py

Rospy Service & Client

Step1: Define the service message(srv file) Step2: Create a ROS server node Step3: Create a ROS client node Step4: Execute the service Step5: Consume the service by the client

Create srv folder inside beginner_tutorials. Make a service file AddTwoInts.srv inside srv folder.

int64 a

int64 b

---

int64 sum

Make changes in package.xml by adding these 2 lines, These lines will generate request and response It is responsible for reading service file and converting it to source code.

message_generation

message_runtime

Make changes in CMakelist.txt

Inside find_package Add the following line:

message_generation

Add Service file

add_service_files( FILES AddTwoInts.srv )

After making changes in package.xml and CMakelist.txt, Build your package

catkin_make source devel/setup.bash

Make a file add_two_ints_server.py inside scripts folder

#!/usr/bin/env python

from beginner_tutorials.srv import *
import rospy

def handle_add_two_ints(req):
    print "Returning [%s + %s = %s]"%(req.a, req.b, (req.a + req.b))
    return AddTwoIntsResponse(req.a + req.b)

def add_two_ints_server():
    rospy.init_node('add_two_ints_server')
    s = rospy.Service('add_two_ints', AddTwoInts, handle_add_two_ints)
    print "Ready to add two ints."
    rospy.spin()

if __name__ == "__main__":
    add_two_ints_server()

make the script executable by chmod +x add_two_ints_server.py

PreviousSubscriber in ROSNextAdd two int in ROS

Last updated 5 years ago

Was this helpful?