Matlabscript DroneCamera: Difference between revisions

From Control Systems Technology Group
Jump to navigation Jump to search
No edit summary
No edit summary
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
Hieronder staat de Matlab-code voor de lokale camera. Comments over gebruikte code staan in het script erbij vermeldt.
<code  style="font-size:18px">
<code  style="font-size:18px">


function dronecamdata(drone, Xball_l,Yball_l, Diam)
function dronecamdata(drone, Xball_l,Yball_l, Diam)
     % Dronecamdata is a function that interprets the output data from the  
     % Dronecamdata is a function that interprets the output data from the  
     % video analysis and converts it to the drone's movement
     % video analysis and converts it to the drone's movement
  .
  <br>
     if (Xball_l == 0 && Yball_l == 0)  
     if (Xball_l == 0 && Yball_l == 0)  
       % do nothing if ball is undetected
       % do nothing if ball is undetected
Line 15: Line 16:
     x_l_target = Xball_l - Xref;   
     x_l_target = Xball_l - Xref;   
     y_l_target = Yball_l - Yref;
     y_l_target = Yball_l - Yref;
  .
  <br>
     %% Calling upon the drone's drive function
     %% Calling upon the drone's drive function
  .
  <br>
         rSpeed  = 0; %right/left turn speed
         rSpeed  = 0; %right/left turn speed
         revSpeed = 0; %reverse/forward speed
         revSpeed = 0; %reverse/forward speed
  .
  <br>
     % a quadratic correlation is used to reposition the drone.
     % a quadratic correlation is used to reposition the drone.
     % the further the distance from the reference line, the faster it moves
     % the further the distance from the reference line, the faster it moves
  .
  <br>
         if x_l_target > 0
         if x_l_target > 0
             rSpeed =  (0.000015*(x_l_target)^2);   
             rSpeed =  (0.000015*(x_l_target)^2);   
Line 31: Line 32:
             disp('turning left')
             disp('turning left')
         end
         end
  .
  <br>
     % to ensure the right distance, the drone has to get the diameter of the
     % to ensure the right distance, the drone has to get the diameter of the
     % ball to be between a certain range, otherwise act as necessary
     % ball to be between a certain range, otherwise act as necessary
Line 41: Line 42:
         end
         end
     end
     end
  .
  <br>
         drone.drive([revSpeed, 0, 0, rSpeed ]);
         drone.drive([revSpeed, 0, 0, rSpeed ]);
     end
     end
end
end
</code>
</code>
linkje Matlabscript: [https://www.dropbox.com/sh/gbh5m6odnoqne99/AABFMLRutZ_o2IONJv1cpYDWa?dl=0 All-Project Matlab Files]
----
Terug naar: [[Control]]

Latest revision as of 00:13, 14 January 2016

Hieronder staat de Matlab-code voor de lokale camera. Comments over gebruikte code staan in het script erbij vermeldt.

function dronecamdata(drone, Xball_l,Yball_l, Diam)
   % Dronecamdata is a function that interprets the output data from the 
   % video analysis and converts it to the drone's movement

if (Xball_l == 0 && Yball_l == 0)  % do nothing if ball is undetected drone.drive([0,0,0,0]); else Xref = 640/2;  % middle of the screen Yref = 0; Diamref_min = 70; Diamref_max = 90; x_l_target = Xball_l - Xref; y_l_target = Yball_l - Yref;
 %% Calling upon the drone's drive function
rSpeed = 0; %right/left turn speed revSpeed = 0; %reverse/forward speed
 % a quadratic correlation is used to reposition the drone.  % the further the distance from the reference line, the faster it moves
if x_l_target > 0 rSpeed = (0.000015*(x_l_target)^2); disp('turning right') elseif x_l_target < 0 rSpeed = - (0.000015*(x_l_target)^2); disp('turning left') end
 % to ensure the right distance, the drone has to get the diameter of the  % ball to be between a certain range, otherwise act as necessary if 1 if Diam > Diamref_max; revSpeed = max(0.0003*(Diam-Diamref_max)^2,0.3); %backwards elseif Diam < Diamref_min revSpeed = - max(0.0003*(Diam-Diamref_min)^2,0.3); %forward end end
drone.drive([revSpeed, 0, 0, rSpeed ]); end end

linkje Matlabscript: All-Project Matlab Files


Terug naar: Control