Presentation is loading. Please wait.

Presentation is loading. Please wait.

A simple control application with Real Time Linux Peter Wurmsdobler Real Time Systems Lab 2001.09.12 Jong-Koo, Lim Paper Survey.

Similar presentations


Presentation on theme: "A simple control application with Real Time Linux Peter Wurmsdobler Real Time Systems Lab 2001.09.12 Jong-Koo, Lim Paper Survey."— Presentation transcript:

1 A simple control application with Real Time Linux Peter Wurmsdobler Real Time Systems Lab 2001.09.12 Jong-Koo, Lim Paper Survey

2 2 Contents I.Abstraction II.Introduction III.Control algorithm implementation ① Application architecture ② Real time module ③ User space application IV.Conclusion

3 3 Abstraction  A simple control application using real time linux is presented  A linux kernel module is responsible for Getting a value from a DAQ-board Carrying out the control algorithm Outputing the result to the DAQ board  This user application can set control parameters and adjust a setpoint in shared memory, or start and stop the control process by FIFO-buffers

4 4 Introduction  ‘Control Engineer’ vs ‘Software Engineer’  The real time application based on linux presented in this paper should make an access to ‘real time linux’ easier for a control engineer by implementing a simple discrete time controller

5 5 Control algorithm implementation  There is already some control algorithm defined in time discrete scheme  Software architecture for its implementation Time critical tasks and less time critical tasks have to separated.  Application here implements, only a ‘simple discrete time controller’ with its parameters to be adjustable from a graphical user space application

6 6 Application architecture  Two parts, ① Simple graphical interface being non-real time module - xcontrol, the X-Windows control interface ② Small real time module - rtl_control.o, the real time linux control kernel module  Communication of two parts, by FIFO(first-in-first-out) buffers - rtl_fifo.o Shared memory - mbuff.o

7 7 Logical Software Structure

8 ‘ The Modules’ used to talk two parts User space applicationKernel modules # define SHM_DEV_FILE (“/dev/mbuff”) # define SHM_NAME (“control”) # define SHM_SIZE (sizeof(shm_t)) typedef struct { unsigned int N; // length of measured vectors unsigned short int w; // {0,65535}, setpoint unsigned short int u[SAMPLES]; // {0,65535}, control current unsigned short int y[SAMPLES]; // {0,65535}, measured position Int a[LENGTH] ;// scaled control denominator of ORDER+1 Int b[LENGTH] ;// scaled control numerator of ORDER+1 } shm_t ; Shared Memory (shm.h) # define FIFO_SIZE (5000)// byte size for fifo buffer # define CONTROL_FIFO// for passing message to rt_control # define CONTROL_FILE “/dev/rtf0” # define EVENT_FIFO (1)// for triggering events in Xcontrol # define EVENT_FILE (1) “/dev/rtf1” # define START_CONTROL (‘a’) // xcontrol -> rtl_control # define STOP_CONTROL (‘b’) // xcontrol -> rtl_control # define TRIGGER_MEASURE (‘c’) // xcontrol -> rtl_control # define MEASURE_READY (‘a’) // rtl_control -> xcontrol # define INVALID_MEASURE (‘b’) // rtl_control -> xcontrol FIFO buffers (fifos.h) 8

9 The Other Modules extern int rt_bmc1000_ init (void); extern void rt_bmc1000_ release (void); extern unsigned shor int rt_bmc1000_ aget (void); extern void rt_bmc1000_ aset (unsigned short int channel, unsigned short int value); extern void rt_bmc1000_ mux_select (unsigned int channel, unsigned int range_code); BMC1000 DAQ board specific module (rt_bmc1000.h) 9

10 inline void rt_control_event_msg (unsigned char message) ; void * rt_control_thread (void *); static int rt_control_message_handler (unsigned int fifo); static void rt_control_start (void); static void rt_control_stop (void); static void rt_control_trigger_measure (void); All basic functions The Other Modules (cont.) 10 pthread_t control; // THE control thread, or task static int measure;// flag if measurement is on static shm_t *shm;// shared memory (sic!) static unsigned int index;// index in shared memory static int e[LENGTH]// control deviation buffer static int u[LENGTH]// control signal buffer static unsigned int k; // index k of actual value static unsigned short int Y; // THE measure value, input static unsigned short int U; // THE control value, output static unsigned short int W; // THE setpoint

11 Example of some basic function inline void rt_control_event_msg (unsigned char message) { rft_put(EVENT_FIFO, &message, 1) } static int rt_control_message_handler (unsigned int fifo); { unsigned char message; while(rft_get(fifo, &message, 1) > 0) { switch(message) { case START_CONTROL : rt_control_start(); break; case STOP_CONTROL : rt_control_stop(); break; case TRIGGER_MEASURE : rt_control_trigger_measure(); break; default : rt_control_event_msg(INVALID_MESSAGE) } return 0; } 11

12 12 Structure of RT Application User Process RT Fifo RT Process Peripheral Device Linux Kernel NetworkDisk X Windows Display RT-Kernel

13 Internal of in RTLinux Application pthread_t thread; void * start_routine(void * arg) {... } int init_module(void) { return pthread_create(&thread, NULL, start_routine, 0); } int cleanup_module(void) { pthread_delete(thread); } 13

14 In this RTL Application … void * rt_control_thread(void * arg) {... } int init_module(void) { … if (rt_bmc1000_init()) … // Initialize PCL818 DAQ board if (rtf_create(CONTROL_FIFO, FIFO_SIZE) < 0) … // Initialize rt-fifos if (rtf_create_handler(CONTROL_FIFO, rt_control_message_handler)) … // Initialize message handler if (shm_allocate(SHM_NAME, SHM_SIZE, (void **) &shm) < 0) … // Initialize shared memory … if (pthread_create(&thread, &attr, rt_control_thread, (void *)1) ) { printk( “ Initializing real time control thread failed ” ); return – ENOMEM; } printk ( “ %S Init module successful\n ”, RT_FILTER_ID); return (0); } int cleanup_module(void) { pthread_delete_np(control);// Delete control thread shm_deallocate(shm);// Release shared memory rtf_destroy (CONTROL_FIFO) ;// Release rt-fifos rt_bmc1000_release(); // Release the PC1000 DAQ board … } 14

15 15 Insert and Remove Module  insmod rtl_control.o This will make the init_module function to be called -Initailize everything such as hardware, rt-fifos, message handler, shared memory and kernel thread  rmmod rtl_control.o This will make the cleanup_module function to be called -The entire process is killed. -All resources being allocated are released.

16 User space application  This X-Windows interface is programmed using the GTK+ widget set library in combination with a scientific plot widget ( GTKplot ) 16 Graphic User Interface Input (Y) and Output (U), only with a sinusoilda input of 500 Hz at 10 kHz sampling rate

17 17 Conclusion  Arriving at the end of this paper, A control engineer even not too familiar with c should be able to understand the concept of implementing his control algorithm in real time linux. ☞


Download ppt "A simple control application with Real Time Linux Peter Wurmsdobler Real Time Systems Lab 2001.09.12 Jong-Koo, Lim Paper Survey."

Similar presentations


Ads by Google