Raspberry Pi: Unterschied zwischen den Versionen

Aus HSHL Mechatronik
Zur Navigation springen Zur Suche springen
Keine Bearbeitungszusammenfassung
 
(8 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 13: Zeile 13:
The Raspberry Pi is a single computer the size of a credit card. It features an ARM/Broadcom SoC with a GPU, RAM, and wireless and cable communication options. In some ways, it's that straightforward: the Raspberry Pi is just a small computer. However, it is not so straightforward in another manner. The Raspberry Pi is a very adaptable platform that allows you to build whatever you desire.
The Raspberry Pi is a single computer the size of a credit card. It features an ARM/Broadcom SoC with a GPU, RAM, and wireless and cable communication options. In some ways, it's that straightforward: the Raspberry Pi is just a small computer. However, it is not so straightforward in another manner. The Raspberry Pi is a very adaptable platform that allows you to build whatever you desire.


Initially, we got the AlphaBot with an Arduino attached to it and then we replaced Arduino with a Raspberry Pi 4 and used or programmed it accordingly. In this article, the idea of using Raspberry Pi 4 instead of Arduino IDE with Alphabot  is introduced. Like, how different tools make the Raspberry Pi 4 to control and work with Alphabot. Before we go further, let us take a closer look at the difference between these two boards, Arduino IDE and Raspberry Pi. Then, I will discuss on the installation of required softwares and role of GPIO pins to control the hardware.
Initially, we got the AlphaBot with an Arduino attached to it and then we replaced Arduino with a Raspberry Pi 4 and used or programmed it accordingly. In this article, the idea of using Raspberry Pi 4 instead of Arduino IDE with Alphabot  is introduced. Like, how different tools make the Raspberry Pi 4 to control and work with Alphabot. Before we go further, let us take a closer look at the difference between these two boards, Arduino IDE and Raspberry Pi. Then, the installation of required softwares and role of GPIO pins to control the hardware will be explained.


=== Arduino ===
=== Arduino ===
Zeile 49: Zeile 49:
== Project planning ==
== Project planning ==


[[Datei:Project Plan.jpg|left|mini|700px|Abb 2: Project plan]]
[[Datei:Project Plan.jpg|left|mini|700px|Abb. 4: Project plan]]


<br clear=all>
<br clear=all>
Zeile 55: Zeile 55:
== [[Installation of Ubuntu Server and ROS2]] ==
== [[Installation of Ubuntu Server and ROS2]] ==


== [[Overview of ROS]] ==




== What is ROS? ==


ROS stands for Robot Operating System and it is an open-source platform that makes it easier for researchers and developers to create and reuse code for robotics applications. ROS is also a global open-source community of engineers, developers, and enthusiasts that work to improve, expand, and make robots more accessible to the general public. ROS is not an actual operating system but it is more like an environment. The big strength of ROS is its ability of connecting nodes together.
== [[Using the Raspberry Pi’s GPIO to control hardware components]] ==


== Why should we use ROS for robotics? ==


Due to the following reasons, one can analyze the advantages of using ROS for robotics:
=== Language-agnostic ===
A Python node and a C++ node can readily communicate with each other. It implies a lot of reusability and coworking possibilities. Because ROS is primarily focused on C++ and Python, several modules also allow you to use other languages. We can also install a websocket server (rosbridge suite) or an HTTP server on our robot and communicate with it using any language.
=== Light ===
ROS's core doesn't take up a lot of space or resources. In only a few minutes, we can install the essential packages and get started. Furthermore, ROS may be used on embedded computers like Raspberry Pi 3 boards. As a result, we may immediately begin a new project with minimal effort.
=== Packages for everything ===
Do you need to calculate a robot's trajectory? That is anything for which there is a package. Control the robot using your joystick? There is a package for that as well. Or perhaps you want to use a drone to map out a room? There are numerous software available to accomplish this. If you do a little searching, you'll find a plethora of ROS packages for practically every robotic application.
=== Great simulation tools ===
We require simulation tools since we cannot always get our robot to run in real time. Webots, Rviz, and Gazebo are just a few of the fantastic tools available in ROS. For educational purposes or to test in a specific context, the simulation tools can allow us to observe and utilise other robots that we do not own.
=== Control multiple robots ===
Multiple ROS masters can be used with ROS. It means that we can have a large number of autonomous robots, each with its own ROS system, and they can all communicate with one another.
== Terminologies in ROS ==
Following are the different terms used in ROS that we come to know about them in deep while walking through tutorials.
[[Datei:Nodes-TopicandService.gif|left|mini|600px|Abb.11 Communication between nodes <nowiki></nowiki>]]
<br clear = all>
The above GIF which is taken from [https://docs.ros.org/en/foxy/Tutorials/Understanding-ROS2-Nodes.html here] shows the communication between nodes.
=== Nodes ===
Nodes are software components that can be written in C++ or Python. They are capable of handling a limited number of jobs. For instance, reading a sensor or controlling a servo are two examples. Each node can communicate with other nodes through topics, services, actions, and parameters.
=== Publisher ===
A ROS Node can be either a Subscriber or a Publisher. A Publisher is the person who assigns communications of a certain standard Message Type to a specific Topic.
=== Subscriber ===
The Subscriber, on the other hand, subscribes to the Topic in order to receive messages whenever the Topic is updated.
=== Topics ===
ROS 2 deconstructs complex systems into a series of modular nodes. Topics are an important part of the ROS graph since they serve as a bus for nodes to communicate with one another. A node can publish data to any number of topics and subscribe to any number of topics at the same time. Topics are one of the primary methods for moving data between nodes and, as a result, between different areas of the system.
=== Services ===
Services are another way for nodes in the ROS graph to communicate. Unlike topics, which use a publisher-subscriber paradigm, services use a call-and-response model. While topics allow nodes to subscribe to data streams and receive continuous updates, services only deliver data when a client requests it.
=== Parameters ===
A parameter is a node's configuration value. Parameters are similar to node settings. Integers, floats, booleans, texts, and lists can all be stored as parameters in a node. Each node in ROS 2 has its own set of parameters.
=== Actions ===
Actions are a sort of communication in ROS 2 that is designed for long-running tasks. There are three elements to them: a goal, feedback, and a result. A client-server model, similar to the publisher-subscriber approach, is used for actions. An "action client" node delivers a goal to a "action server," which acknowledges it and responds with a stream of feedback and a result.
=== Package ===
You can think of a package as a container for your ROS 2 code. You'll need to organise your code into a package if you wish to install it or share it with others. You may easily release your ROS 2 work and allow others to build and utilise it with packages. In ROS 2, package creation is done with the ament build system and colcon as the build tool. Although additional build types exist, you can construct a package using either CMake or Python, which are officially supported.
== Using the Raspberry Pi’s GPIO to control hardware components ==
The Raspberry Pi's row of GPIO pins along the top edge of the board is a powerful feature. General-Purpose Input/Output is an acronym for GPIO. These pins are the Raspberry Pi's physical interface to the outside world. You can think of them as switches that you can turn on or off (input) or that the Pi can turn on or off (output) at the most basic level (output). The Raspberry Pi's GPIO pins link to electronic circuits and allow it to control and monitor the outside world. The Raspberry Pi can control LEDs, switch them on and off, and run motors, among other things. It can also tell if a switch has been pressed, the temperature, and the amount of light. This is referred to as physical computing.
[[Datei:GPIO Pins.png|right|mini|200px|Abb. 12: GPIO Pin Label.
This image is taken from [https://raspi.tv/2013/rpi-gpio-basics-4-setting-up-rpi-gpio-numbering-systems-and-inputs here] ]]
The Raspberry Pi has 40 pins (26 pins on early variants), each of which serves a different purpose. If you have a RPi pin label, you can use it to assist you figure out what each pin is for. Make that the keyring hole on your pin label is facing outwards, away from the USB ports.
1. GND: Zero volts is a voltage that is used to complete a circuit.
2. GP2: These pins can be used for a variety of purposes and can be set up as input or output pins.
3. 5V: Anything that is attached to these pins will always receive 5 volts of power.
4. 3V3: Anything attached to these pins will receive 3.3V power at all times.
5. ID_SC/ID_SD/DNC: pins with a specific purpose.
<br clear=all>
TIP: Playing with the GPIO pins is safe and enjoyable if you follow the instructions. Randomly putting wires and power sources into a Pi, on the other hand, may cause it to fail, especially if the 5V pins are used. If you try to connect devices to a Pi that use a lot of power, bad things can happen.
An ultrasonic distance sensor emits ultrasound pulses that are undetectable by humans and detects the echo that is returned when the sound bounces off a nearby object. The distance from that thing is then calculated using the speed of sound.
Two GPIO pins (one for echo, one for trigger), the ground pin, and a 5V pin are connected to the circuit. You must know which GPIO pins the echo and trigger are attached to in order to use the ultrasonic distance sensor in Python. First, we initialize the GPIO pins in our program.
Here,
* the echo is connected to pin '5'
* the trigger is connected to pin '17'
* the servo to pin '27'.
[[Datei:GPIO 1.png|left|mini|300px|Abb. 13 Program  ]]
<br clear=all>
GPIO.setmode(GPIO.BCM) = set up GPIO Broadcom chip-specific pin numbering
self.p = GPIO.PWM(servo, 50) = When RPi configured for software pulse-width modulation, each pin generates a square waveform with a configurable duty cycle and frequency
self.PWMA.start ( ) = hints left wheel speed
self.PWMB.start ( ) = hints right wheel speed
[[Datei:GPIO 2.png|left|mini|400px|Abb. 14 GPIO part in code  ]]
<br clear=all>


== Illustration of the robot with UML diagram ==
== Illustration of the robot with UML diagram ==
Zeile 191: Zeile 71:
== [[Zusammenfassung_Praxissemester_Murad|Summary]] ==
== [[Zusammenfassung_Praxissemester_Murad|Summary]] ==


This whole article conveys the information related to one specific part of this project. From the name "Raspberry Pi and ROS2", we can get an insight of what can be included in this section. In this article, I discussed on difference between Raspberry Pi and Arduino, Ubuntu as an operating system on our microprocessor, how we can begin with ROS2, why we need it, how it helps us and using Raspberry Pi GPIO pins to control the hardware.
It is shown how Ubuntu Server can be installed on a Raspberry Pi 4, connected to the internet, and used remotely in this article. There are two ways to set up Pi: with an external HDMI screen and USB keyboard, or without. We utilized the first one, which came with an additional HDMI screen and a USB keyboard. After the installation of Ubuntu server, ROS2 is installed with the help of Debian packages on Raspberry Pi, so that it can be programmed with the integration of ROS2. Why do we need ROS? those reasons and its importance is also discussed here. The Raspberry Pi's GPIO pins link to electronic circuits and allow it to control and monitor the outside world. The role of GPIO pins to control the motors and sensor of the AlphaBot is mentioned with the help of code too.
=== Self-reflection ===
Since, the above mentioned things are not the only ones what I participated in doing. We worked as a team on this project and achieved the overall result together. Along with above mentioned sections, I was also able to work and sharpen my skill of programming in Python and C++ language by programming Raspberry Pi 4 using ROS2 and the simulation on Webots .
First, each of us was obliged to practise the tutorials of ROS2 and Webots in order to have a good command on these two tools. After walking through the tutorials, I was able to build a similar robot like Alphabot on Webots that I integrated with ROS2 later. We can also control the robot using Keyboard along with allowing it to drive autonomously on Webots. Then, I started programming Raspberry Pi 4 with the integration of ROS2 in order to make our AlphaBot to be able to detect obstacles and drive autonomously.
In short, I got a good grip on following tools by working on this project:
* Ubuntu, family member of Linux OS
* Credit-card sized computer:  Raspberry Pi 4
* Robot Operating System
* Programming in object-oriented language, Python and C++
=== Outlook ===
Every day, technology evolves and expands. It's also affecting how individuals conduct their jobs. Robotics is one of the technologies that is transforming the global industrial landscape. Patience, the courage to work through mistakes, and problem-solving skills are all required to thrive in robotics. And I was privileged to work under the supervision of the professors in order to get into this world, explore my abilities, realize my mistakes and improve them. Internship is the point where we get a chance to implement all of our skills that we learnt previously in a real and professional world.
So far, this what has been done on this project. In future, the main program can be modified for more accuracy, so that the robot can detect the obstacle from a specified distance and move in a direction where there is no nearby object. The feature of mapping can also be added that is more useful for the main purpose of this project.
Around the world, robotics is forging new ground in learning approaches. It is imperative that we prepare ourselves for the changes that will occur in the future in all facets of our lives, whether personal, educational, or professional. And I am looking very forward to playing my part in it in near future.


== Softwares ==
== Softwares ==

Aktuelle Version vom 20. März 2022, 00:31 Uhr

Autoren: Fawad Murad
Betreuer: Prof. Schneider
Art: Praxissemester
Projektlaufzeit: 02.11.2021 - 20.02.2022

Abb.1 AlphaBot with Raspberry Pi 4


Introduction

The Raspberry Pi is a single computer the size of a credit card. It features an ARM/Broadcom SoC with a GPU, RAM, and wireless and cable communication options. In some ways, it's that straightforward: the Raspberry Pi is just a small computer. However, it is not so straightforward in another manner. The Raspberry Pi is a very adaptable platform that allows you to build whatever you desire.

Initially, we got the AlphaBot with an Arduino attached to it and then we replaced Arduino with a Raspberry Pi 4 and used or programmed it accordingly. In this article, the idea of using Raspberry Pi 4 instead of Arduino IDE with Alphabot is introduced. Like, how different tools make the Raspberry Pi 4 to control and work with Alphabot. Before we go further, let us take a closer look at the difference between these two boards, Arduino IDE and Raspberry Pi. Then, the installation of required softwares and role of GPIO pins to control the hardware will be explained.

Arduino

Abb.2 Arduino Uno Plus


Arduino is a development board that uses a microcontroller. Arduino UNO uses the ATmega328P microcontroller, which is based on Atmel microcontrollers. The Processor, RAM, and ROM are all contained in the Microcontroller on the Arduino Board (such as the ATmega328P). Supporting hardware (for power and data) and GPIO pins are included on the board. Arduino was built from the ground up as open-source hardware and software. The hardware and software of Arduino are both easily accessible. There is no need for an operating system because it is a Microcontroller. To connect to the internet using Arduino, you'll need an extra module or shield. In the case of Arduino, there is no wireless connectivity (at least on board). C or C++ programming languages can be used to programme Arduino.


Raspberry Pi

Abb.3 Raspberry Pi 4


The Raspberry Pi is an SBC (Single Board Computer). It's built around a Broadcom SoC, which is an ARM Cortex A Series microprocessor. The Raspberry Pi Board contains all of the necessary components, such as the processor, RAM, storage, connectors, and GPIO pins. Raspberry Pi's hardware and firmware are both closed-source, which means they are not available for general usage. To boot the Raspberry Pi, you'll need a Debian-based Linux distribution called Raspberry Pi OS. Using Wi-Fi or Ethernet, you may effortlessly connect to the internet. The Raspberry Pi includes Bluetooth and Wi-Fi technology. Python, Scratch, Ruby, C, and C++ are the most popular programming languages for Raspberry Pi application development.


Software requirement

  • Ubuntu 20.04.3 LTS (RPi 3/4/400)
  • Robot Operating System 2 (Foxy Fitzroy)

Hardware requirement

  • Robot (AlphaBot)
  • Raspberry Pi 4
  • HDMI cable (for connecting RPi with Monitor)
  • Network cable
  • Network switch

Project planning

Abb. 4: Project plan


Installation of Ubuntu Server and ROS2

Overview of ROS

Using the Raspberry Pi’s GPIO to control hardware components

Illustration of the robot with UML diagram

Abb. 15 Use Case Diagram


Summary

Softwares

  • Ubuntu 20.04.3 LTS (RPi 3/4/400). To install Ubuntu Server 20.04.3 LTS on a Raspberry Pi, please use this guide.
  • Robot Operating System 2 (Foxy Fitzroy). To install ROS 2 Foxy on a Raspberry Pi, please use these instructions.

Demo

The code can be run straight from the SVN repository: https://svn.hshl.de/svn/Robotik_und_Autonome-Systeme/trunk/Projekte/AlphaBot_PI_ROS2/ .

In order to know how the code can be executed from SVN directory, please go through these instructions .

Weiterführende Links