[ROS Projects] – Use OpenAI_ROS with Turtlebot2 Step by Step – PE

[ROS Projects] – Use OpenAI_ROS with Turtlebot2 Step by Step – PE

 

This is an extra short video updating what it has been done new on OpenAI_ROS package. You can find the link to the package wiki down below.
This is important for the people that saw the other two videos, because the structure of the package has changed and it might lead to some confusion and errors.

[irp posts=”10259″ name=”ROS Projects – Use OpenAI_ROS with Turtlebot2 Step by Step #Part 1″]

[irp posts=”10441″ name=”ROS Projects – Use OpenAI_ROS with TurtleBot2 Step-by-Step #Part 2″]

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 rrbot_control. You can easily clone the project with this link.

Step 1. Train Turtlebot 2 with OpenAI ROS

In the ROSject, we already clone the openai ros package for you. You can run the turtlebot 2 simulation from Simulations->Select launch file->main.launch. You should see the simulation is up and running.

Then you can run the training script with

cd catkin_ws
source devel/setup.bash
roslaunch turtle2_openai_ros_example start_training.launch

The robot starts moving and learning how to move in a maze.

Want to learn more?

If you are interested in using the openAI gym in ROS, please check our OpenAI Gym for Robotics 101 course.

Edit by: Tony Huang


 

[ROS Q&A] 149 – How to command joint position of a robot in ROS using Python?

This video extends the excellent tutorial on Gazebo-ROS control by demonstrating a Python script that will send the command to move a robot. The robot is used as an example, and a simple Python code sends joint position command to it through the appropriate topic.

This video is a response to a question posted on Gazebo Answers

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 rrbot_control. You can easily run the RRBOT simulation from Simulations->RRBOT in ROSDS.

Step 1. Load controller

If you launch the simulation successfully, you should see the robot is swinging its arm. As an example, the controller for this robot is already developed. You can launch the controller with the following command.

roslaunch rrbot_control rrbot_control.launch

Now if you type rostopic list , you should see several topic like /rrbot/joint1_position_controller/command in the list. We can publish to these topics to control the robot. For example,

rostopic pub /rrbot/joint1_position_controller/command std_msgs/Float64 "data: 0.5"

You should see the rrbot move its joint to a new position. The value here is in radian. Let’s try to control the robot with code instead of sending command.

Step 2. Create a package

We’ll create a ros package for our code first.

cd ~/catkin_ws/src
catkin_create_pkg rrbot_control rospy
cd rrbot_control
mkdir scripts

Then we create a script called main.py under the scripts folder with the following content.

#!/usr/bin/env python
# license removed for brevity
import rospy
from std_msgs.msg import Float64
import math

def talker():
    pub = rospy.Publisher('/rrbot/joint1_position_controller/command', Float64, queue_size=10)
    rospy.init_node('talker', anonymous=True)
    rate = rospy.Rate(10) # 10hz
    while not rospy.is_shutdown():
        hello_str = "hello world %s" % rospy.get_time()
        position = math.pi/2
        rospy.loginfo(position)
        pub.publish(position)
        rate.sleep()

if __name__ == '__main__':
    try:
        talker()
    except rospy.ROSInterruptException:
        pass

We can use rosrun rrbot_control main.pyto tun our script(remember to give it permission). You should see the robot move to the desired position. You can also try the code with different position function like sin, cos or even publish to more joints if you want.

Want to learn more?

If you are interested in learning ROS, please check our Robot Ignite Academy.

 

Edit by: Tony Huang

RELATED LINKS

Gazebo-ROS control tutorial
Official ROS Publisher / Subscriber tutorial
ROS Development Studio (ROSDS)
Robot Ignite Academy


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] 148 – ROS CPP Time and Duration arithmetics build error

In this video we are going to explain about a problem trying to build a ROS C++ node using ros::Time and ros::Duration.

It is because the order of the terms in sum operation matters. You can check in the video it is simple to solve but it can be a trap if you do not pay attention to that during the development.

Step 1. 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 call the project ros time error.

Step 2. Create a package

Let’s start by creating a ROS package for our code

cd ~/catkin_ws/src
catkin_create_pkg mypkg roscpp geometry_msgs 

Then we call the source file mypkg_node.cpp and put it under the mypkg/src folder with the content from the question.

// This program publishes randomly-generated velocity

// messages for turtlesim.
#include <ros/ros.h>
#include <geometry_msgs/Twist.h>  // For geometry_msgs::Twist
#include <stdlib.h> // For rand() and RAND_MAX

int main(int argc, char **argv) {



  ros::init(argc, argv, "publish_velocity");

  ros::NodeHandle nh; // handles node


  ros::Publisher pub = nh.advertise<geometry_msgs::Twist>(
    "turtle1/cmd_vel", 1000); //links publisher to the node


  while(ros::ok()) {

    geometry_msgs::Twist msg; //Object msgs

    msg.linear.x = 0.5; 
    msg.angular.z = 0;
    msg.linear.z = 0.5;

    // Time tracking
    ros::Time beginTime = ros::Time::now();
    ros::Duration MessageTime = ros::Duration(3);
    ros::Time endTime = MessageTime + beginTime; 

    while(ros::Time::now() < endTime){
        pub.publish(msg);


        ROS_INFO_STREAM("Sending velocity command:"
          << " linear=" << msg.linear.x
          << " angular=" << msg.angular.z
           <<"linearZ="<<msg.linear.z);


        ros::Duration(0.3).sleep();

    }


  }
}

To compile the code, we need to at first uncomment the add_executable and target_link_libraries in the CMakeLists.txt. After that, we can compile it with

cd ~/catkin_ws
catkin_make

However, some error related to ROS time occurs. After checking the documentation ROS C++ Time and Duration, we found out that the order is not quite right. The following part should be changed.

...
    ros::Time endTime = beginTime +  MessageTime; 
...

If we compile again, the problem is solved.

Want to learn more?

If you are interested in using ROS with C++, please check our ROS Basics in 5 days(C++) course for more information.

 

Edit by: Tony Huang

RELATED LINKS

The original question on ROS_Answers
ROS Development Studio (ROSDS)
Robot Ignite Academy
ROS C++ Time and Duration


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] 147 – How to make a Python file executable?

 

One of the most frequent question that we get in our customer support channels is an error when trying to ‘rosrun’ a Python file. The package is there, the file is there, the command has been typed in correctly, but it doesn’t want to run. Sounds familiar?

This is usually due to the file’s permission, which had to be set to be executable. So in this video, we will see how to do this, as well as explore a bit more on this subject. Beginners of ROS and the Linux system should find this very useful.

RELATED LINKS

Original question
ROS Development Studio (ROSDS)
Robot Ignite Academy

Step1. Create a project in Robot Ignite Academy(RIA)

We have the best online ROS course available in RIA. It helps you learn ROS in the easiest way without setting up ROS environment locally. The only thing you need is a browser! Create an account here and start to browse the trial course for free now! We’ll use the ROS Basics in 5 Days course unit 2 as an example today.

Step2. How to make .py file executable

Here we create a package called test_exec using the following command

cd catkin_ws/src
catkin_create_pkg test_exec rospy

We create a file called simple_topic_publisher.py under the src folder and copy the code from the course.

Then we compile the package using

cd ~/catkin_ws
catkin_make

Now we try to run the .py file with rosrun test_exec simple_topic_publisher.py  , but got the same error as the question.

How to solve this problem? We can execute the following command to give the file execute permission

chmod +x simple_topic_publisher.py

You can also check if the file has the permission with

ls -l

Then we run the file again with the rosrun command, the file is able to execute now.

Want to learn more?

If you are interested in learning ROS, please check our Robot Ignite Academy.

 

 

Edit by: Tony Huang

 


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 Projects] Use OpenAI_ROS with  WAM-V Step-by-Step

[ROS Projects] Use OpenAI_ROS with WAM-V Step-by-Step

 

What you will learn?

In this video you will learn how to use openai_ros package to make learn the WAM-V sea robot of the RobotX Challenge to pass the first Navigation Control.  The only thing you need to code is the AI algorithm if you want to use a different one to the one provided Q-Learn.

You can run the ROSject containing all the ROS code and simulation of the robot and sea by clicking on the next button:

Run on ROSDS your ROS project

 

 

And here the different gits used:

And a course on OpenAI in RobotIgniteAcademy: OpenAI Gym for ROS Based Robots 101

Link to RobotX PDF instructions for the challenge:
[https://robotx.org/images/files/RobotX_2018_Task_Summary.pdf]
[https://www.robotx.org/]

[ROS Q&A] 146 – Command line argument passing in rosrun

 

In this video we are going to explore how to pass an argument through command line using rosrun.

It can be a bit confusing, but we are going to explain the difference of the return of the method depending of the type of the value you pass to the argument.

 

Step 1. 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 call the project rosrun_param.

Step 2. Create package

We’ll create a package for our code with the roscpp and std_msgs dependency.

cd ~/catkin_ws/src
catkin_create_pkg my_pkg roscpp std_msgs

Under the my_pkg/src folder, create a my_pkg_node.cpp file with the code from the question.

#include <ros/ros.h>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{  
  std::string param;
  ros::init(argc, argv, "node_name");
  ros::NodeHandle nh("~");
  ROS_INFO("Got parameter : %s", param.c_str());

  if(nh.getParam("blue", param))
  {
    cout << "blue" << endl;
  }
  else if(nh.getParam("green", param))
  {
    cout<< "green" << endl;
  }        
  else
  {
    cout << "Don't run anything !! " << endl;
  }
  return 0;
}

To compile the code, we have to modify the CMakeLists.txt file. Please uncomment the add_executable and target_link_libraries in the build part.

Then we can compile the code with

cd ~/catkin_ws
catkin_make

After compile, we can run the executable with

rosrun my_pkg my_pkg_node

The output is just don’t run anything because we didn’t pass any argument yet.

As an example, we can pass arguments like the following

rosrun my_pkg my_pkg_node _blue:=text

Then the output is blue.

However, the code doesn’t quite make sense. Let’s modify it.

#include <ros/ros.h>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{  
  std::string param;
  ros::init(argc, argv, "node_name");
  ros::NodeHandle nh("~");
  nh.getParam("param", param)
  ROS_INFO("Got parameter : %s", param.c_str());

  if(param.compare("blue")==0)
  {
    cout << "blue" << endl;
  }
  else if(param.compare("green")==0)
  {
    cout<< "green" << endl;
  }        
  else
  {
    cout << "Don't run anything !! " << endl;
  }
  return 0;
}

Now if you pass blue or green as arguments, it will print the color. If you pass something else, it will run nothing.

Want to learn more?

If you are interested in ROS and want to learn more about it, please check our ROS Basics C++ Course.

 

Edit by: Tony Huang

RELATED LINKS

ROS Development Studio (RDS)
Robot Ignite Academy
ROS Basics C++ Course

 


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.

Pin It on Pinterest