soft real-time scheduling for embedded control system

Upload: cristig99

Post on 02-Jun-2018

226 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    1/60

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    2/60

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    3/60

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    4/60

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    5/60

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    6/60

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    7/60

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    8/60

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    9/60

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    10/60

    3.5 Sensing component . . . . . . . . . . . . . . . . . . . . . . . 283.5.1 Image processing algorithm . . . . . . . . . . . . . . 29

    4 Experiments 314.1 Experimental setup . . . . . . . . . . . . . . . . . . . . . . . 314.2 Evaluation metrics . . . . . . . . . . . . . . . . . . . . . . . 324.3 Experimental results . . . . . . . . . . . . . . . . . . . . . . 334.4 Analysis Tool Results . . . . . . . . . . . . . . . . . . . . . . 35

    4.4.1 Computation time estimation . . . . . . . . . . . . . 354.4.2 Minimum bandwidth estimation . . . . . . . . . . . . 37

    4.5 Additional results in curved paths . . . . . . . . . . . . . . . 38

    5 Conclusions 43

    Bibliography 45

    viii

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    11/60

    List of Figures

    1.1 Differential drive mobile robot. . . . . . . . . . . . . . . . . 31.2 Basic feedback loop. . . . . . . . . . . . . . . . . . . . . . . 41.3 Mathematical model of a task. . . . . . . . . . . . . . . . . . 5

    2.1 Schematic view of the robots architecture. . . . . . . . . . . 92.2 BeagleBone Black Rev A5A. . . . . . . . . . . . . . . . . . . 10

    3.1 Example of the schedule of a task nishing before its deadline. 213.2 Example of schedule of a task nishing after its deadline. . . 213.3 Example of schedule of a task nishing after the threshold. . 223.4 General schema of a differential drive mobile robot. . . . . . 233.5 Tracking error with respect to the position ( y). . . . . . . . . 28

    3.6 Tracking error with respect to the orientation ( ). . . . . . . 283.7 Result of the algorithm of rectication on an image captured

    from the camera. . . . . . . . . . . . . . . . . . . . . . . . . 30

    4.1 Straight path and initial position of the robot. . . . . . . . . 314.2 Percentage of cancelled jobs vs. deadlines respected for differ-

    ent values of bandwidth. . . . . . . . . . . . . . . . . . . . . 344.3 Total time the robot was able to follow the line for different

    values of bandwidth. . . . . . . . . . . . . . . . . . . . . . . 35

    4.4 Root mean square estimation error of the distance from theline for different values of bandwidth. . . . . . . . . . . . . . 36

    4.5 Histogram of the computation time. . . . . . . . . . . . . . . 374.6 Probability distribution of the computation time. . . . . . . 374.7 Minimum bandwidth that guarantees the QoC specications. 384.8 Curved path and initial position of the robot. . . . . . . . . 394.9 Total time the robot is able to follow the line on a curved

    path, for different values of bandwidth. . . . . . . . . . . . . 40

    4.10 Root mean square estimation error of the distance from theline for different values of bandwidth on a curved path. . . . 41

    ix

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    12/60

    4.11 Percentage of cancelled jobs vs. deadlines respected for differ-ent values of bandwidth on a curved path. . . . . . . . . . . 41

    x

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    13/60

    Chapter 1

    Introduction

    It is well known that, in modern systems (e.g., an automobile), thenumber of embedded functionalities is considerably high and constantlyincreasing. The typical approach to address this situation used to be the useof dedicated electronic devices. Nevertheless, because of economic reasonsand its intractable engineering complexity, this strategy is no longer applied.Currently, each electronic computing unit (ECU) is required to sustainseveral applications, and this can only be achieved by an aggressive policyof sharing hardware and software resources among them.

    However, resource sharing presents the drawback of a reduced predictabil-ity of the timing behaviour. An application could receive different availabilityof resources, generating delays in its execution time due to the "interference"suffered from other application using the shared resources.

    Additionally, in the last years, the use of technologically advanced sensorssuch as video cameras, radars, or laser scanners, has become increasinglypopular in many real-time control applications. A characteristic of thesesensors is the production of a signicant computation workload. The process-ing of the sensed information depends heavily on the input data set, whichvaries from sensor to sensor. As a result, the computation requirements arehighly variable, leading to time varying computation delays.

    These two problems, the scheduling interference and the time varyingcomputation delays, undermine the classical assumptions of digital control:constant sampling time and xed delay in the feedback loop. The standardapproach in digital control relies on the combination of a time-triggeredmodel of computation [22] (which forces the communications between plantand controller to take place at precise points in time), and on the hard

    real-time scheduling theory [25] (which ensures that all the activities willalways be able to deliver the results at the planned instants).

    1

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    14/60

    CHAPTER 1. Introduction

    In the past few years, many researchers have investigated how to makea robust control design under an irregular timing behaviour of the imple-mentation [ 32, 21, 26]. Suitable ways to modify the scheduling behaviour in

    overload conditions have been tested [6, 8] basically by re-modulating thetask periods in response to an overload condition.

    Additionally, the hard real-time scheduling theory is extremely conserva-tive and reduces the number of tasks that can be executed simultaneously.This is not convenient, mainly because the strict respect of every deadline isnot necessary in several control systems [7].

    To overcome this situation it is necessary to explore new schedulingsolutions which combine performance guarantees with an efficient resourceutilization [ 16].

    Hence, a more promising direction is the application of soft real-timeapproaches, which allow for occasional temporal constraints violations inreturn for a more efficient utilization of the resources. This is achieved atthe cost of a degradation in the provided quality of service (QoS ). Sucha degradation often depends on the number and severity of the constraintviolations over a certain interval of time. Therefore, an objective to focus,when executing soft real-time applications, is to keep timing constraintviolations under control.

    In classical digital control design, the QoS is associated with the pair(T , D), where T denotes the sampling time and D is the loop delay. Thestandard tools of digital control allow the designer to identify the QoC performance given a (T , D) QoS specication. In the implemented solution[15], the period T is still used to trigger the activation of the control task,even though the samples are not always collected at the timer expiration. Inthe approach, the loop delay D is allowed to change according to a speciedmodel F D .

    This (T , F D ) QoS model allows us to set up an optimization problem,where the decision variables are the scheduling parameters of the controltask, and the goal is the minimization of the CPU utilization. All this, withthe constraint that the system must attain some specied quality of controlgoals (QoC ).

    In this work, a robotic scenario is dened. A control task, periodicallyactivated by a timer, compete for the CPU with other tasks, such as thedata acquisition and the data processing task. A resource-based schedulerallocates the CPU in presence of simultaneous execution requests. And,

    the use of the CPU is minimized in an attempt to save resources for otherapplications.

    2

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    15/60

    CHAPTER 1. Introduction 1.1 Robotic study

    1.1 Robotic study

    The robotic study considered in this Masters Thesis is heavily inspired

    in the automotive industry. The work is implemented on a mobile roboticcar (see Figure 1.1) designed and built at the Embedded Electronics andComputing Systems (EECS) research group at the University of Trento.

    Figure 1.1: Differential drive mobile robot.

    This type of mobile robots are known as differential drive robots. It isa mobile robot (e.g., cart or car), with usually two parallel driven wheels,one mounted on each side of its structure. It is also common, the presenceof a sort of offset castor to maintain the balance. The two driven wheelscan turn at different velocities (vr Right and vl Left). By controlling thosevelocities, the robot is able to move around the environment.

    The objective of this Masters Thesis is to implement a model of com-putation for concurrent real-time tasks which are characterized by highlyvarying computation times, and that run on a shared CPU. The implementedmodel is used by a feedback control loop. This solution allows the robot tofollow a dened straight path on the oor, with minimum CPU utilization,while guaranteeing the stabilization of the system. Additionally, the mini-mum CPU utilization experimentally measured on the real robot, will becontrasted with the results obtained on an analysis tool [15] developed bymembers of EECS.

    The robot in this study is equipped with a high frame rate camera (the

    sensor) pointing sideways which captures images of the line to be followed.This information is used by a line following algorithm that estimates the

    3

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    16/60

    1.2 Theoretical framework CHAPTER 1. Introduction

    orientation and the position of the robot with respect to the road line. Thefeedback controller uses these estimations to control the robot to follow thetarget path.

    1.2 Theoretical framework

    There were some theoretical foundations that had to be investigatedin order to successfully accomplish this Masters Thesis. These topics arebriey mentioned below.

    1.2.1 Control Theory

    The area of study that deals with the behaviour of dynamical systems andits inputs is called control theory [ 3]. The general concept can be expressedas: the external input of a system is called the reference; one (or more)output variables of a system need to follow the reference over time; hence, acontroller manipulates the inputs of the system to obtain the desired effecton its output. The inputs and outputs of a continuous control system aregenerally related by differential equations.

    The main objective of control theory is to calculate the corrective actions

    the controller has to apply, in order to ensure the stability of the system.This means that the system will remain in the reference point and will notoscillate around it.

    In control theory there are two basic types of control: feedback and feed-forward . This work is based on a closed-loop feedback system, asshown in Figure 1.2. The feedback control system [11], presents three maincomponents: a plant which is the object to be controlled, a sensor to measurethe output of the plant, and, a controller to generate the plants input.

    Figure 1.2: Basic feedback loop.

    Control theory provides the general framework that describes the designand implementation of the controller for the robot.

    4

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    17/60

    CHAPTER 1. Introduction 1.2 Theoretical framework

    1.2.2 Real-Time Tasks

    In general, a real-time task [5] can be seen as a sequence of actions (e.g.,a process, a thread) with an associated temporal constraint, called deadline ,that must be respected to ensure the correctness of the application. It isuseful to dene a formal model to identify tasks and associate deadlines tothem. The mathematical model of a task can be viewed as:

    A real-time task i consists of a stream of jobs J i,j with j Z > 0 . Each job J i,j is activated at time r i,j and nishes at time f i,j after executingfor a time ci,j . The job J i,j is also characterised by a deadline di,j , that isrespected if f i,j di,j , and is missed if f i,j > d i,j . The response time of jobJ i,j is i,j = f i,j r i,j . Figure 1.3 shows the typical characterization of atask.

    Figure 1.3: Mathematical model of a task.

    A periodic tasks is a task which is periodically activated after a xedamount of time, called task period T i (e.g., r i,j +1 = r i,j + T i ). Moreover,there are some periodic task where each activation time is also the deadlineof the previous instance (e.g., di,j = r i,j +1 ).

    A deadline is said to be hard, if a deadline miss causes a critical failurein the system. A deadline is said to be soft, if a deadline miss causes adegradation in the Quality of Service, but is not a catastrophic event. Thetask is called a hard real-time one, if all the deadlines are met; and is calledsoft real-time, if deadlines are met with a given probability.

    The worst case utilization of a task ( U i ), dened as the maximum fractionof processor time spent in the execution of the task set, is given by:

    U i = sup jci,jT i

    and the utilization of the system ( U ) is given by:

    U =i

    U i

    5

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    18/60

    1.2 Theoretical framework CHAPTER 1. Introduction

    1.2.3 Reservation-based Scheduling

    This form of scheduling is used together with a class of real-time appli-cations whose quality of output depend on sufficient access to a resourceover time [27]. Reservation techniques proved to be very effective in pro-viding temporal isolation, meaning that a task who has reserved a specicamount of a resource should have access to this regardless of what othertasks are running on the system. These techniques have been implementedin a number of different systems using different scheduling algorithms [1,23].

    A reservation is a pair ( Qi , T i ), where Q i is the amount of time that thetask is allowed to use the resource within every reservation period T i . The

    fraction of resource utilization dedicated to task i is given by Bi = Qi /T iand, normally, it is called bandwidth . Qi is also called the budget or capacityof the reservation. It is often useful to set the reservation period so thatT = kT i , where k N and T is the task period.

    The behaviour of a reservation is the following: a task i attached toa reservation (Q i , T i) can execute for a time Qi with a real-time priority,assigned according to some real-time scheduling policy, like Rate Monotonicor Earliest Deadline First (EDF) [ 24]. The reservation is often implementedusing a budget q i that is recharged to the maximum value Qi at the beginningof every reservation period, and is decreased during the task execution. Whenthe budget reaches zero, the reservation is said to be depleted.

    Although any scheduling algorithm could be used to implement a reserva-tion strategy, the use of a dynamic priority scheduler permits to obtain a moreefficient implementation. An example is the Constant Bandwidth Server(CBS) [1], a reservation algorithm based on the EDF priority assignment,that uses a server mechanism to implement reservations.

    The selection of a scheduling algorithm, that allows modelling the delay

    evolution of one task resulting from a choice of scheduling parameters, isfundamental in this work.

    1.2.4 Vision-based localization

    Generally speaking, robotic scientists refer to the autonomous capabilityof a vehicle to follow a desired path as a path following problem [2, 35]. In thiscontext, line detection and obstacle recognition through smart cameras havean essential role for road environment reconstruction and safety improvement

    [17, 37].Unfortunately, camera-based systems often rely on complex vision al-

    6

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    19/60

    CHAPTER 1. Introduction 1.3 Document Organization

    gorithms that can hardly meet the real-time constraints. These problemsare caused mainly by a low image acquisition rate, limited resolution, orexcessive computational load. Moreover, complex vision systems may suffer

    from critical reliability and robustness problems due to time-varying lightconditions or vehicle vibrations.

    For these reasons researchers are increasingly developing robust andcomputationally efficient solutions for visual path following [20, 17, 29].

    In the specic case of this work, the solution proposed in [29] was chosen.The referred work presents a vision system that is able to recognize alongitudinal road line and to estimate, with respect to vehicle movementdirection, the position as well as the orientation of the robot in real-time.Thus, longitudinal road lines (either a central line or a lateral one) could beused as a reference for automatic trajectory correction.

    The vision algorithms used for the camera use a combination of Ran-domised algorithms (RANSAC) [13] and Kalman Filtering [33].

    1.3 Document Organization

    The rest of the paper is organized as follows. Chapter 2 presents anoverview of the different components both of the hardware and software used

    in this work. Chapter 3 provides specic details regarding the developedapplication, focusing mainly on the model of computation of the controltask and the design of the controller. Chapter 4 describes the experimentalactivities performed, and the discussion of the results. Finally, Chapter 5elaborates on the conclusions of this Masters Thesis.

    7

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    20/60

    1.3 Document Organization CHAPTER 1. Introduction

    8

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    21/60

    Chapter 2

    Architecture of the robot

    This chapter presents a brief description of the robots elements that wereused for the development of this Thesis. These elements include the mainhardware components and the software platform running on the embeddedboard.

    The robot is equipped with a BeagleBone Black [9] board running apersonalized Linux kernel. It also includes a camera, mounted on the side,used to follow the path indicated by a line on the oor. In Figure 2.1 it is

    possible to observe a schematic view of the architecture of the robot.

    Figure 2.1: Schematic view of the robots architecture.

    The BeagleBone Black is the "brain" of the robot. This unit is in chargeof the control process. Exploiting the data captured by a USB camera, itperforms the "sensing" function. Commands are sent to the driver of the

    motors through the CAN Bus. Additionally, the unit communicates, via anad-hoc wireless network, with a PC for debugging and safety procedures.

    9

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    22/60

    2.1 Hardware overview CHAPTER 2. Architecture of the robot

    2.1 Hardware overview

    As mentioned before, the robot contains several hardware components

    that will be briey mentioned in the following subsections.

    2.1.1 BeagleBone Black

    The BeagleBone Black, displayed in Figure 2.2, is a low-cost high-expansion computer using a Sitara XAM3359AZCZ100 Cortex A8 ARMprocessor from Texas Instruments. Its main characteristics are:

    Processor AM3359AZCZ100, 1 GHz

    Video Out HDMIDRAM 512 MB DDR3LFlash 2GB eMMC, uSD

    Serial Out HeaderPower 210-460 mA@5V

    Ethernet 10/100 RJ45

    It is important to point out that the BeagleBone Black supports differentexpansion capes. One of these capes is a CAN Bus Cape, which is the basefor the communication with the motors of the robot.

    Figure 2.2: BeagleBone Black Rev A5A.

    The BeagleBone Black is shipped with a Linux 3.8 kernel. It supports

    out-of-the-box distributions like Fedora Core, Android, Ubuntu, openSUSEand ngstrm. The board also supports other operating systems such as:

    10

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    23/60

    CHAPTER 2. Architecture of the robot 2.1 Hardware overview

    FreeBSD, NetBSD, OpenBSD, QNX, MINIX 3, RISC OS, and WindowsEmbedded.

    2.1.2 Motors, drivers and encoders

    The robot has two stepper motors mounted on its sides. A steppermotor is a motor, meaning that it converts electrical power into mechanicalpower, which unlike other motors does not rotate continuously. Instead, itdivides a full rotation into a number of equal steps. Each step is a fractionof a full circle.

    The stepper motor also differs in the way it is powered. Instead of an ACor a DC voltage, this motor is usually driven with pulses, and each pulse istranslated into a degree of rotation which is usually denominated the basicstep angle.

    Additionally, a motor controller or driver is a device that serves togovern in some predetermined manner the performance of a motor. It mightinclude manual or automatic means for starting and stopping the motor,selecting forward or reverse rotation, selecting and regulating the speed,regulating or limiting the torque, and protecting the motor against overloadsand faults.

    Finally, an incremental rotary encoder is a sensor of mechanical motionthat generates a train of digital pulses which can be used to determine theposition, velocity and direction of a motor, in response to rotational motion.

    Encoders are controlled through the rotation of the shaft they aremounted on. The shaft comes into contact with an internal hub of theencoder. As the shaft rotates, it causes a disc, with both transparent andsolid lines, to rotate across the circuitry of the encoder. The circuitry of the encoder includes a LED which is captured by a photoelectric diode andemits pulses visible to the user. The speed at which the disc rotates will bedependent on the speed of the shaft the encoder is connected to.

    The resolution of incremental encoders is frequently described in termsof cycles per revolution (CPR). Cycles per revolution are the number of output pulses per complete revolution of the encoder disk.

    In this architecture, the encoder is directly mounted to the end of amotor via a shaft. The critical parameter of measurement is the motor speed.The encoder provides feedback to the driver, allowing the driver to verifythat the speed and direction are correct. There is a team effort between the

    driver and the encoder. This ensures that whatever the motor is driving,runs safely and smoothly, and does not run out of control or erratically in

    11

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    24/60

    2.1 Hardware overview CHAPTER 2. Architecture of the robot

    applications where a precise speed is required.The motors used in this work provide 4000 steps per revolution, resulting

    in a basic step angle of 0.09 . Moreover, a 1:16 gear reducer is introduced

    between the motor shaft and the encoder. Therefore, the resolution of theencoders is 64000 CPR; meaning that there are 64000 pulses generated pereach complete revolution of the encoder.

    2.1.3 CAN Bus

    The Controller Area Network Bus (CAN Bus) [10] is an automotive serialbus protocol designed to allow micro-controllers and devices to communicate

    with each other, within a vehicle, without a host computer. This protocolefficiently supports distributed real-time control with a very high level of security. The protocol has become very popular in automotive applicationsand it is currently used in other areas such as aerospace, maritime, industrialautomation and medical equipment production.

    The CAN Bus is a Carrier-Sense Multiple-Access protocol with CollisionDetection and Arbitration on Message Priority (CSMA/CD+AMP). CSMAmeans that each node on a bus must wait for a prescribed period of inactivitybefore attempting to send a message. CD+AMP means that collisions areresolved through a bit-wise arbitration, based on a pre-programmed priorityof each message in the identier eld of the message. The higher priorityidentier always wins the bus access.

    In a CAN network, many short messages are broadcast to the entirenetwork, which provides data consistency in every node of the system. EachECU is able to send and receive those messages, but not simultaneously. Amessage consists primarily of an identier (ID), which represents the priorityof the message, and up to eight data bytes. The message is transmittedserially onto the bus at a maximum signaling rate of 1 Mbps.

    2.1.4 Camera

    The sensor of the robot is a camera. The chosen option was the PlaySta-tion Eye which has become a popular choice for interactive applications. Itis a digital camera device practically built for Computer Vision applications.The camera performs well in variable lighting with a low-latency USB per-

    formance, and is capable of capturing at high frame rates ranging from 15to 60 fps at 640x480 pixels or even 125 fps at 320x240 pixels.

    12

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    25/60

    CHAPTER 2. Architecture of the robot 2.2 Software overview

    2.2 Software overview

    Software elements are essential for the joint operation of the different

    hardware components and the correct functionality of the application understudy. In this section, the main software components in the implementedarchitecture are described.

    2.2.1 Linux kernel

    The kernel [18] is the core of an operating system. The operating systemis the collection of all the programs that manage the hardware and allow theusers to run applications on a computer. The kernel controls the hardware

    and applications. Applications do not communicate with the hardwaredirectly, instead they do it through the kernel. In summary, software runson the kernel and the kernel operates the hardware.

    The Linux kernel is a monolithic kernel. This means that a portion of the RAM is reserved as kernel space, the whole operating system is placedthere and only the kernel may use that space until the system is turned off.In contrast to the kernel space, there is the user space. This is the portionof the RAM that the users programs own. Applications like web browsers,video games, or word processors, are placed there. When an application isclosed, any program may use the newly freed space.

    Because the Linux kernel is monolithic, it has the largest footprint andthe highest complexity over the other types of kernels. In order to avoidsome of the problems of monolithic kernels, Linux kernel developers decidedto make kernel modules that could be loaded and unloaded at runtime. Asa result, adding or removing features of the kernel on the y can be done.This goes beyond just adding hardware functionalities to the kernel. It isalso possible to include modules that run server processes, and even, in someinstances, allow the entire kernel to be replaced without needing to rebootthe computer.

    The Linux kernel is also a preemptive multitasking kernel. This meansthat the kernel will pause some tasks to ensure that every application gets achance to use the CPU. One of the most interesting aspect of Linux, givenits size and complexity, is its portability. Linux can be compiled to runon a huge number of processors and platforms with different architecturalconstraints and needs.

    Another important functionality in the Linux kernel is the concept of

    patches. A patch is a small text document containing a delta of changesbetween two different versions of a source tree. Basically, a patch contains

    13

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    26/60

    2.2 Software overview CHAPTER 2. Architecture of the robot

    updates in the code that usually x bugs or enhance the performance. Tocorrectly apply a patch it is important to know what base it was generatedfrom, and what new version the patch will change the source tree into.

    Usually, the patches are applied to the uncompressed source code before thekernel is congured.

    As stated before, the BeagleBone Black is shipped with a Linux kernel3.8.13 ashed in the eMMC memory; however it is mandatory for this workto include a specic patch called SCHED_DEADLINE [ 12] for reasons thatare detailed in the following subsection. The BeagleBone Black offers thepossibility of booting from an external uSD card where any Linux distributioncan be stored. This feature gives the freedom to compile a new size-madekernel for the BeagleBone Black, which includes all the characteristics neededfor the work.

    The compiling process presents some peculiarities due to the interestof keeping most of the functionalities provided by the embedded platformand that have to be considered when compiling the kernel. There are somepatches that must be applied to guarantee the proper behaviour of theBeagleBone Black. In order to ensure this, the instructions in [31] wherefollowed, as stated here:

    1. Install and congure the cross-compiler for ARM to guarantee thatthe programs can be executed in this platform.

    2. Congure the bootloader, which is the program that loads the mainoperating system for the platform after completion of the self-tests.

    3. Download, patch, and compile the Linux kernel using the cross-compiler.

    4. Download the root le system for the compiled kernel.

    5. Setup the uSD card to store the operating system.

    6. Install the kernel and the root le system in the memory card.

    The BeagleBone Black in this work has a Linux kernel 3.8.13-bone28fully patched according to its necessities. The SCHED_DEADLINE patch,

    which is fundamental for this work, is not included as a basic component of the platform.

    14

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    27/60

    CHAPTER 2. Architecture of the robot 2.2 Software overview

    2.2.2 SCHED_DEADLINE patch

    This patch is the implementation of the real-time scheduling algorithmcalled Earliest Deadline First (EDF), one of the most common real-timescheduling algorithms. EDF is a dynamic scheduling algorithm used inreal-time operating systems to place processes in a priority queue. Whenevera scheduling event occurs, the queue is called to search the process whosedeadline is closest. This process is then established as the next one to bescheduled for execution.

    SCHED_DEADLINE provides a "temporal isolation". This feature grantsthat the temporal behavior of each task (i.e., its ability to meet its deadlines)is not affected by the behavior of any other task in the system. In other

    words, even if a task misbehaves, it is not able to exploit a larger CPUshare than the amount it has been allocated, with its own -strictly enforced-periodicity.

    In this implementation, each task is characterized by a "budget" anda "period" (equal to its deadline). At any time, the system schedules theready task(s) having the earliest deadline(s). During execution, the budgetis decreased by an amount equal to the time executed. When a tasks budgetreaches zero (i.e., the task was executed for a time interval equal to itsbudget), the task is stopped until the time instant of its next deadline. Atthe deadline point, the task is resumed, its budget is relled, and a newdeadline is computed.

    As a result, each task is guaranteed a share of processor time. Of course,the sum of the time assigned to each task cannot be higher than the totalbandwidth available in the system (usually equal to the number of CPUs).If this constraint is not accomplished, deadlines cannot be guaranteed anylonger.

    The kernel on the BeagleBone Black includes the SCHED_DEADLINE

    patch version 7.0.

    2.2.3 OpenCV

    OpenCV (Open Source Computer Vision) [4] is a cross-platform libraryof programming functions mainly focused on real-time computer vision andimage processing. The platform includes interfaces for C++, C, Python andJava. OpenCV was designed for computational efficiency and it can takeadvantage of multi-core processing. The version of OpenCV used in this

    work is the 2.4.5.

    15

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    28/60

    2.2 Software overview CHAPTER 2. Architecture of the robot

    16

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    29/60

    Chapter 3

    Application development

    This chapter focuses on the application developed during this MastersThesis. It includes the denition of a platform model describing the differenttask involved in the solution. The scheduling algorithm, and the decisionregarding the selection of its parameters, are explained here. Additionally,the implementation of the model of computation for the control task, andthe design and implementation of the controller for the robot are detailed.Finally, a brief description of the image processing algorithm applied, andits integration in the nal solution are presented.

    3.1 Platform model

    For this work, it is considered a scenario where a set of 3 tasks (T = iwith i {1, 2, 3}) share the same computation platform. These tasks areimplemented as threads; meaning that they can be managed independentlyby the operating system scheduler. They are described as follows:

    1. Image capture task: it is a periodic task that is responsible for inter-

    acting with the camera and obtaining the image to be processed. Theperiodic characteristics of this task depends, exclusively, on the framerate supported by the camera.

    Moreover, the capture period is important in this work because it isused to determine the period of the control task. As mentioned before,the chosen camera offers a wide range of resolutions and frame rates.Nevertheless, it was decided to set this parameter to a capture of 30frames per second, which translates in capturing one frame every 33 , 33ms.

    2. Control task: it is the task in charge of controlling the robot. It receives

    17

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    30/60

    3.2 The scheduling algorithm CHAPTER 3. Application development

    the position and orientation of the robot, estimated from the imageprocessing task, and produces the control output that guarantees thestability of the robot. Additionally, the control task implements the

    model of computation that establishes the precise time for the nextactivation of the controller.

    It is important to note that the periodicity of the control task isvariable depending on the evolution of the delay experienced by theimage processing task. In the nominal case, the control task behavesas a periodic task with period equal to 100 ms (three times the periodof the capture task). However, in presence of delay, its period changesand becomes 33.33 ms (one period of the capture task).

    3. Image processing task: it is the task responsible for the image process-ing. This task takes the captured images, i) reduces their dimensionsto 160x120 pixels, ii) converts them to gray-scale, iii) applies an edgelter to the converted images, and then, iv) runs the image processingalgorithm.

    An output of this task is the estimation of the distance from the robotto the centre of the line, and also the orientation of the robot withrespect to the line. This data is then used by the control task toperform corrective actions when needed.

    This task present the characteristic that is completely under the su-pervision of the control task. It is initiated by it, when there is anavailable image and the control output has been released; and, it canbe terminated by the control task, when its computation time haspassed a predened threshold.

    Based on the description of the task, it is possible to observe that some

    tasks in T are real-time tasks (e.g., the image processing task), while othersare best-effort tasks (e.g., the image capture task). The former have temporalconstraints on their execution, while the latter do not receive any kind of temporal guarantees.

    3.2 The scheduling algorithm

    As stated before, the Linux kernel on the embedded board includes a

    scheduler adopting the resource reservations policy [34]. Resource reservationsare shortly explained as follows.

    18

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    31/60

    CHAPTER 3. Application development 3.3 QoS Model for the control task

    Each task i is associated with a reservation pair (Qi , Ri), meaningthat it is allowed to execute for Qi time units (known as budget) in everyinterval of length Ri (reservation period). The bandwidth allocated to the

    task is dened as Bi = Qi /R i and corresponds to the fraction of CPU timeallocated to the task. The reservation period Ri is typically chosen as aninteger sub-multiple of the task period: T i = N i R i where N i N .

    The implementation of the resource reservation approach considered hereis the CBS [1]. In this situation, the bandwidths assigned to the differenttasks have to respect the constraint:

    iB i U lub , U lub = 1

    As a result, the sum of the bandwidth assigned to the different taskscannot exceed a bound ( U lub ), which quanties the efficiency of the schedulingalgorithm.

    When this condition is respected, it is possible to give temporal guaranteesto each task based on its computation requirements and on its schedulingparameters, regardless of the parameters of the other tasks in the system.Therefore, the policy used to choose the reservation parameters (Q i , R i )depends on the real-time constraints of the task and on its computation

    requirements.In this work, only a static policy is considered. The parameters arechosen once and for all, and are kept constant throughout the execution of the task. The particular election for the reservation period was Ri = 33.33ms which coincides with three reservations periods within a period of thecontrol task ( N = 3).

    For a soft real-time task with known distributions of the computationtime, as in this case, it is possible to compute the minimum bandwidth(B i) that has to be assigned to the image processing task to ensure theachievement of the QoC requirements. This is performed using an analysistool developed within the group. As mentioned before, it is of interestfor this thesis, to contrast the results obtained experimentally with thoseobtained by the analysis tool.

    3.3 QoS Model for the control task

    As previously stated, it is necessary to construct a QoS model (T, F D )

    for the control task that describes the evolution of the delays introducedin the computation of the image processing task under different scheduling

    19

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    32/60

    3.3 QoS Model for the control task CHAPTER 3. Application development

    parameters, namely different budgets ( Q i ).It is important to remember that the image processing task is scheduled

    by a reservation ( Qi , R i ) and, due to the temporal isolation property, evolves

    independently of the other tasks. The control task is activated, in its nominalbehaviour, with period T i = NR i ; each activation produces a job J j thattakes a sample y j from the output of the plant and produces a control valueu j .

    To construct a QoS model that can be used in the control design, it isnecessary to know the precise instant s j when y j is sampled (sampling time)and the instant v j when u j is released (release time).

    Although, in the nominal behaviour, the control task should present aperiodic activation, the collection of the input samples, the execution of theimage processing algorithm, and the release of the computation result, couldbe affected by several sources of timing uctuations (jitter) and computationtime variability. Therefore, it is important to dene a model of computationthat specify the possible sampling and release times ( s j and v j respectively).

    This model of computation is given by:Rule 1: If a job J j nishes before its deadline (e.g., f j < d j = r j + T ), the

    release of the output u j is deferred to the end of the period (e.g. v j = r j + T is forced).

    Rule 2: If a job J j nishes after its deadline (i.e. r j + T + ( D j 1) R < f j r j + T + D j R with D j N ), the release of the output u jtakes place immediately at the end of the present reservation period (e.g.,v j = r j + T + D j R is enforced and D j is the number of delayed reservationsperiods of job J j ).

    Rule 3: If a job J j experiences a delay D j greater than a threshold, it iscancelled and a new job J j +1 is activated. In this work, the threshold is setto a control task period; hence, the maximum number of delayed reservationperiods allowed is set to 3.

    Rule 4: The output y j is sampled at the same time the control u j 1 isreleased (at instant s j = v j 1 ).

    In order to clarify the behavior of the model of computation, someillustrative examples are presented. These examples are developed underthe following initial considerations:

    The nominal period of the control task is set to 9 time units ( T = 9 ).

    The reservation period of the image processing task is set to 3 timeunits ( R i = 3).

    The budget of the image processing task is set to 3 time units ( Q i = 3 ).

    20

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    33/60

    CHAPTER 3. Application development 3.3 QoS Model for the control task

    The bandwidth assigned to the image processing task is set to 1 timeunits ( B i = 1).

    The number of reservation periods within the control task period isset to 3 (N = 3).

    The computation time ( ci,j ) of a given job J j is subject to strong timevariations.

    Figure 3.1: Example of the schedule of a task nishing before its deadline.

    Figure 3.1 presents the situation of a job J j with computation timeci,j = 3 time units. It evolves in the nominal behavior; arrives at time 0and nishes its processing at time 7. The next activation of the control taskoccurs at time 9; and, since the job has nished, the output can be releasedand the next input is sampled ( v j = s j +1 = 9). This is dened by Rule 1.

    Figure 3.2: Example of schedule of a task nishing after its deadline.

    Figure 3.2 presents the situation of a job J j with computation timeci,j = 4 time units. Given a bandwidth of 1 time unit ( B i = 1 ) it is intuitiveto observe that the deadline will be missed ( D i = 1 ). This situation producesa change in the nominal behavior of the period of the control task.

    In the example, the control task wakes up at time 9 but the imageprocessing task has not yet nished yet. Thus, the periodicity of the controltask changes from 9 time units to 3 time units. At time 12 , the control taskwakes up again and the image processing task has already nished. Then,the output is released and a new input sample is captured.

    Besides, a temporal next activation is calculated, forcing the next control

    task to realign with its initial nominal behavior (the next control task willwake up at time 18) and the algorithm continues normally.

    21

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    34/60

    3.3 QoS Model for the control task CHAPTER 3. Application development

    Note that this delay in the computation time penalizes the behavior of the next captured image because it will have only 6 time units to nish theprocessing before the control task will wake up again.

    Figure 3.3: Example of schedule of a task nishing after the threshold.

    Finally, Figure 3.3 shows an example of a job J j with extremely largecomputation time ci,j = 8 time units. As stated before, the maximumnumber of delayed reservation periods allowed is 3; meaning that, in total,the image processing task is allowed to execute for 6 reservation periods ( 6time units). In this example, that amount of time is not enough to nish theimage processing, causing the drop of the job J j and the activation of thenext one J j +1 . This is stated in the Rule 3 , which avoids the accumulation of

    very large delays. This strategy is applied since these delays are impossibleto be compensated.It is important to point out that, in dropping situations, when a new

    frame is captured and sent to the image processing task, it is considered asif it already has 3 delayed reservation periods. In the example, the controltask will wake up at time 21 to verify if the image captured at time 18 hasnished its processing. If by time 27, it has not nished yet, it will also bedropped.

    Rule 4 ensures that output sampling always occurs at the beginning of areservation period, even if the task can receive its budget later in the samereservation period.

    As nal remarks in this section, if the computation consistently terminateswithin the deadline, the application of the rules recovers the standard time-triggered behaviour with periodic sampling and a xed delay equal to T inthe computation.

    On the other hand, when the task execution gets delayed, Rule 4 allowsa more exible management of the sampling instants than a time-triggered

    approach: when the next job starts its execution, it is given the possibilityof using fresher data. This can be seen in the examples.

    22

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    35/60

    CHAPTER 3. Application development 3.4 Control task

    3.4 Control task

    The Thesis requires to determine a feedback control law such that the

    differential drive robot moves at constant speed following a straight line onthe oor, at a predetermined distance from it. A differential drive robot canbe outlined by the following characteristics, see Figure 3.4.

    Figure 3.4: General schema of a differential drive mobile robot.

    1. Dimensions: The two main parameters that have to be consideredare the wheel base (how far away are the wheels from each other)represented by L and the radius of the wheel, R.

    2. Inputs: Although the objective is to control how the robot is movingin the environment, the available control signals are vr and vl (therate at which the wheels are turning) hence those are the inputs of thesystem.

    3. Position: The robot can be represented by P = (x, y, ), with x and yas the position of the robot (where the robot is) and as its orientation(where the robot is heading to) in the world reference frame. Theseare called the states of the system.

    In order to design a controller for the differential drive robot, it isnecessary to dene its mathematical model. This model has to map the

    inputs ( vr and vl) with the states of the robot. The differential drive robotmodel is given by:

    23

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    36/60

    3.4 Control task CHAPTER 3. Application development

    x = R2 (vr + vl)cos

    y = R2

    (vr + vl)sin

    = RL

    (vr vl)

    (3.1)

    This model is very useful in the implementation of the controller; however,it is not natural to design controllers in terms of wheel velocities. For thisreason, the unicycle model [36] is used instead of the differential drive one.This model comprises many known differential drive robots and approximate

    in many situations even the four wheeled cars.

    3.4.1 Unicycle model in state space form

    The unicycle model overcomes the issue of dealing with unnatural termslike wheel velocities and allows to deal directly with the position and theorientation of the robot. Therefore, the pair ( v, ) is the input control, whichrepresents respectively, the linear velocity (how fast the robot is moving) andthe angular velocity (how quickly the robot is turning). In the particularcase of this study, the velocity v is assumed to be constant (v = k) hencethe input control is only the angular velocity, .

    It is important to clearly specify the geometric characteristics of the pathto be followed. The unicycle model slightly differs depending if the pathconsidered is straight or curved [28, 30]. The non-linear model that describesthe kinematics of the unicycle model for a straight path is:

    x = k cos y = k sin =

    (3.2)

    However, this non-linear model is not suitable for the design of thecontroller, therefore it must be linearized. Considering the condition wherethe orientation of the robot is very small ( 0) then the following approxi-mations could be done:

    cos() 1sin()

    It is also possible to neglect the rst of the three equations in ( 3.2) sincethe behaviour over the x axis is not interesting for this work. As regards

    24

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    37/60

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    38/60

    3.4 Control task CHAPTER 3. Application development

    x =0 k0 0

    y

    +01

    y =1 00 1

    y

    The further step is the discretization of the model. This process regards thetransposition of the continuous time model into its discrete counterpart, inorder to make it suitable for numerical evaluation and implementation on adigital embedded system.

    Assuming zero-order hold for the input u, the continuous time statespace form in (3.4) can be discretized to:

    x(k + 1) = Adx(k) + Bdu(k)

    y(k) = C dx(k)(3.5)

    where,Ad = eAT

    Bd = T

    0eA dB

    C d = C

    and T is the sampling time. Now, the discrete time state space form of the model would be:

    x(k + 1) =1 kT 0 1

    y(k)(k)

    +kT 2

    2T

    (k)

    y(k + 1) =1 00 1

    y(k)(k)

    Once the system is discretized, it is possible to continue with the design of the controller.

    3.4.2 Design of the controller

    As stated before, the main objective when applying a control input is toensure the stability of the system. The stability of a discrete time systemcan be studied from its eigenvalues which are given by the matrix A. The

    system is asymptotically stable if and only if, for all the eigenvalues of A,its real part is negative (Re() < 0, eig(A)); therefore, the goal in

    26

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    39/60

    CHAPTER 3. Application development 3.4 Control task

    the design of the controller for the closed-loop system must be to obtaineigenvalues with negative real part.

    In order to obtain those eigenvalues, and assuming that it is possible to

    measure all of the state vector, the state feedback design method will be used.Given the discrete time state space system in (3.5) and the state feedbackcontrol law: u = Kx , where K is the static feedback gain. This gives:

    x(k + 1) = Adx(k) BdKx (k)= ( Ad BdK )x(k)

    The application of the state feedback control law produces a new systemmatrix A, usually know as closed-loop dynamics and given by:

    A = ( Ad BdK ).

    Evidently, this will also change the eigenvalues of the system. Now, thecontrol design task, from the stability point of view, consists of picking, if possible, K such that the closed-loop system is stabilized. This means thatthe real part of the eigenvalues of the closed-loop dynamics has to be strictlynegative ( Re(eig(Ad BdK )) < 0).

    In order to do that, an optimal control approach, known as LinearQuadratic Regulator, was chosen. This method allows to nd out the besttrade off between fast response and input signal size. This can be viewed asnding K which minimizes the following "cost":

    k =0x(k)T Qx(k) + u(k)T Ru (k).

    where Q and R are positive denite weighting matrices for the state errorand the control action respectively.

    Before implementing the designed controller on the embedded platform,there was performed an analysis (simulation) to verify its behavior. Thevelocity of the robot and the sampling time of the discretization were set,respectively, to 0.5 m/s and 0.1 s. The initial position of the robot wasconsidered as y0 = 12 cm. and 0 = 15 degrees.

    Figure 3.5 presents the time taken by the designed controller to reachthe desired position in the y axis. It is possible to observe that the controllerneeds 5 s. to overcome the initial position of the system and locate it in thedesired position.

    Additionally, Figure 3.6 shows the settling time for the orientation ()

    of the robot. Once again, the controller needs 5 s. to adjust the initialorientation of the system towards the desired value.

    27

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    40/60

    3.5 Sensing component CHAPTER 3. Application development

    Figure 3.5: Tracking error with respect to the position ( y).

    Figure 3.6: Tracking error with respect to the orientation ( ).

    3.5 Sensing component

    The next key aspect of a control system regards the sensing componentwhich measure the physical state of the system and provide an accurateestimation for the feedback controller to take the convenient actions. In thepresent work, the sensing task is performed by a camera which capturesimages of 320x240 pixels at 30 frames per second.

    A clear advantage of video systems is their relative low-cost compared toother sensors such as laser scanners and their ability to collect a large amountof data. A potential limitation is the high computational burden required

    for image processing and its high sensitivity to environmental changes.From a computational perspective, the most efficient way to visually

    28

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    41/60

    CHAPTER 3. Application development 3.5 Sensing component

    detect and follow a path on a surface is to place the image plane parallelto the surface. This way, image processing algorithms are simplied andimage distortions are almost completely removed by design [14]. However,

    such a solution limits the image measurements to a quite small portion of the scene, which is not always practical; therefore some extra processing hasto be performed.

    3.5.1 Image processing algorithm

    A popular technique for a vehicle to localize a line on the oor is by usinga camera mounted on the chassis but not necessarily with its image planeparallel to the surface. This approach, used in this work, requires an imageprocessing algorithm to extract the relevant information from the scene, andan estimation algorithm to estimate the position of the line boundary.

    The applied solution solves both the image processing problem andthe estimation problem simultaneously. It is based on a randomized andcomputationally efficient algorithm developed by members of the group andalready proved to be robust and efficient during several analysis. Moreover,an experimental set-up has been provided and results have been reported in[29]. However, for the sake of completeness, the general idea of the solution

    is briey explained below.The goal is to reconstruct the position and the direction of motion of

    the robot with respect to the centre of a xed line. The approach involvescombining the Inverse Perspective Mapping (IPM) with the RANSAC algo-rithm [13] to estimate the position of the line in a "rectied" image. Thiscombination of techniques is particularly efficient from the software point of view, which makes it suitable for an embedded implementation on low costand compact hardware. However, the approach relies on a perfect knowledgeof the pose of the camera with respect to the ground plane.

    In order to determine the distance from the path and the orientation itis necessary to know the positions of two parallel lines in the image plane.These lines are the borders of the ribbon on the oor. However, even withperfectly planar motion, parallel lines in the 3D space are not mappedinto parallel lines in the image space for the presence of the perspectiveprojection.

    On the other hand, the image processing algorithm would be greatlysimplied if parallelism were preserved in the images, paving the way for the

    application of computationally light and robust algorithms. The idea is thento synthesize an image from actual measures that preserves the quantities of

    29

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    42/60

    3.5 Sensing component CHAPTER 3. Application development

    (a) (b)

    Figure 3.7: Result of the algorithm of rectication on an image capturedfrom the camera.

    interest and, at the same time, the line parallelism. In essence, the originalgrabbed image is rectied to keep lines parallelism across an IPM.

    Figure 3.7 presents an example of the results produced by the recticationalgorithm. It is possible to observe the captured image in the left (a), wherethe two lines are, evidently, not parallel. Nevertheless, once the recticationalgorithm has been applied, a "new" image is obtained where the parallelismis kept.

    Afterwards, the algorithm [14] estimates the actual position and orienta-tion of the camera and provides the information to the control task.

    30

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    43/60

    Chapter 4

    Experiments

    This chapter presents and discusses the results obtained during theexperimental phase with the robot, its controller, and the CPU allocationprocess. Moreover, it contrasts the results obtained experimentally withthose obtained with the analysis tool.

    4.1 Experimental setup

    Figure 4.1: Straight path and initial position of the robot.

    31

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    44/60

    4.2 Evaluation metrics CHAPTER 4. Experiments

    The experimental setup consisted of a camera xed on a static supportplaced on the right side (with respect to the direction of the movement) of the differential drive robot. The camera is facing the oor with a pitch angle

    of 23.5

    .A straight line was placed on the oor, creating a track with a total length

    of 6.5 meters. Note that the presented unicycle model was modelled to dealonly with straight paths. The linear velocity was constant, as mentionedbefore, and set to 0.5 m/s.

    The initial position of the robot, shown in Figure 4.1, was dened as:

    Position: 12 centimeters from the line. This position is considered asthe y component of the position.

    Orientation: 15 degrees with respect to the line. Due to thisconguration, the robot was slightly turned towards the line.

    4.2 Evaluation metrics

    The correctness of the proposed solution will be measured through thefollowing evaluation metrics:

    1. Percentage of cancelled jobs: indicates the percentage of times that a

    job is cancelled because it did not nish within 2 periods of the controltask. It is representative of the violations in the timing constraint;therefore, strongly related to the bandwidth assigned to the imageprocessing task. In the ideal behaviour, it should always remain verysmall; meaning that most of the jobs are able to nish its processing.

    2. Percentage of respected deadlines: denes the percentage of timesthat a job nishes before its deadline. In the ideal behaviour, thispercentage should be very high (around 100%); meaning that the

    deadlines are respected and the jobs nished on time.3. Time spent following the line: represents the total time that the robot

    successfully followed the line on the oor. As mentioned before, forsafety reasons, the robot was monitored through a wireless connection.Under unstable behaviour, the wireless connection facilitates stoppingthe operation of the robot to avoid collisions or any other dangeroussituations.

    This metric is representative of the stability of the system; it depends

    on the velocity of the robot, and, in the ideal behaviour, for a velocityof 0.5 m/s it should be around 12 seconds.

    32

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    45/60

    CHAPTER 4. Experiments 4.3 Experimental results

    4. Root mean square error from the line: shows the estimated errorbetween the reference distance of the robot and the measured one. Itis representative of the accuracy of the controller, and it should be

    very small.

    4.3 Experimental results

    For the experimental phase, 17 different bandwidths were tested. Thesebandwidths ranged from 19 to 35 in steps of 1. For each bandwidth, 10trials were performed. The range of values allows us to observe the twoextreme cases in the evolution of the delays. Namely, the number of delayed

    reservation periods that the image processing task experienced during theexperiments, were measured.The selection of bandwidth values above 35 was not considered, mainly

    because, in those conditions, the assigned bandwidth was more than enoughto satisfy the computation time requirements of the image processing task.In fact, the great majority of the jobs respected its deadline with that amountof CPU utilization.

    The rst interesting result is presented in Figure 4.2, where it is possibleto observe the existing relationship between the percentage of cancelled jobs

    and the bandwidth assigned to the task. If the bandwidth is too low, mostof the jobs will be cancelled, making it more difficult for the control task tostabilize the system. On the other hand, when the bandwidth increases, thepercentage of cancelled jobs decreases drastically. In fact, it is possible tonote that, with more than 30% of the bandwidth, no job is cancelled.

    On contrast, and as expected, the percentage of respected deadlinesincreases with the bandwidth. It was observed that, for bandwidths greaterthan 35%, practically all the jobs respected their deadlines.

    As mentioned before, in a track of length 6.5 meters and moving at aspeed of 0.5 m/s, it was expected that the robot travels lasted 13 seconds.However, due to safety reasons, the execution could be stopped remotely viaa wireless connection with the BeagleBone Black.

    In general, the execution was stopped for two reasons: 1) when therobot was approaching the end of the track; and, 2) when the robot becameunstable creating the risk of crashing against the walls.

    With that in mind, another important result is presented in Figure 4.3.It shows the total time that the robot was able to follow the track as a

    function of the assigned bandwidth. It is possible to observe that, with abandwidth of 21% the robot is still able to follow the track.

    33

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    46/60

    4.3 Experimental results CHAPTER 4. Experiments

    Figure 4.2: Percentage of cancelled jobs vs. deadlines respected for differentvalues of bandwidth.

    This result, when analyzed together with the previous one, shows aninteresting situation. In Figure 4.2, it is possible to determine that, with21% of bandwidth the percentage of respected deadlines is almost zero. Thismeans that, no job was able to nish its processing within a control taskperiod (100 ms). Moreover, almost 60% of the jobs were cancelled; meaning

    that, they were not even able to nish its processing within two control taskperiods (200 ms).However, even with this scarcity of the resource, Figure 4.3 determines

    that with 21% of the bandwidth the robot is still able to complete the path.Evidently, it is logic to assume that the robot could make some mistakes

    along the way. At this point, it is relevant to present a description of theroot mean square error of the robots position with respect to the referencesposition.

    Figure 4.4 reports the root mean square error of the robots position.Note that for low bandwidths ( 19% and 20% ) the error is large. This is moreevident if it is considered the fact that the execution was stopped becauseof instability.

    In the range of interest, for bandwidths greater than 21% , it is possibleto observe that the error is small and tends to decrease until a certainbandwidth. It is worth to point out that for bandwidths greater or equalthat 28% the error was stabilized.

    This is due to the fact that the 97 .80% of the jobs where executed in less

    than 28 ms, as expressed in Figure 4.5 and analyzed in the following section.Therefore, with a bandwidth of 28% , the system is, almost always, operating

    34

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    47/60

    CHAPTER 4. Experiments 4.4 Analysis Tool Results

    Figure 4.3: Total time the robot was able to follow the line for differentvalues of bandwidth.

    in its nominal behaviour where the QoC requirements are respected bydesign.

    4.4 Analysis Tool Results

    As mentioned before, it is of interest for this Thesis to contrast theresults obtained experimentally with those obtained by the analysis tool. Inorder to do that, it is necessary to estimate two parameters from the datacollected during experimentation: the worst case execution time (WCET)of the image processing task and the parameters of the probability densityfunction that best ts the histogram of the computation time.

    In this regard, it is extremely important to characterize the distributionof the computation time in a very precise way.

    4.4.1 Computation time estimation

    The exact measure of the computation time presents some difficulties,mainly because the operating system does not provide an measure of theeffective time a process is using the processor. In general, the time functionsin an operating system include the context switch time and the time usedto serve interrupts.

    Additionally, the use of the resource reservation scheduler, which al-

    lows partitioning the processor time assigned to a task, makes even morecomplicated the estimation of the computation time.

    35

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    48/60

    4.4 Analysis Tool Results CHAPTER 4. Experiments

    Figure 4.4: Root mean square estimation error of the distance from the linefor different values of bandwidth.

    In order to overcome this situation, it is necessary to dene a formulathat calculates the computation time taking into consideration the responsetime given by the operating system (T r ), the reservation period (R i) andthe budget (Q i) from the resource reservation scheduler. The formula thatconsiders all these parameters and produces the estimated computation timeis:

    ci,j =T rR i

    Qi + ( T r mod Ri ) (4.1)

    The rst component represents the time when the task used the wholebudget assigned to it; the second component represents the time used in thelast reservation period (which is smaller than the whole budget).

    Figure 4.5 shows the histogram of the computation time calculated usingthe formula in (4.1). It is assumed that the computation time of a task isindependent of the bandwidth assigned to it. Therefore, this histogram isconstructed considering the computation times of more than 15800 sampledimages with different bandwidths and under different light conditions.

    As stated before, there are two elements that must be extracted fromthis histogram in order to guarantee the accuracy of this work: the WCETand the parameters of the probability density function that best ts thehistogram.

    The WCET obtained during the experiments was 50 ms, expressed asthe maximum value in the histogram. Additionally, the probability density

    function that best t the obtained histogram was the beta distribution. InFigure 4.6, the estimated distribution is shows, characterized by the following

    36

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    49/60

    CHAPTER 4. Experiments 4.4 Analysis Tool Results

    Figure 4.5: Histogram of the computation time.

    parameters: = 27.3905 and = 34.8936.

    Figure 4.6: Probability distribution of the computation time.

    Now it is possible to simulate the behaviour of a control task with theparameters just obtained.

    4.4.2 Minimum bandwidth estimation

    As mentioned before, the EECS research group has developed an anal-ysis tool which takes as input: the characterization of the controller, theparameters of the scheduling algorithm, and the parameters of the prob-ability density function previously obtained. With this information, the

    simulation is able to determine the minimum bandwidth to sustain the QoC specication.

    37

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    50/60

    4.5 Additional results in curved paths CHAPTER 4. Experiments

    Figure 4.7 presents the simulation results based on the data obtainedfrom the performed experiments. It is possible to observe that, according tothe simulation, the image processing task has to receive the 23% of CPU

    utilisation in order to respect the control requirements.

    Figure 4.7: Minimum bandwidth that guarantees the QoC specications.

    The result of the analysis tool is quite comparable with the result obtainedexperimentally. In the experimental phase it was possible to claim that, withthe 21% of the bandwidth, the controller was able to stabilize the robot. Thesimulations expressed that the minimum bandwidth that should be assignedto the image processing task to guarantee the stability of the system was23%.

    Additionally, it is worth to mention that there were also performed

    experiments with a linear velocity of 0

    .8

    m/s. However, the obtained resultswere very similar to the ones obtained with 0.5 m/s.

    4.5 Additional results in curved paths

    Finally, there was performed an additional experiment considering alsoa curved path. As mentioned initially, the controller was designed for astraight path with no change on the geometry of the trajectory. In order toproperly adopt a curved path in the experiments, the dynamics of the modelshould change to take into consideration the curvature of the trajectory.

    Nevertheless, in this nal experiment, the model was kept as in a straightpath, but the trajectory was changed. It was of interest, to experimentallyverify the behaviour of the controller, even under this mismatch conditions.It was also useful to determine the minimum bandwidth that ensures thestability of the system.

    Given that the path to be followed changed, its total length changed.The new distance to be cover was of 8.5 meters, and included a relatively

    wide curve at the beginning and a sharp one at the end. Figure 4.8 showsthe modied path. Additionally, there was a slightly variation in the initial

    38

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    51/60

    CHAPTER 4. Experiments 4.5 Additional results in curved paths

    position of the robot. It was placed 2 centimeters from the line with anorientation of 2 degrees with respect to the line.

    Figure 4.8: Curved path and initial position of the robot.

    The experiments consist of 11 different bandwidths ranging from 20 to40 in steps of 2. For each bandwidth, 10 trials were performed. The selectedrange was a bit higher because of the difficulties introduced in the curvedpath, that had not been observed in the previous experiments.

    In general, the results were very interesting. Regarding the stability of the system, Figure 4.9 shows that it was necessary a bandwidth of 28% tosuccessfully complete the path. When assigned smaller values the stabilityof the system was not always guaranteed. The problem was presented whentaking the last curve because of its very aggressive nature.

    It is important to point out that the root mean square error of the robotsposition with respect to the references position, in Figure 4.10, seems tobe smaller in the case of curved paths. It must be noticed that the initial

    conditions were completely different in this situation (mainly favourable forthe robot), causing these small values.

    39

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    52/60

    4.5 Additional results in curved paths CHAPTER 4. Experiments

    Figure 4.9: Total time the robot is able to follow the line on a curved path,for different values of bandwidth.

    Once again, the results show that the error decreases consistently untilreaching a stabilization point (around 30% of the bandwidth). The errorwas actually very similar to the value observed in the case of straight paths(around 0.05 cm).

    Finally, the relationship existing between the percentage of cancelled jobs and the bandwidth assigned to the task presents the same trend as inthe previous case. Figure 4.11 shows the respective results.

    The main difference with respect to the straight path result is given bythe fact that, in order to reach a 100% of respected deadlines, it is necessaryto assign the 40% of the bandwidth. Similarly, the 0% of cancelled jobs isonly reached with a bandwidth of 34% . These two values are slightly greaterthan in the straight path case.

    A nal, yet important, remark is that in this additional experiments, theresults of the analysis tool were not considered. As previously mentioned,

    the analysis tool needs, as part of its inputs, the mathematical model of therobot and the characterization of the controller. Both of these factors weredesigned for a straight path. Using them in a mismatch condition would beincorrect.

    40

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    53/60

    CHAPTER 4. Experiments 4.5 Additional results in curved paths

    Figure 4.10: Root mean square estimation error of the distance from theline for different values of bandwidth on a curved path.

    Figure 4.11: Percentage of cancelled jobs vs. deadlines respected for differentvalues of bandwidth on a curved path.

    41

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    54/60

    4.5 Additional results in curved paths CHAPTER 4. Experiments

    42

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    55/60

    Chapter 5

    Conclusions

    This Masters Thesis presented the implementation of a model of compu-tation, called Soft Real-Time Time-Triggered, for real-time tasks, runningon a shared CPU with highly varying computation times, within a roboticcontrol scenario. Additionally, it was implemented a feedback control loop ona path following robot. This solution allowed to determine, experimentally,the minimum CPU utilisation for the image processing task while satisfyingthe QoC requirements (stability of the system).

    The implemented Soft Real-Time Time-Triggered Model of Computation

    is more exible in managing the delays than the classical Time-Triggeredmodel. It tolerates delays and allows the system to operate with "fresh"data; however the analysis is difficult because it is necessary to deal withtwo interacting dynamical systems: one given by the controlled system andthe other one given by the evolution of the delays. Moreover, it is importantto point out that performing such analysis will only produce a sufficientcondition for stability.

    Additionally, the minimum CPU utilisation which was experimentallymeasured, was contrasted with the results achieved through an analysis tool.This tool, starting from the designed control law and from the stochasticdescription of the computation time, derives a scheduling policy that allowsus to attain stability for the system and to minimize the consumption of computation resources. It is very interesting to note that, in both conditions:experiments and simulations, a similar performance was observed.

    The high similarity between the obtained results veries the correctnessof the analysis tool, and reinforces its applicability for soft real-time taskscheduling in a control scenario. This tool could be exploited as a preliminary

    analysis, allowing the nal system to efficiently share its resources. Thisresults into an enhanced system utilisation, and increment in the number of

    43

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    56/60

    CHAPTER 5. Conclusions

    applications that could be executed in the same ECU.Furthermore, the experiments carried out in a curved path showed

    promising results. Although the used model was not entirely suitable for

    this analysis, it was possible to experimentally determine the minimumutilization resource in order to guarantee the stability of the system. Thereare great expectations that, when applying the matching model, the resultswill be more than satisfactory.

    The obtained results allow us to claim that the hard real-time schedulingcan be effectively replaced for the implementation of feedback control sys-tems. The new strategies based on soft real-time scheduling offer importantadvantages, minimizing the utilization of the resources and guaranteeing theperformance of the control tasks.

    44

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    57/60

    Bibliography

    [1] Luca Abeni and Giorgio Buttazzo. Integrating multimedia applica-tions in hard real-time systems. In: Real-Time Systems Symposium,1998. Proceedings., The 19th IEEE . IEEE. 1998, pp. 413.

    [2] A Pedro Aguiar and Joo P Hespanha. Trajectory-tracking andpath-following of underactuated autonomous vehicles with parametricmodeling uncertainty. In: Automatic Control, IEEE Transactions on 52.8 (2007), pp. 13621379.

    [3] Neculai Andrei. Modern Control Theory. In: Studies in Informatics and Control 15.1 (2006), p. 51.

    [4] Gary Bradski and Adrian Kaehler. Learning OpenCV: Computer vision with the OpenCV library . OReilly Media, Inc., 2008.

    [5] Giorgio C Buttazzo. Hard real-time computing systems: predictable scheduling algorithms and applications . Vol. 24. Springer, 2011.

    [6] Giorgio Buttazzo, Manel Velasco, and Pau Marti. Quality-of-controlmanagement in overloaded real-time systems. In: Computers, IEEE Transactions on 56.2 (2007), pp. 253266.

    [7] Anton Cervin et al. How does control timing affect performance? In:IEEE control systems magazine 23.3 (2003), pp. 1630.

    [8] Thidapat Chantem, Xiaobo Sharon Hu, and Michael D Lemmon.Generalized elastic scheduling for real-time tasks. In: Computers,IEEE Transactions on 58.4 (2009), pp. 480495.

    [9] Gerald Coley. BeagleBone Black System Reference Manual . 2013.

    [10] Steve Corrigan. Introduction to the controller area network (CAN).In: Application Report, Texas Instruments (2002).

    [11] John C Doyle, Bruce A Francis, and Allen R Tannenbaum. Feedback control theory . Courier Dover Publications, 2013.

    45

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    58/60

    BIBLIOGRAPHY BIBLIOGRAPHY

    [12] Dario Faggioli et al. An implementation of the earliest deadline rstalgorithm in linux. In: Proceedings of the 2009 ACM symposium on Applied Computing . ACM. 2009, pp. 19841989.

    [13] Martin A Fischler and Robert C Bolles. Random sample consensus:a paradigm for model tting with applications to image analysis andautomated cartography. In: Communications of the ACM 24.6 (1981),pp. 381395.

    [14] D Fontanelli, M Cappelletti, and D Macii. A RANSAC-based fastroad line detection algorithm for high-speed wheeled vehicles. In:Instrumentation and Measurement Technology Conference (I2MTC),2011 IEEE . IEEE. 2011, pp. 16.

    [15] Daniele Fontanelli, Luca Greco, and Luigi Palopoli. Soft real-timescheduling for embedded control systems. In: Automatica 49.8 (2013),pp. 23302338.

    [16] Daniele Fontantelli, Luigi Palopoli, and Luca Greco. Optimal CPUallocation to a set of control tasks with soft realtime execution con-straints. In: Proceedings of the 16th international conference on Hybrid systems: computation and control . ACM. 2013, pp. 233242.

    [17] Chunzhao Guo, Seiichi Mita, and David McAllester. Lane detectionand tracking in challenging environments based on a weighted graphand integrated cues. In: Intelligent Robots and Systems (IROS), 2010 IEEE/RSJ International Conference on . IEEE. 2010, pp. 55435550.

    [18] Christopher Hallinan. Embedded Linux primer: a practical, real-world approach . Pearson Education India, 2007.

    [19] Joo P Hespanha. Linear systems theory . Princeton university press,2009.

    [20] Willie D Jones. Building safer cars. In: Spectrum, IEEE 39.1 (2002),pp. 8285.

    [21] Chung-Yao Kao and Anders Rantzer. Stability analysis of systemswith uncertain time-varying delays. In: Automatica 43.6 (2007),pp. 959970.

    [22] Hermann Kopetz and Gnther Bauer. The time-triggered architec-ture. In: Proceedings of the IEEE 91.1 (2003), pp. 112126.

    46

  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    59/60

    BIBLIOGRAPHY BIBLIOGRAPHY

    [23] Giuseppe Lipari and Sanjoy Baruah. Greedy reclamation of unusedbandwidth in constant-bandwidth servers. In: Real-Time Systems,2000. Euromicro RTS 2000. 12th Euromicro Conference on . IEEE.

    2000, pp. 193200.[24] Chung Laung Liu and James W Layland. Scheduling algorithms for

    multiprogramming in a hard-real-time environment. In: Journal of the ACM (JACM) 20.1 (1973), pp. 4661.

    [25] Fan Liu, Ajit Narayanan, and Quan Bai. Real-time systems. In:(2000).

    [26] Pau Marti et al. Jitter compensation for real-time control systems.In: Real-Time Systems Symposium, 2001.(RTSS 2001). Proceedings.22nd IEEE . IEEE. 2001, pp. 3948.

    [27] Clifford W Mercer, Stefan Savage, and Hideyuki Tokuda. Processor capacity reserves for multimedia operating systems . Tech. rep. DTICDocument, 1993.

    [28] Alain Micaelli, Claude Samson, et al. Trajectory tracking for unicycle-type and two-steering-wheels mobile robots. In: (1993).

    [29] F Moro, D Fontanelli, and L Palopoli. Vision-based robust localiza-tion for vehicles. In: Instrumentation and Measurement Technology Conference (I2MTC), 2012 IEEE International . IEEE. 2012, pp. 553558.

    [30] Angelo Morro, Antonio Sgorbissa, and Renato Zaccaria. Path follow-ing for unicycle robots with an arbitrary path curvature. In: Robotics,IEEE Transactions on 27.5 (2011), pp. 10161023.

    [31] Robert Nelson. BeagleBone Black - Linux on ARM - eewiki . [This pagewas last modied on 2 January 2014]. 2014. url : http://eewiki.net/display/linuxonarm/BeagleBone+Black .

    [32] Johan Nilsson, Bo Bernhardsson, et al. Analysis of real-time controlsystems with time delays. In: IEEE CONFERENCE ON DECISION AND CONTROL . Vol. 3. INSTITUTE OF ELECTRICAL ENGI-NEERS INC (IEE). 1996, pp. 31733172.

    [33] David Nistr. Preemptive RANSAC for live structure and motionestimation. In: Machine Vision and Applications 16.5 (2005), pp. 321329.

    47

    http://eewiki.net/display/linuxonarm/BeagleBone+Blackhttp://eewiki.net/display/linuxonarm/BeagleBone+Blackhttp://eewiki.net/display/linuxonarm/BeagleBone+Blackhttp://eewiki.net/display/linuxonarm/BeagleBone+Blackhttp://eewiki.net/display/linuxonarm/BeagleBone+Black
  • 8/10/2019 Soft Real-Time Scheduling for Embedded Control System

    60/60

    BIBLIOGRAPHY BIBLIOGRAPHY

    [34] Ragunathan Rajkumar et al. Resource kernels: A resource-centricapproach to real-time and multimedia systems. In: Photonics West98 Electronic Imaging . International Society for Optics and Photonics.

    1997, pp. 150164.[35] Claude Samson and K Ait-Abderrahim. Feedback control of a nonholo-

    nomic wheeled cart in cartesian space. In: Robotics and Automation,1991. Proceedings., 1991 IEEE International Conference on . IEEE.1991, pp. 11361141.

    [36] Roland Siegwart, Illah Reza Nourbakhsh, and Davide Scaramuzza.Introduction to autonomous mobile robots . MIT press, 2011.

    [37] Akihiro Tsukada, Masahiro Ogawa, and Franck Galpin. Road struc-ture based scene understanding for intelligent vehicle systems. In:Intelligent Robots and Systems (IROS), 2010 IEEE/RSJ International Conference on . IEEE. 2010, pp. 55575562.