Learning ROS notes from theconstructsim.com

Learning ROS notes from theconstructsim.com

Ros tutorial
https://app.theconstructsim.com/#/Desktop

Topics:
communication to compnents of

services and actions

tutorial 1


# basic demoroslaunch publisher_example move.launch
roslaunch publisher_example stop.launch

# services
roslaunch service_demo service_launch.launch
rosservice call /service_demo "{}"

the subscribers run last message that it recieved

services

Defintion:

basic demoroslaunch publisher_example move.launch

roslaunch publisher_example stop.launch

services

requices the node to finish its process

actions

live feedback retuine

roslaunch service_demo service_launch.launch
rosservice call /service_demo "{}"
roslaunch action_demo action_launch.launch
roslaunch action_demo_client client_launch.launch
rosrun rviz rviz
cd ~/catkin_ws/src
catkin_create_pkg my_examples_pkg rospy std_msgs
cd ~/catkin_ws
catkin_make
source devel/setup.bash
rospack profile
roscd my_examples_pkg
mkdir scripts


roscd my_examples_pkg/scripts
touch NAME_OF_EXAMPLE_SCRIPT.py
chmod +x NAME_OF_EXAMPLE_SCRIPT.py

roscd my_examples_pkg/scripts
python NAME_OF_EXAMPLE_SCRIPT.py
# OR
rosrun my_examples_pkg NAME_OF_EXAMPLE_SCRIPT.py

roscd my_examples_pkg/scripts
touch simple_topic_publisher.py
chmod +x simple_topic_publisher.py

file simple_topic_publisher.py

#! /usr/bin/env python

import rospy
from std_msgs.msg import Int32 

rospy.init_node('topic_publisher')
pub = rospy.Publisher('/counter', Int32, queue_size=1)
rate = rospy.Rate(2)
count = Int32()
count.data = 0

while not rospy.is_shutdown(): 
  pub.publish(count)
  count.data += 1
  rate.sleep()

run shell 1

rosrun my_examples_pkg simple_topic_publisher.py

run shell 2

rostopic list | grep  '/counter'

how to see data publishing on ros

rostopic info /counter

result

user:~$ rostopic info /counter
Type: std_msgs/Int32

Publishers:
 * /topic_publisher (http://5_xterm:42533/)

Subscribers: None

how view the data

rostopic echo /counter

data: 546
---
data: 547
---
data: 548
---

what's a topic?

A topic is a channel that acts as a pipe, where other ROS nodes can either publish or read information

list ros topics

rostopic list

rostopic echo <topic_name>
rostopic echo <topic_name> -n1
rostopic echo /counter
rostopic echo /counter -n1


rostopic info /counter
rostopic -h
20210219

Messages

rosmsg show <message>
rosmsg show std_msgs/Int32

resulst

user:~/catkin_ws/src/my_examples_pkg$ rosmsg show std_msgs/Int32
int32 data

'data' is a variable defined in simple_topic_publisher.py

count = Int32()
count.data = 0

looking at Int32.msg

roscd std_msgs/msg/

rostopic info /cmd_vel 
rosmsg show

solving the challenge

cd ~/catkin_ws/src/
catkin_create_pkg exercise_31 rospy std_msgs geometry_msgs
cd ~/catkin_ws
catkin_make
source devel/setup.bash
rospack profile
roscd exercise_31
mkdir scripts
touch ./scripts/move_robot.py
#! /usr/bin/env python

import rospy
from geometry_msgs.msg import Twist

rospy.init_node('move_robot_node')
pub = rospy.Publisher('/cmd_vel', Twist, queue_size=1)
rate = rospy.Rate(2)
move = Twist()
move.linear.x = 0.5 #Move the robot with a linear velocity in the x axis
move.angular.z = 0.5 #Move the with an angular velocity in the z axis

while not rospy.is_shutdown(): 
  pub.publish(move)
  rate.sleep()

link how ros launch files work roslaunch - ROS Wiki

roscd exersize_31
# created a file called /catkin_ws/src/exersize_31/launch/move_robot.launch
touch ./launch/move_robot.launch
chmod +x ./launch/move_robot.launch

add text

<launch>
    <node pkg="exercise_31" type="move_robot.py" name="move_robot_node" output="screen" />
</launch>
chmod +x ./scripts/move_robot.py
roslaunch exercise_31 move_robot.py

roslaunch exercise_31 move_robot.launch

Subscribers

reads data from a publisher (similar to a client)


cd ~/catkin_ws/src
catkin_create_pkg my_examples_pkg rospy std_msgs
cd ~/catkin_ws
catkin_make
source devel/setup.bash
rospack profile
roscd my_examples_pkg
mkdir scripts

roscd my_examples_pkg/scripts
touch NAME_OF_EXAMPLE_SCRIPT.py
chmod +x NAME_OF_EXAMPLE_SCRIPT.py

roscd my_examples_pkg/scripts
python NAME_OF_EXAMPLE_SCRIPT.py
# OR
rosrun my_examples_pkg NAME_OF_EXAMPLE_SCRIPT.py


roscd my_examples_pkg/scripts
touch simple_topic_subscriber.py
chmod +x simple_topic_subscriber.py

simple_topic_subscriber.py


#! /usr/bin/env python

import rospy
from std_msgs.msg import Int32 

def callback(msg): 
  print (msg.data)

rospy.init_node('topic_subscriber')
sub = rospy.Subscriber('/counter', Int32, callback)
rospy.spin()

rosrun my_examples_pkg simple_topic_subscriber.py
rostopic echo /counter

OUTPUT:
----------
user ~ $ rostopic echo /counter
WARNING: no messages received and simulated time is active.
Is /clock being published?
---------

how to publish test data to topic

rostopic pub <topic_name> <message_type> <value>
rostopic pub /counter std_msgs/Int32 5

OUTPUT
----
user ~ $ rostopic echo /counter
WARNING: no messages received and simulated time is active.
Is /clock being published?
data:
5
---
----

#! /usr/bin/env python

import rospy                                          
from std_msgs.msg import Int32 

def callback(msg):   # Define a function called 'callback' that receives a parameter 
                     # named 'msg'
    print (msg.data) # Print the value 'data' inside the 'msg' parameter
rospy.init_node('topic_subscriber')  # Initiate a Node called 'topic_subscriber'

# Create a Subscriber object that will listen to the /counter
# topic and will cal the 'callback' function each time it reads

sub = rospy.Subscriber('/counter', Int32, callback)

# something from the topic
rospy.spin()   

Challenge 2


rostopic info /odom
OUTPUT:
--------------------------
Type: nav_msgs/Odometry

Publishers:
 * /gazebo (http://15_simulation:35255/)

Subscribers: None
--------------------------

find more about nav_msgs/Odometry

roscd nav_msgs


Debugging tools

Questions:

  • what does "{}" mean
  • what does it mean to 'call' a sevice
  • what does http://5_xterm:37773/ mean
  • what is a ros master?
    • how is it used?
  • what are paramaters?
  • what is queue_size=1
  • how does the datatypes work in ros
  • what does rospy.spin() do?

Sucess!

Results!

#! /usr/bin/env python

import rospy
from std_msgs.msg import Int32 
from nav_msgs.msg import Odometry
def callback(msg): 
  print (msg.header)
  print (msg.child_frame_id)
  print (msg.pose)
  print (msg.twist)

rospy.init_node('topic_subscriber')
sub = rospy.Subscriber('/odom', Odometry, callback)
rospy.spin()

roscd <package_name>
mkdir msg

The "Age.msg" file must contain this:


float32 years
float32 months
float32 days


how to install ros serial to communicate with arduino

rosserial_arduino/Tutorials/Arduino IDE Setup - ROS Wiki

sudo apt-get install ros-noetic-rosserial-arduino
sudo apt-get install ros-noetic-rosserial
cd ~/catkin_ws/src
git clone https://github.com/ros-drivers/rosserial.git
cd ~/catkin_ws
catkin_make
catkin_make install

Errors with install

Trying catkin_make_isolated

that didnt work...

this issue was someone's elses package was installed that was broaken

Fix: move the problem package out and run 'catkin_make`

Sucess!

install arduino ide

Program an Arduino UNO with your Raspberry Pi — The MagPi magazine

sudo apt-get update && sudo apt-get upgrade
sudo apt-get install arduino
Skechbook folder location
cd ~/sketchbook/libraries
rm -rf ros_lib
rosrun rosserial_arduino make_libraries.py .

Windows note:

If you are building the Arduino on Windows, you need to create the ros_lib folder in some convenient directory.

cd <some_empty_directory>
rosrun rosserial_arduino make_libraries.py .

Issue i ran into

links

usb_cam - ROS Wiki

fatal error: serial/serial.h: no such file or directory in ros - ROS Answers: Open Source Q&A Forum

robotarmhackathon/launch at main · agillies8/robotarmhackathon

agillies8/robotarmhackathon: Code for the robot arm hackathon

ros-drivers/rosserial: A ROS client library for small, embedded devices, such as Arduino. See: http://wiki.ros.org/rosserial

rosserial_arduino - ROS Wiki

3AxisArm/Single_BUTTON_TEST.ino at master · agillies8/3AxisArm

exaplse simple

3AxisArm/buttonPlex.py at master · agillies8/3AxisArm

3AxisArm/TWO_BUTTON_TEST.ino at master · agillies8/3AxisArm

simple keyboard input

teleop_twist_keyboard - ROS Wiki

If you want to help me out and give some donations here's my monero address: 432ZNGoNLjTXZHz7UCJ8HLQQsRGDHXRRVLJi5yoqu719Mp31x4EQWKaQ9DCQ5p2FvjQ8mJSQHbD9WVmFNhctJsjkLVHpDEZ I use a tracker that is pravicy focused so if you block its cool, im big on blocking stuff on my own machine. im doing it to see if anyone is actualy reading my blog posts...:)