[instructions] - real-time embedded systems...

25
Assignment -3 1. What is the general setup of embedded system control? In the industry the general setup typically consists of the following components given below. Here the basic interaction is between the low powered electronics domain interacting with the high power physical domain. Controller – Low power electronic component. Interacts with either human for high level inputs to the system. Could also be programmed to run certain jobs in a defined manner. Actuator – Is a type of device (motor) used to move and control a system. Plant - The plant operates in a high-power hydraulics, mechanics, thermal, and other physical domains. Here transducers are needed to convert between controller and the plant. Sensors – are used to provide measurements to the low power computational electronics domain.

Upload: phamcong

Post on 03-Jul-2018

221 views

Category:

Documents


0 download

TRANSCRIPT

Assignment -3

1. What is the general setup of embedded system control?

In the industry the general setup typically consists of the following components given below. Here the basic interaction is between the low powered electronics domain interacting with the high power physical domain.

Controller – Low power electronic component. Interacts with either human for high level inputs to the system. Could also be programmed to run certain jobs in a defined manner.

Actuator – Is a type of device (motor) used to move and control a system. Plant - The plant operates in a high-power hydraulics, mechanics, thermal, and other physical domains. Here

transducers are needed to convert between controller and the plant. Sensors – are used to provide measurements to the low power computational electronics domain.

2. But since we don’t have a robot arm lying around handy to test whether our design and code is working correctly we need a way to simulate this setup.

Here in this simulation environment the following components would be used.

Controller: Linux running either on a virtual machine or another system. The input to the target would be from the mouse interacting with the Linux system.

Actuator, Plant and Sensors would be provided as a Simulink model. This would simulate the behavior of a robot arm based on the inputs given to it from the controller. The model would also send back the sensor data as feedback.

2. What is Code Generation?

Simulink Embedded Coder™ generates C and C++ code from Simulink® diagrams, Stateflow® charts, and MATLAB® functions. The generated source code can be used for real-time and nonreal-time applications, including simulation acceleration, rapid prototyping, and hardware-in-the-loop testing.

For more details check out: http://www.mathworks.com/products/embedded-coder/

3. Basic steps for development and execution.

The entire setup requires 3 environments running:

a) TARGET Environment – Linux on VM ware or another machine. Since we require networking, the VM machine or remote machine should be networked.

b) Code Generation Environment: Due to licensing, students cannot generate code on their personal machines using the Simulink provided on MyApps (My ASU). For this you would be required to log into the virtual machines provided by ASU containing MATLAB-Simulink with the required licenses for code generation.

http://cidse.engineering.asu.edu/forstudent/labs/

c) HOST Environment – Use the locally installed Simulink on your machine (from MyApps) to run the robot model.

STEPS FOR CODE GENERATION WITH UDP COMMUICATION EXAMPLE

TARGET -LINUX HOST - SIMULINK

1. Open the VLAB desktop and login with you ASU credentials. For access to VLAB you would require CitrixReciever to be installed on your system. If accessing from off-campus locations you would also require a secure VPN login. The details of the setup are provided on the link provided above.

2. Open MATLAB R2013b within the VLAB. Now to build this example we need blocks for which we can generate target specific code, and in our case it would be Linux specific code. The special OS specific blocks are the one’s with LINUX written within them. Other generic blocks such as Function-Call Subsystem, S-Function Builder can be used as it is -for code generation.

3. In the main MATLAB command window type in mex –setup and set the compiler.

NOTE: For building models for the ROBOT (not needed for the example) you would also need to import the required parameters. Type in the matlab window the following command.

>> Robot_parameters

Please ensure that the robot_parameters.m file is present within the workspace.

CONFIGURING THE TARGET MODEL

4. -Start a new Simulink model. -Add the Task (Linux) and the Function-Call Subsystem blocks to generate a Linux thread. - Provide the startup code within the System Start Block. This is to read the keyboard key events. KEYBOARDFILE value would be mentioned with the header that you would be required to create. The steps for this would be given in the following sections.

if((fd = open(KEYBOARDFILE, O_RDONLY)) == -1) {

perror("opening device"); exit(EXIT_FAILURE);

}

- Provide a unique name to each task that you would be creating (if more than 1)

5. This is the complete view of the Function-Call Subsystem that would be needed.

Here set the following parameters for the Triggered Port block.

6. Add an S-Function Builder and set the following parameters

7. Within the Outputs window add the following code:

8. Build the s-function builder. Make sure that the Generate wrapper TLC checkbox is checked before building.

#ifndef MATLAB_MEX_FILEstatic int value = 0;read(fd, &ie, sizeof(struct input_event));/*printf("time %ld.%06ld\ttype %d\tcode %d\tvalue %d\n",

ie.time.tv_sec, ie.time.tv_usec, ie.type, ie.code, ie.value);*/if(ie.type == 4 || ie.code ==4){ value = value + ie.value; printf("|value = %d|\n", value );}y0[0] = value;#endif

9. UDP COMMUNICATION PRE-REQUISITES:For this you would be required to know the IP Address of the TARGET and the HOSTTo get TARGET IP (Linux) type in the Linux terminal:

To get the HOST IP (Windows) type in the command prompt:

NOTE: Every time you reboot your system- Linux or Windows- most likely the IP address would change.

10. SETTING THE UDP BLOCK parameters

With the IP address acquired now you can set the parameters for the UDP block in the following manner. Here IP and Port make up a unique communication channel for the TARGET and HOST to communicate over.

BUILDING THE TARGET MODEL and CODE GENERATION

11. Save the model and generate the code.

Set the following parameters within the code generation window.

GATHERING THE REQUIRED FILES

12. Gathering the files required for UDP communication.

Since we are using UDP communication blocks for LINUX TARGET, we need to get files .c and .h files from the MATLAB installation folders.

Copy the contents of the following folders into this folder:

C:\Program Files\MATLAB\R2013b\toolbox\target\extensions\operatingsystem\linux\src ( linuxUDP.c)

C:\Program Files\MATLAB\R2013b\toolbox\shared\dspblks\extern\include

C:\Program Files\MATLAB\R2013b\toolbox\shared\dspblks\extern\src

Open HostLib_Network.c and add the following line :

#define _USE_TARGET_UDP_

This would be a one-time effort . Make sure you copy these files and maintain them separately. EVERYTIME THE LINUX TARGET NEEDS TO BE BUILT THESE FILES WOULD BE REQUIRED.

13. Copying the generated files:

NOTE: EVERYTIME YOU BUILD THE MODEL AGAIN (WITH CHANGES) ALL OF THE FOLLOWING FILES WOULD NEED TO BE REPLACED.

A) Navigate to the MATLAB folder where the model was built.As for this example it was C:\Users\gbulusu\Desktop\Assignment_3\TARGET_MODEL and copy all of the .c files with names ending with wrapper (wrapper files). If there are more than one wrapper files, then copy all of them.

B) Go into the sub-folder within this folder and COPY ALL .c and .h files.

14. Create your own header. For the sake of is this example we have named it as RTES_Assgn3_headers.h

#include <semaphore.h>#include <pthread.h>#include <fcntl.h>#include <linux/input.h>#include "dlfcn.h"#include <stdio.h>

#define KEYBOARDFILE "/dev/input/event1"

int fd;struct input_event ie;

15. Create a Makefile:

16. CREATE ONE WORKING DIRECTORY which would contain all of the above mentioned files, and which would be copied to TARGET

default:

gcc *.c -o $(APP1) -lpthread -lm -ldl -include RTES_Assgn3_headers.h

clean:

rm -f *.o

rm -rf .tmp_versions

rm -f $(APP1)

17. Copy this folder (or all the above files) to LINUX TARGET and make.

To run target make sure you have root access because we are reading “/dev/input/event1” keyboard event file for this example.

BUILDING THE HOST MODEL

18. Open up MATLAB on your own systems. And add the following blocks to build the HOST.

Here UDP receive is not the LINUX UDP receive but from the Instrument Control ToolBox

NOTE: If you want to add any S-function builders into your host model then you just need to build them (as in Step 8) to run the simulation.

RUNNING THE ENTIRE SETUP – TARGET AND HOST

19. Make sure the TARGET and HOST are both ready before you start.On the Linux Target side it is advisable to run the target code from the LINUX NATIVE TERMINAL and not the terminal provided as a part desktop environment like LXDE desktop environment. To access the terminal press Ctrl + Alt + F6 and log in. Navigate to the working directory folder.

20. Run the Host simulation and Linux Target code- and see it all finally fall into place.