[ROS Q&A] 153 Use ROSjects locally

[ROS Q&A] 153 Use ROSjects locally

 

In this video you will learn how to use a ROSject locally. In this case we will use the WAM-V from RobotX Challenge ROSject, but this applies for any ROSject

Related recourses mentioned in the video:

Commands to run locally the ROSject:

mkdir -p /home/rdaneel/Desktop/tutorial_ws/src
cd /home/rdaneel/Desktop/tutorial_ws
catkin_make

# Copy Files
catkin_make
# Se which dependencies you are lacking
# Install them
rosdep install –from-paths /home/rdaneel/Desktop/tutorial_ws –ignore-src –rosdistro=kinetic
# Clone Repo
git clone https://bitbucket.org/theconstructcore/spawn_robot_tools.git

 

[ROS Q&A] 152 – Publish on a topic for a certain period of time

[ROS Q&A] 152 – Publish on a topic for a certain period of time

 

This video tries to answer the following question found in the ROS Answers forum

In the video, we’ll show how to publish on a topic for a certain period of time by using the rospy Timer class, which allows to trigger events at a certain time.

RELATED LINKS

Robot Ignite Academy
ROS Basics course
ROS Development Studio (ROSDS)
Original question


We Love Feedback!

Did you like this video? Do you have questions about what is explained? Whatever the case, please leave a comment on the comments section below, so we can interact and learn from each other.

If you want to learn about other ROS topics, please let us know on the comments area and we will do a video about it.

[ROS Q&A] 150 – How to publish data changed in Dynamic Reconfigure

[ROS Q&A] 150 – How to publish data changed in Dynamic Reconfigure

 

This video shows how to use dynamic reconfigure client to change or receive updates about dynamic parameter value updates inside your node. Using a dynamic reconfigure client allows you to interact with these parameters outside the server node.

Step 0. Create a project in ROS Development Studio(ROSDS)

ROSDS helps you follow our tutorial in a fast pace without dealing without setting up an environment locally. If you haven’t had an account yet, you can create a free account here. Let’s create a new project and call it dynamic_reconfigure.

Step 1. Create the package

We’ll put our code in a new package called mypkg

cd ~/catkin_ws/src
catkin_create_pkg mypkg rospy
cd mypkg
mkdir cfg
mkdir scripts

We’ll create a Tutorials.cfg file under the cfg folder with the following content.

#!/usr/bin/env python
PACKAGE = "dynamic_tutorials"

from dynamic_reconfigure.parameter_generator_catkin import *

gen = ParameterGenerator()

gen.add("int_param",    int_t,    0, "An Integer parameter", 50,  0, 100)
gen.add("double_param", double_t, 0, "A double parameter",    .5, 0,   1)
gen.add("str_param",    str_t,    0, "A string parameter",  "Hello World")
gen.add("bool_param",   bool_t,   0, "A Boolean parameter",  True)

size_enum = gen.enum([ gen.const("Small",      int_t, 0, "A small constant"),
                       gen.const("Medium",     int_t, 1, "A medium constant"),
                       gen.const("Large",      int_t, 2, "A large constant"),
                       gen.const("ExtraLarge", int_t, 3, "An extra large constant")],
                     "An enum to set size")

gen.add("size", int_t, 0, "A size parameter which is edited via an enum", 1, 0, 3, edit_method=size_enum)

exit(gen.generate(PACKAGE, "dynamic_tutorials", "Tutorials"))

We also need a server.py file under the scripts folder to publish these parameters.

#!/usr/bin/env python

import rospy

from dynamic_reconfigure.server import Server
from dynamic_tutorials.cfg import TutorialsConfig

def callback(config, level):
    rospy.loginfo("""Reconfigure Request: {int_param}, {double_param},\ 
          {str_param}, {bool_param}, {size}""".format(**config))
    return config

if __name__ == "__main__":
    rospy.init_node("mypkg", anonymous = True)

    srv = Server(TutorialsConfig, callback)
    rospy.spin()

Step 2. rqt_reconfigure tool

Then we can launch the rqt_reconfigure tool from another shell

rosrun rqt_reconfigure rqt_reconfigure

Go to Tools->Graphical tool to open the GUI.

Since the parameters have not been published yet, you’ll see nothing on it.

Let’s run the server

rosrun mypkg server.py

You’ll see the parameters are in the gui now.

Step 3. Client

If you want to get the updated value from the tool, you’ll need a client. Let’s create a client.py under the scripts folder.

#!/usr/bin/env python

import rospy

import dynamic_reconfigure.client

def callback(config):
    rospy.loginfo("Config set to {int_param}, {double_param}, {str_param}, {bool_param}, {size}".format(**config))

if __name__ == "__main__":
    rospy.init_node("dynamic_client")

    client = dynamic_reconfigure.client.Client("mypkg", timeout=30, config_callback=callback)

    r = rospy.Rate(0.1)
    x = 0
    b = False
    while not rospy.is_shutdown():
        x = x+1
        if x>10:
            x=0
        b = not b
        #client.update_configuration({"int_param":x, "double_param":(1/(x+1)), "str_param":str(rospy.get_rostime()), "bool_param":b, "size":1})
        r.sleep()

After giving the file permission, you can run it with

rosrun mypkg client.py

You should receive the parameter now. If you want to update the parameters with the client. Please uncomment the client.update_configuration line in the script.

Want to learn more?

If you are interested in learning ROS, please check our ROS Basic in 5 Days course.

 

Edit by: Tony Huang


RELATED LINKS

Robot Ignite Academy
ROS Development Studio (ROSDS)
Original question

We Love Feedback!

Did you like this video? Do you have questions about what is explained? Whatever the case, please leave a comment on the comments section below, so we can interact and learn from each other.

If you want to learn about other ROS topics, please let us know on the comments area and we will do a video about it.

[ROS Q&A] 151 – Rviz receives LaserScan messages but doesn’t display them

[ROS Q&A] 151 – Rviz receives LaserScan messages but doesn’t display them

 

In the video, we’ll show how to properly visualize LaserScan messages in RViz.

RELATED LINKS

Robot Ignite Academy
ROS Basics course
ROS Development Studio (ROSDS)
Original question

Step 0. Create a project in ROS Development Studio(ROSDS)

ROSDS helps you follow our tutorial in a fast pace without dealing without setting up an environment locally. If you haven’t had an account yet, you can create a free account here. Let’s create a new project and call it laser_qa.

Step 1. Clone the code and create a package

The questioner provides the code he used. Let’s clone it first.

cd catkin_ws/src
git clone http://github.com/erenaud3/fakeLaserScan.git

In the /launch/fakeLaserScan.launch file, please leave the node tag and comment out the others since we don’t need them. Then we can compile and run  the package

cd ~/catkin_ws
catkin_make
source devel/setup.bash
roslaunch beginner_tutorial fakeLaserScan.launch

To visualize the laser scan, we’ll use rviz

rosrun rviz rviz

After launching rviz, go to Tools->Graphical Tool. You’ll see the rviz window pops out.

In rviz, click Add->LaserScan to add a visualization. Then we select the topic /fakeScan, however, there is nothing.

It turns out the size of the display is too small. Please change it to a larger value. e.g. 0.1

You should see the visualization now.

Want to learn more?

If you are interested in learning more about ROS, please check our ROS Basic in 5 Days course.

Edit by: Tony Huang

 


We Love Feedback

Did you like this video? Do you have questions about what is explained? Whatever the case, please leave a comment on the comments section below, so we can interact and learn from each other.

If you want to learn about other ROS topics, please let us know in the comments area and we will do a video about it.

How to create a ROS Service Client

How to create a ROS Service Client

Learn how to create a ROS Service Client in less than five minutes, and understand the relationship between a ROS Service Server and a ROS Service Client.

Let’s go!

Step1: Create an account and/or Login to Robot Ignite Academy (RIA)

On RIA, you get access to the best online ROS courses and environment. No need to install and set up ROS locally – the only thing you need is a browser!

  • Create an account and/or login here.
  • Launch the ROS Basics in 5 Days Python course.
  • You’ll now have access to the simulation screen with a Notebook, an Editor, four Shells, and a Simulation Window. We are only using the Editor and Shells for this demo.

Step 2: Create a ROS Service Client and execute it!

ROS Services use a client/server approach. A server provides services, a client calls the server to use the services. In this post, we will create a Python-based client that will call a Python-based server in five easy steps minus one!

(1) I wrote about how to create a ROS service server in another post. We will use the server code here. Please follow steps 1 to 5 of the section named “Step 2: Create a ROS Service Server and call it” in that post to create and run the service server.

(2) Create a sos_service_client.py file on Shell #3:

user:~$ cd catkin_ws/src
user:~/catkin_ws/src$ touch sos_service_client.py && chmod +x sos_service_client.py

(3) Open sos_service_client.py in the Editor and copy-paste the following code into it.

#! /usr/bin/env python

import rospy
from std_srvs.srv import Trigger, TriggerRequest

# init a node as usual
rospy.init_node('sos_service_client')

# wait for this sevice to be running
rospy.wait_for_service('/fake_911')

# Create the connection to the service. Remember it's a Trigger service
sos_service = rospy.ServiceProxy('/fake_911', Trigger)

# Create an object of the type TriggerRequest. We nned a TriggerRequest for a Trigger service
sos = TriggerRequest()

# Now send the request through the connection
result = sos_service(sos)

# Done
print result

(4) Run sos_service_client.py in Shell #3:

user:~/catkin_ws/src$ ./sos_service_client.py
success: True
message: "Hey, roger that; we'll be right there!"

Easy-peasy, right? Let’s consolidate the learning in the next step.

Step 3: Master the Concept: Creating a ROS Service Server

  • A ROS Service Server accepts a request and returns a response. In this case, our server is the Python code.
  • A ROS Service Client makes requests to a ROS Service Server. Our “client” in this case was the Python script!

Please see the inline comments for an explanation of the code.

Done!

Extra: Video

Prefer to see the ‘sights and sounds’ version of this post? We made this video just for you!

Feedback

If you are interested in this topic, please check our ROS Basics in 5 Days course where you’ll learn how to create topic, service, and action in ROS.

Did you like this post? Please leave a comment on the comments section below, so we can interact and learn from each other. Thank you!

How to Create a ROS Service Server

How to Create a ROS Service Server

Hello ROS Developers! In this post (and embedded video), we will see how to create a ROS Service Server (or simply ROS Service) in just five minutes! We’ll see in it action as well as learn some theory behind it.

Let’s go!

Step1: Create an account and/or Login to Robot Ignite Academy (RIA)

On RIA, you get access to the best online ROS courses and environment. No need to install and set up ROS locally; the only thing you need is a browser!

  • Create an account and/or login here.
  • Launch the ROS Basics in 5 Days Python course.
  • You’ll now have access to the simulation screen with a Notebook, an Editor, four Shells, and a Simulation Window. We are only using the Editor and Shells for this demo.

Step 2: Create a ROS Service Server and call it!

ROS Services use a client/server approach. A server provides services, a client calls the server to use the services.

Here, we’ll create a simple service server based on Python and then call it from the command line, all in five easy steps! (In another post, we’ll see how to call the service server from Python code).

(1) On Shell #1, change to the source directory and create an executable python file (since this is a simple demo, we are not creating a ROS package):

user:~$ cd catkin_ws/src
user:~/catkin_ws/src$ touch sos_service.py
user:~/catkin_ws/src$ chmod +x sos_service.py
user:~/catkin_ws/src$

(2) Open sos_service.py in the Editor and copy-paste the following code into it.

#! /usr/bin/env python
import rospy                                      # the main module for ROS-python programs
from std_srvs.srv import Trigger, TriggerResponse # we are creating a 'Trigger service'...
                                                  # ...Other types are available, and you can create
                                                  # custom types
def trigger_response(request):
    ''' 
    Callback function used by the service server to process
    requests from clients. It returns a TriggerResponse
    '''
    return TriggerResponse(
        success=True,
        message="Hey, roger that; we'll be right there!"
    )

rospy.init_node('sos_service')                     # initialize a ROS node
my_service = rospy.Service(                        # create a service, specifying its name,
    '/fake_911', Trigger, trigger_response         # type, and callback
)
rospy.spin()                                       # Keep the program from exiting, until Ctrl + C is pressed

(3) Run the service server in Shell #1:

user:~/catkin_ws/src$ ./sos_service.py # press enter

(4) In Shell #2, see a list of available services, you should find /fake_911:

user:~$ rosservice list
...
/fake_911
...
user:~$

(5) Call your service in Shell #2:

user:~$ rosservice call /fake_911 "{}"
success: True
message: "Hey, roger that; we'll be right there!"

Let’s wrap up with a bit of “small talk” in the next section.

Step 3: Master the Concept: Creating a ROS Service Server

  • A ROS Service Server accepts a request and returns a response. In this case, our server is the Python code.
  • A ROS Service Client makes requests to a ROS Service Server. Our “client” in this case was the shell!

Please see the inline comments for an explanation of the code.

Done!

Extra: Video

Prefer to see the ‘sights and sounds’ version of this post? We made this video just for you!

Feedback

If you are interested in this topic, please check our ROS Basics in 5 Days course where you’ll learn how to create topic, service, and action in ROS.

Did you like this post? Please leave a comment on the comments section below, so we can interact and learn from each other. Thank you!

Pin It on Pinterest