Categories

Robot Controller

In this document, we will guide you on How to Install Ubuntu MATE 16.04.2 LTS and ROS Kinetic on Raspberry Pi.

 

 

Step1: Download the image for Ubuntu MATE

Official Download Link for Ubuntu MATE for Raspberry Pi
https://ubuntu-mate.org/download/
It comes packaged as an XZ archive so use 7 Zip to extract the IMG file.

 

Step2: Download and Install Win32 Disk Imager

https://sourceforge.net/projects/win32diskimager/
Installing an OS onto a Raspberry Pi requires you to use another computer to write the image file onto a micro SD card. You must have a way to mount a micro SD card onto the computer using either an inbuilt or external USB reader.

  • Insert your micro SD card and launch Win32 Disk Imager.
  • Select your extracted Ubuntu Mate IMG file and change the Device to the drive letter of your micro SD Card.
  • Click Write to begin the process.

  • It will take about 10 minutes to write the image

 

Step 3: Eject the device safely in Windows, insert it into the Raspberry Pi 3 and power it on.
  • Connect Raspberry Pi to Monitor or TV using HDMI cable.
  • Select English as the Language and click Continue.

  • Select “I don’t want to connect to a wi-fi network right now” and click Continue.

  • Select an appropriate location on the map to set the timezone and system locale and click Continue

  • Select an appropriate keyboard layout and click Continue.

  • Enter an appropriate Name, Username and Computer name and then a password. Select “Log in automatically” and click Continue.

  • The installer will now proceed to configure the system.

  • When configuration is complete you will see the splash screen below.

  • Go to the System Menu in the top left corner and select Preferences – Internet and Network – Network Connections.

  • Select “Wired connection 1” under Ethernet and click the Edit button. Click on the “IPv4 Settings” tab at the top.

  • Click on the Method drop-down list and select Manual.

  • Enter an appropriate IP Address, a Netmask in CIDR notation and the Gateway address. Enter your networks DNS server address. Click Save. Click Close to finish.

 


 

How to install ROS Kinetic on Raspberry Pi 3 (Ubuntu Mate)

 

The ROS framework is compatible with a short list of Linux distributions. Neither the hardware side is not better. There are just few hardware architectures compatible with ROS. Raspberry Pi is one of the development boards compatible in terms of hardware with ROS.

So, I thought to install ROS Kinetic on the Raspberry Pi 3 running Ubuntu Mate. But only a certain version of Ubuntu Mate is compatible with ROS and Raspberry Pi 3, it is about the Ubuntu MATE for Raspberry Pi 3. This is an OS version released last year and include support for the WiFi and Bluetooth modules integrated into the Pi 3.

The OS version used by me on Raspberry Pi 3 is Ubuntu MATE 16.04.2.

The ROS version that I have installed is Kinetic Kame. Kinetic was released early last year and is compatible with Ubuntu Mate 16.04. I chose this version for two reasons:

  1. it will be officially supported for the next five years;
  2. it is the most complete version after Indigo;

The first step in installing ROS on Raspberry Pi 3 is called Mate. Ubuntu Mate. The operating system is simple to install. I followed the steps on the download page, and within minutes I managed to have a Pi 3 running Ubuntu Mate.

What you find below are the steps to install ROS Kinetic on the Raspberry Pi 3.

 

Step1 : Go to System -> Administration -> Software & Updates

 

Step2 : Check the checkboxes to repositories to allow “restricted,” “universe,” and “multiverse.”

Software and Updates

 

 

Step3 : Setup your sources. List
sudo sh -c ‘echo “deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main” > /etc/apt/sources.list.d/ros-latest.list’

 

Step4 : Setup your keys
wget http://packages.ros.org/ros.key -O – | sudo apt-key add –

 

Step5 : To be sure that your Ubuntu Mate package index is up to date, type the following command
sudo apt-get update

 

Step6 : Install ros-kinetic-desktop-full
sudo apt-get install ros-kinetic-desktop-full

 

Step7 : Initialize rosdep
sudo rosdep init
rosdep update

 

Step8 : Setting up the ROS environment variables
echo “source /opt/ros/kinetic/setup.bash” >> ~/.bashrc
source ~/.bashrc

 

Step9 : Create and initialize the catkin workspace

mkdir -p ~/catkin_workspace/srccd catkin_workspace/src

catkin_init_workspace

cd ~/catkin_workspace/

catkin_make

 

Step10 : Add the catkin_workspace to your ROS environment

source ~/catkin_workspace/devel/setup.bash

echo “source ~/catkin_workspace/devel/setup.bash” >> ~/.bashrc

 

Step11 : Check the ROS environment variables
export | grep ROS

 

The setup looks like in the picture 

Check the ROS installation
  1. Open a new terminal and type: roscore
  2. Open a new terminal and type: rosrun turtlesim turtlesim_node

 


Testing Rplidar

 

  • ### Create a ROS Workspace

mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/src
catkin_init_workspace

  • ### Clone the ROS node for the Lidar in the catkin workspace src dir

git clone https://github.com/robopeak/rplidar_ros.git

  • ### Build with catkin

cd ~/catkin_ws/catkin_make

  • ### Set environment when the build is complete

source devel/setup.bash

  • ### Launch demo with rviz

Check the authority of rplidar’s serial-port :

ls -l /dev |grep ttyUSB

Add the authority of write: (such as /dev/ttyUSB0)

sudo chmod 666 /dev/ttyUSB0

Start a rplidar node and view the scan result in rviz.

$ roslaunch rplidar_ros view_rplidar.launch    #for rplidar A1/A2

Start a rplidar node and run rplidar client process to print the raw scan result

 

Result

 

Rviz will pop-up and show a background grid. The “view” from the laser scanner will be marked in red. The laser scanner is positioned at the center of the grid, it has a range of roughly 15cm to 6 meters, so you’ll be able to see everything around it on its scanning plane within that range.

1.0 Introduction

A typical rotary incremental encoder consists of a light-emitting diode (LED), a disk, and a light detector on the opposite side of the disk (see next figure). The disk, which is mounted on the rotating shaft, has patterns of opaque and transparent sectors coded into the disk. As the disk rotates, the opaque segments block the light and, where the glass is clear, light is allowed to pass. This generates square-wave pulses, which can then be interpreted into position or motion. These pulses can be read by microcontroller as part of a PID feedback control system to determine translation to distance, rotational velocity, and/or angle of a moving robot or robot part. For instance, if you have a wheel rotating, and you want to measure the time it takes to rotate exactly 40 degrees, or if you want to know when you have traveled X distance, you can use an rotary encoder. The encoder will be fixed on your robot, and the mechanical part (the encoder wheel) will rotate with the wheel. Since the output of an encoder is a square wave, you can then count the pulses if you hook up this signal to a digital counter or microcontroller. Knowing the distance/angle between each pulse, and the time from start to finish, you can easily determine position or angle or velocity or whatever. Encoders are necessary for making robot arms, and very useful for acceleration control of heavier robots. They are also commonly used in robot for maze navigation.

clip_image004

Rotary Incremental Encoder Basic working model

Rotary Encoders usually offer 100 to 6,000 segments per revolution. This means the encoder can provide 3.6 deg of resolution for 100 segments and 0.06 deg of resolution for 6,000 segments. Linear encoders work under the same principle as rotary encoders except that instead of a rotating disk, there is a stationary opaque strip with transparent slits along its surface, and the LED-detector assembly is attached to the moving body.

2.0 Quadrature Encoder

An encoder with one set of pulses is sometime not sufficient because it cannot indicate the direction of rotation. Using two code tracks with sectors positioned 90 degree out of phase (see next figure); the two output channels of the quadrature encoder indicate both position and direction of rotation. For example, if A leads B, the disk is rotating in a clockwise direction. If B leads A, the disk is rotating in a counter-clockwise direction. Therefore, by monitoring both the number of pulses and the relative phase of signals A and B, the microcontroller can track both the position and direction of rotation. In addition, some quadrature encoders include a third output channel – called a zero or reference signal – which supplies a single pulse per revolution. This single pulse can be used for precise determination of a reference position. This signal is called the Z-Terminal or the index in most of encoder. A typical, ideal quadrature signal looks like this:

clip_image006

Quadrature Encoder Output

With incremental encoders, you can measure only changes in position (from which you can determine velocity and acceleration), but it is not possible to determine the absolute position of an object. Another type of encoder, called an absolute encoder, is capable of determining the absolute position of an object. Its function is similar to position feedback using variable resistor (analog output), the only differences are that it can be rotated in 360 degree and digital output. This type of encoder has alternating opaque and transparent segments like the incremental encoder, but the absolute encoder uses multiple groups of segments that form concentric circles on the encoder wheel like a bull’s-eye on a target or dartboard. The concentric circles start in the middle of the encoder wheel and, as the rings go out toward the outside of the ring, each of them has doubled the number of segments than the previous inner ring.

To make encoder measurements, you need a basic electronic component called a counter. Based on its several inputs, a basic counter emits a value that represents the number of edges (low to high or high to low transitions in the waveform) counted. Most of the Microchip PICs have this peripheral; normally Timer 0 or Timer 1 is used as external input counter. External interrupt pins (INT) can also be used for counting the pulse; the rising edge (low to high) or falling edge (high to low) is configurable. Once the edges are counted, the next thing you need to take care is how those values are converted to position, further to speed and etc. The process by which edge counts are converted to position depends on the type of encoding used. There are three basic types of encoding, X1, X2, and X4.

2.1 1X Encoding

You will be able to see the signals shown in the next figure if we are scanning from left to right ; and reverse the direction or scan from right to left on previous figure. This is a quadrature cycle and the resulting increments and decrements for X1 encoding. When channel A leads channel B, the increment occurs on the rising edge of channel A. When channel B leads channel A, the decrement occurs on the falling edge of channel A.

clip_image008

1X Encoding

2.2 2X Encoding

A shortcoming of the previous method is that the count frequency is the same as the frequency of channel A. Thus, an encoder is said to have a resolution of 500 pulses per revolution (ppr) does exactly that. We can do better by using both edges of Channel A. This is not too hard to arrange in hardware but this uses up valuable board space. The equality test described just now works just as well if we are detecting falling edges. Thus we can use the same routine for both rising and falling edges and detect twice as many transitions. With 2X decoding our 500 ppr encoder can generate 1000 pulses per revolution.

clip_image010

2X Encoding

2.3 4X Encoding

It is possible to do even better if we examine the edges of both channel A and channel B. There are four edges for each phase of channel A and it is possible to get 2000 pulses per revolution from our 500 ppr encoder.

clip_image012

4X Encoding

When I cut out the middle part of this signals which shown in the next figure, we can see clearly that the two bit encoder field (A, B) is Gray Code Encoded. Only one of the two bits changes for any given state transition.

clip_image014

4X Encoding State Transition

Furthermore, we can tell whether the wheel is turning clockwise or counter-clockwise based on the state transitions, which are mutually exclusive for the two directions, as shown in the table below.

clip_image016

4X Encoding State Transition Table

Most engineers will be more comfortable with the table above representing a state transition diagram, as shown in figure below.

clip_image018

4X Encoding State Transition Diagram

If you have a microcontroller with the ability to generate interrupt form external source, it is pretty simple to get the count we want. But at least it must has two external interrupt pins for 4X encoding, let’s say we use PIC18F4520 (3 external interrupt pins). Channel A is connected to the INT1/RB1 pin and channel B is connected to the INT0/RB0 pin. The sense of the interrupt is changed after each interrupt so that the routine responds alternately to rising and falling edges. On each interrupt, after determining the current state, we can get the direction by checking back the previous state and Count Value will be increased or decreased. Listing below is the example interrupt routine for PIC18F4520 and the sequence is based on the previous state transition diagram.

clip_image020

4X Encoding Interrupt Routine Listing

Angle of rotation (degree) = (CountValue/XN) x 360 where N = number of pulses generated by the encoder per shaft revolution, X is the encoding type. Let’s say Rotary Encoder B-106-23983 (available from robu.in) is used, N=500ppr and we use 4X encoding, so our angle of rotation (degree) = CountValue x 0.18. This encoder outputs capable to produce up to 100 kHz pulse, it is good enough for a normal mobile robot. Your microcontroller speed might limit the maximum angular speed of your encoder due to the time for serving interrupt routine. Some of the 8-bit Microchip PIC has Quadrature Encoder Interface (QEI) feature with noise filters like PIC18F2331, PIC18F2431, PIC18F4331 and PIC18F4431. With this model of microcontroller, configure some of the related registers is sufficient; position and velocity of your encoder can be obtained directly without serving the interrupt routine. Hope this article helps in using rotary encoder. If you have any feedback, please discuss in our technical forum: https://robu.in/forums/

* If you like to have faster response from author regarding your inquiry/comments/feedback, please do post in our technical forum as we seldom check the comment section in tutorial site.

References:

http://www.ni.com/

http://www.microchip.com/

http://www.eehomepage.com/