How to use MATLAB to develop robots

Robots are definitely one of the current hot topics. From industrial robots to sweeping robots, from laboratory robots to various innovative toy robots, robots have gradually entered the public's field of vision and entered the lives of ordinary people. Whether it is a technology enthusiast or an ordinary consumer, more and more eyes are on the robot. With the rise of online crowdfunding, the economic threshold of technology entrepreneurship has been reduced, and one star celebrity crowd-raising project has also stimulated more and more technology enthusiasts to focus on the development of robots. Everyone is looking forward to the innovative prototypes they have developed, which can be called the focus of the next investor or the public.

The ancients said, "If you want to do something good, you must first sharpen it." Now let's take a look at how to use MATLAB as a "tool" to help us quickly realize our creativity.

MATLAB platform

MATLAB is the world's leading data analysis and processing software. This red quadric LOGO appears in almost every university textbook.

How to use MATLAB to develop robots

Figure 1 MATLAB LOGO

But in fact, it is no longer just the “super calculator” that we only know about data processing and drawing in our student days. It is far more extensive and in-depth in the industry than in education. From the toolbox structure in the figure below, you can get a glimpse of it. You can see the dark blue module on the right, which also develops a series of toolboxes for each specific application area.

How to use MATLAB to develop robots

Figure 2 MATLAB Toolbox

The MATLAB/Simulink algorithm development platform is also an indispensable tool for control algorithm design in the automotive, military and other industries. Based on Simulink model modeling, simulation, test verification and code generation, this model-based design concept (MBD) is also replacing the traditional handwritten C code development process, becoming the mainstream and future trend of algorithm development.

How to use MATLAB to develop robots

Figure 3 Model-based design

So what does this mean for developing robots? This means that you can not only get rid of complicated C code programming, but also use MATLAB's powerful toolbox series to help you test algorithms, optimize parameters, and more. If the user purchases the code generation toolbox, he can also extract the generated embedded C/C++ algorithm functions and integrate them into his own external engineering project, as shown in the left arrow of Figure 4. This is also the mainstream choice for commercial product development.

Electronic enthusiasts "Robot Technology Special Issue", more quality content, download now

Special issue of robotics

MATLAB/Simulink Support Package

I mainly want to introduce the free hardware support package here: MATLAB/Simulink Support Package. It is equivalent to a bridge between MATLAB and a variety of low-cost hardware.

Download and install the official free MATLAB/Simulink Support package. After simply setting the corresponding board, the Simulink block diagram or MATLAB script can be compiled and downloaded to the hardware with one click, as shown in the right arrow below. This is very useful for quickly implementing early ideas, especially for small development teams, where more attention can be paid to algorithm design and development than to basic C code implementation.

How to use MATLAB to develop robots

Figure 4 from model to implementation

The MATLAB/Simulink Support Package provides a basic driver module for a series of supported boards. Simply perform a simple configuration on the software interface, and you can download the block diagram-based algorithm model to the hardware board with one click. Help us quickly realize early ideas and shorten the prototype development cycle.

Through it, we can easily communicate with these hardware, read data into the MATLAB environment for analysis and processing, and easily download Simulink's block diagram algorithm to implement a variety of creative applications.

How to use MATLAB to develop robots

Figure 5 MATLAB\Simulink Support Package

Case introduction

Below, we use the Arduino MEGA 2560 to demonstrate how to implement a one-click download of the model to the hardware. This is a very simple example: using a photoresistor to control the brightness of the LED light.

Hardware connection

To put it simply, a photo resistor and a fixed resistor are used in series to form a voltage dividing circuit, and the divided voltage is read into the Arduino, and then the value is used to output the brightness of the LED. Read the voltage divider value into the Ar1 pin of the Arduino; connect the anode of the LED to the second pin of the PWM as shown below. Other basic connections are not repeated.

How to use MATLAB to develop robots

Figure 6 hardware connection diagram

Software preparation

Select the support package you need to install by using the Add-Ons Get Hardware Support Packages wizard on the MATLAB main interface.

How to use MATLAB to develop robots

Figure 7 installation package download portal

Select Arduino and follow the wizard prompts to download or install the support package.

How to use MATLAB to develop robots

Figure 8 Download Installation Wizard

After the installation is complete, open the Simulink Support Package for Arduino Hardware library in the Simulink Library Browser, as shown below. We can see a series of driver modules for Arduino. From the schematic diagram of the module and the symbols of the ports, we can roughly speculate on its role: reading or outputting signals from various types of board interfaces.

Also visible from the tree on the left, the driver modules for Ethernet Shield and Wifi Shield are also available.

How to use MATLAB to develop robots

Figure 9 Arduino support library

Modeling

Simulink modeling can be described as a drag-and-drop process for modules.

We need to read the voltage divider signal from the A1 port (voltage divider access), so drag an Analog Input module from the library and double-click to set the port number to 1, set the sampling time to 0.01 S. It also needs to be output to the second pin of the PWM (LED connection), so drag in a PWM module and double-click to set the port number to 2.

In order to simplify the entire download process, we do not do any algorithm processing on the signal, directly connect the two modules, as shown below. This means that the brightness of the LED is directly related to the state of the photoresistor.

How to use MATLAB to develop robots

Figure 10 model screenshot

Compile download

The Simulink Support Package for Arduino Hardware supports almost all Arduino models. Before clicking the button in the red box to compile and download, you need to specify the type of Arduino board currently used through the configuration page, as shown below.

How to use MATLAB to develop robots

Figure 11 Setting the Arduino board

Make sure that the Arduino is connected to the computer. Click the compile button in the red box in the screenshot of the above model. The block diagram will automatically generate the C/C++ code, and automatically call the Arduino IDE in the background to compile and download it to the Arduino board.

At this point, if you hold the photoresistor with your hand, you will see the change in the brightness of the LED.

Online debugging

For models such as the Arduino MEGA 2560, online debugging is also supported. In the configuration page, in addition to selecting the model, the following figure is set to 'External mode'.

How to use MATLAB to develop robots

Figure 12 Setting up online debugging operation

Click on the green simulation button in the figure.

How to use MATLAB to develop robots

Figure 13 Online debugging

At this point, the block diagram is also generated and compiled and downloaded to the Arduino, while the Simulink model is running. Double-click to open the oscilloscope Scope module to see the currently read sensor signal in real time. This data can also be saved for download and post-sensor calibration and analysis.

How to use MATLAB to develop robots

Figure 14 signal waveform

Sensor calibration, that is, it is often necessary to linearly or non-linearly scale and translate the original values ​​to obtain values ​​with physical meaning, such as custom light intensity levels. As shown in the figure below, a simple look-up table module is connected in the middle for linear scaling.

How to use MATLAB to develop robots

Follow-up

In addition to the Arduino examples of hardware that supports one-click download, the design of the algorithm can be very complicated. In fact, the more complex the algorithm, the better the advantages of the block diagram algorithm design method.

After downloading and installing the corresponding hardware support package, the help documentation will provide an application case from the shallower to the deeper. The following picture is a case of a LEGO algorithm.

How to use MATLAB to develop robots

Figure 15 LEGO algorithm algorithm model

Open this model, click compile, you can download this algorithm to the LEGO robot completely. If you are interested, you can try it yourself.

How to use MATLAB to develop robots

Figure 16 LEGO solution cube

Conclusion

Using the MATLAB/Simulink Support Package is equivalent to paving the way from Simulink to hardware implementation, so that people who are not good at writing C code can completely get rid of the trouble of code implementation. With Simulink platform, more interesting applications can be easily developed. .

3L Capacity Deep Fryer

3 Liter Oil Deep Fryer,3L Capacity Deep Fryer,Electrical Deep Fryer,Stainless Steel Deep Fryer

Shaoxing Haoda Electrical Appliance Co.,Ltd , https://www.hotplates.nl