Multi-agent Vehicle Communication for Destination Decision

This project consists of two vehicles that want to meet in a desired target. Each vehicle measures the position of the target and exchange this information between them through a network. From the average of both measurements, each vehicle decides the direction that it should go to reach the target. To make the problem more interesting we decided to make the target a moving vehicle which we could set the trajectory and, consequently, both vehicles should be able to follow it, as shown on the Figure 1.

Untitled1

Figure 1. High level description of the system.

This system is considered a cyber-physical system, since it is comprised of physical systems, the dynamics of the vehicles, and cyber systems, the finite state machines responsible for computing the direction based on the acquired target measurements. This system has to take in consideration the sampling rate of each vehicle and the random transmission delay generated by the network.

Project Documentation

Matlab Implementation (Change the extension to .zip)

 

Advertisements

Synchronization of [power-conversion related] oscillators over the network: hybrid system approach

Renewable energy sources are undergoing intense study these days. According to Renewables 2015 Global Status Report, “by 2013, the most year for which data are available, renewable energy provided an estimated 19.1% of global final energy consumption.” This trend is constantly increasing every year. The most common renewable energy sources are photovoltaic panels, fuel cells, and speed wind turbines. To increase the efficiency and reliability of the supplied power, all of the sources might be interconnected to supply power to the single load. Moreover, the sources might be distributed. This, in turn, raises necessity in communication channels between the power generators to increase the efficiency of the overall system.

Figure 1 shows a simple example of interconnection of many DC/AC inverters. This kind of interconnection is typical in distributed power generation with photovoltaic panels. The panels generate DC voltage, and it must be converted to AC. All of the inverters are hooked to a single load to increase overall power. However, a significant amount of efficiency loss is introduced if generated AC voltages by each of the inverters are off-phase.

Figure 1 – interconnection of many DC/AC inverters

This project addresses an issue of unsynchronized power generators and proposes a solution. The interconnection was modeled as a cyber-physical system and was described by the difference and differential equations. The correctness of the proposed solution is based on the MATLAB simulation of the model. The simulation results are available in Results section.

Hybrid Model of Platoon Formation

In course of a examination project for EECI course “Analysis and Design of Hybrid Control Systems”, this project has been conducted. The formation of platoons into a hybrid system is modelled as a hybrid system. You can find the full project report here:

Hybrid Model of Platoon Formation

Below, you can find the simulation code for the multi agent case.

function [value discrete] = C(x) 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Matlab M-file                
%
% Description: Flow set
% Return 0 if outside of C, and 1 if inside C
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
K = round(length(x)/3);

d = x(1:K);
u = x(K+1:2*K);
p = x(2*K+1:3*K);

value = 0;
for i = 1:K-1
    if d(i+1) = d(i)
        if p(i+1) ~= p(i)
            inside = 1;
        end
    end
end

end

function inside = D(x) 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Matlab M-file                
%
% Description: Jump set
% Return 0 if outside of D, and 1 if inside D
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
K = round(length(x)/3);

d = x(1:K);
u = x(K+1:2*K);
p = x(2*K+1:3*K);

inside = 0;

for i = 1:K-1
    if d(i+1) >= d(i)
        if p(i+1) ~= p(i)
            inside = 1;
        end
    end
end
end


function xdot = f(x)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Matlab M-file              
%
% Description: Flow map
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
% state
K = round(length(x)/3);

d = x(1:K);
u = x(K+1:2*K);
p = x(2*K+1:3*K);

% differential equations
xdot = [u;zeros(2*K,1)];
end


function xplus = g(x)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Matlab M-file               
%
% Description: Jump map
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% state
K = round(length(x)/3);

d = x(1:K);
u = x(K+1:2*K);
p = x(2*K+1:3*K);

u_min = 10;
u_max = 20;

% decide whether u_min or u_max will be used in the set valued case
r = rand(1);
if r > 0.5
    bar_u = u_max;
else
    bar_u = u_min;
end

% search for the platoons that caused the jump
for i = 1:K-1
    if d(i+1) >= d(i)
        if p(i+1) ~= p(i)
            break;
        end
    end
end
% find all agents in these platoons
N = find(p == p(i+1) | p == p(i));
p(N) = p(i);
first_agent = sum(N == 1);
last_agent = sum(N == K);
if first_agent && last_agent || ~first_agent && ~last_agent % we're in the middel or one platoon
    u(N) = bar_u;
elseif first_agent && ~last_agent % that's the first platoon
    u(N) = u_min;
elseif ~first_agent && last_agent % that's the las tplatoon
    u(N) = u_max;
end
% the adjustment in order to end up in the flow set after the jump
d(N) = d(N(1));
xplus = [d;u;p];
end


clear all

% function run

u_min = 10;
u_max = 20;

K = 9;

% initial conditions
d = cumsum(rand(1,K))*5;
d = d(K:-1:1);
d = d.';
u(1) = u_min;
des = rand(1,K-2);
u(2:K-1) = u_min*(des > 0.5) + u_max*(des  priority for jumps
% rule = 2 -> priority for flows
rule = 1;

options = odeset('RelTol',1e-6,'MaxStep',.1);

maxStepCoefficient = .1;  % set the maximum step length. At each run of the
                   % integrator the option 'MaxStep' is set to 
                   % (time length of last integration)*maxStepCoefficient.
                   %  Default value = 0.1

% simulate
[t x j] = HyEQsolver( @f,@g,@C,@D,x0,TSPAN,JSPAN,rule,options,maxStepCoefficient);

% plot solution
figure;
subplot(2,1,1)
plot(t,x(:,1:K));
grid on;
% legend('d'interpreter','tex');
ylabel('$d_i$','interpreter','latex');
xlabel('time');
subplot(2,1,2);
plot(t,x(:,2*K+1:end));
xlabel('time');
ylabel('$p_i$','interpreter','latex');
ylim([0,K+1]);

Cyclic redundancy check in HyEQ V2.01 installation

Regarding the release of the HyEQ toolbox V2.01, some users found a glitch when installing the new version into an iMac computer. The error is the following,

>> install
———————————–
 INSTALLATION HyEQ_Toolbox_V2_01
———————————–
 Reading the archiv
—————————-
      ERROR OCCURED
   during installation
—————————-
Error using install (line 80)
The installation file is corrupt!
Ensure that the archive container was not modified (check FTP/
proxy/ firewall settings, anti-virus scanner for emails etc.)!

Thus, to solve this problem and install the toolbox, it is necessary that the user create its own install file in her/his computer. Here are the steps how to create and install the installation file.

  1. You need to know which is your matlab’s user userpath folder, for this, type in your matlab’s command window >>userpath
  2. Download the makeinstall program at http://www.mathworks.com/matlabcentral/fileexchange/1529-makeinstall and uncompress the content in your userpath folder.
  3. Locate and open the makeinstall folder in matlab. Run the script >> makeinstall, and then install the makeinstall program, typing >> install. Now you can create your own install files!
  4. Download the HyEQ V2.01 source files here (please change the .doc extension by .zip)
  5. Uncompress the file and copy the folder in any place but your userpath folder.
  6. Locate the folder in matlab, and then create the install file typing >> makeinstall. Thus, if you didn’t get any error, you can install the HyEQ toolbox V2.01 typing >> install.
  7. Follow the instructions for the installation.

I hope this is usefull for those who found the error, please if you have questions leave a comment, and I’ll try to help you.

Best,

Pablo.

PD: Thanks Sean and Yuchun for all your help.

Pendulum Example for Hybrid Equations Toolbox

Instruction to simulate pendulum example are in the following video:

Notice that this example uses the simulink HyEQ simulator. Thus, you may create the files from scratch, or download the files here. Please, change the extension of the downloaded file from -zip.doc to .zip, then you can unzip and browse the files for the example.
Code for simulations
Flow map: f.m

function xdot = f(x)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Matlab M-file       Project: HyEQ Toolbox  @ Hybrid Dynamics and Control
% Lab, http://www.u.arizona.edu/~sricardo/index.php?n=Main.Software
%
% Project: Simulation of a hybrid system
%
% Name: f.m
%
% Description: Flow map
%
% Version: 1.0
% Required files: - 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% flow map: xdot=f(x,u,parameters);

x1=x(1);
x2=x(2);

length=1;
gamma=-9.81;
xdot=[x(2);gamma/length*sin(x(1))];

Flow set: C.m

function v  = C(x) 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Matlab M-file       Project: HyEQ Toolbox  @ Hybrid Dynamics and Control
% Lab, http://www.u.arizona.edu/~sricardo/index.php?n=Main.Software
%
% Project: Simulation of a hybrid system
%
% Name: C.m
%
% Description: Flow set
%
% Version: 1.0
% Required files: - 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Check on flow conditions
% E.g.,
% if (x(1) >= u(1))  % flow condition
%     v = 1;  % report flow
% else
%     v = 0;   % do not report flow
% end

x1=x(1);
x2=x(2);

if x1 >= 0;
    v = 1;
else
    v=0;
end

Jump map: g.m

function xplus = g(x)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Matlab M-file       Project: HyEQ Toolbox  @ Hybrid Dynamics and Control
% Lab, http://www.u.arizona.edu/~sricardo/index.php?n=Main.Software
%
% Project: Simulation of a hybrid system
%
% Name: g.m
%
% Description: Jump map
%
% Version: 1.0
% Required files: - 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% jump map: xplus = g(x,u,parameters);

x2=x(2);

xplus = [0.001;-.8*x2];

Jump set: D.m

function v  = D(x) 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Matlab M-file       Project: HyEQ Toolbox  @ Hybrid Dynamics and Control
% Lab, http://www.u.arizona.edu/~sricardo/index.php?n=Main.Software
%
% Project: Simulation of a hybrid system
%
% Name: D.m
%
% Description: Jump set
%
% Version: 1.0
% Required files: - 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Check on flow conditions
% % E.g.,
% if (x(1) <= u(1)) && (x(2) <= 0)  % jump condition
%     v = 1;  % report jump
% else
%     v = 0;   % do not report jump
% end

x1=x(1);
x2=x(2);

if x1 <= 0 && x2 <= 0
    v=1;
else
    v = 0;
end

Initialization script: initialization_pendulum.m

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Matlab M-file       Project: HyEQ Toolbox  @ Hybrid Dynamics and Control
% Lab, http://www.u.arizona.edu/~sricardo/index.php?n=Main.Software
%
% Filename: initialization.m
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% initialization for bouncing ball example

% clear all                                                               
clc                                                                       
% initial conditions                                                    
x0 = [pi/4;0];                                                                                                                
          
% physical variables
global gamma lambda
gamma = -9.81;  % gravity constant
lambda = 0.8;   % restitution coefficent

% simulation horizon                                                    
T = 10;                                                                 
J = 20;                                                                 
                                                                        
% rule for jumps                                                        
% rule = 1 -> priority for jumps                                        
% rule = 2 -> priority for flows                                        
% rule = 3 -> no priority, random selection when simultaneous conditions
rule = 1;                                                               
                                                                        
%solver tolerances
RelTol = 1e-6;
MaxStep = 1e-3;

Plot script: postprocessing_pendulum.m

%postprocessing for the bouncing ball example


% plot solution                
figure(1) 
clf
subplot(2,1,1),plotflows(t,j,x(:,1))
grid on                        
ylabel('x1')                    
                               
subplot(2,1,2),plotjumps(t,j,x(:,1))
grid on                        
ylabel('x1')                    
      
figure(2)  
clf
subplot(2,1,1),plotflows(t,j,x(:,2))
grid on                        
ylabel('x2')                    
                               
subplot(2,1,2),plotjumps(t,j,x(:,2))
grid on                        
ylabel('x2') 

% plot hybrid arc              
plotHybridArc(t,j,x(:,1))           
xlabel('j')                    
ylabel('t')                    
zlabel('x1')                    

Updating to mac OSX 10.9 (Mavericks) and Matlab 2013b and the required “fixes” for the HyEQ simulator.

I just updated my OSX to Mavericks 10.9 and Matlab 2013b, and I had some issues trying to use the HyEQ simulator. I just want to share how I fix a couple of problems in the case that anyone has the same issues.

The steps that I suggested to update the system are the following:

    1. Update to Mavericks.
    2. Update Xcode to the newest version (I have 5.0.1).
    3. Update or install Matlab 2013b.
    4. Open Matlab, if you having warnings such as “Warning: Name is nonexistent or not a directory”, please fix those warnings following the steps in: http://www.mathworks.com/support/solutions/en/data/1-1BUE0/?product=ML
    5. Setup the C-compiler in matlab following the steps in the instructions (in the HyEQ instructions file).

    6. Download and install the HyEQ simulator from: http://www.mathworks.com/matlabcentral/fileexchange/41372-hybrid-equations-toolbox-v2-0
    7. Open Simulink and try to run an example:

      it worked? yes = you are done :), no= continue with step 8 :S

    8. If you get the following error “xcodebuild: error: SDK “macosx10.7” you need to change some lines in your file “mexopts.sh”, follow the instructions in http://www.mathworks.com/support/solutions/en/data/1-OAMYBZ/ or http://www.cyberbotics.com/forum?message=2406
    9. In the Matlab’s command prompt >> mex -setup, and follow the steps in the instructions file.

    10. Reboot matlab and try again 7.
    • it worked? yes = you are wellcome 🙂
    • no= sorry 😦

I hope this could be useful for someone, (now my Maverics+Matlab2013b+HyEQ simulator is working)