help me....matlab very difficult...

hello hi i'm korean student.. I want to do a spray drones simulation through MATLAB. I do not know how to represent a map when I want to represent cropland on MATLAB (ex. 100 * 100 ...) And if you pass that part in the original form, you try to express it by adding one cell to +1. This is a difficult situation because there is no example.

 Risposta accettata

Walter Roberson
Walter Roberson il 21 Apr 2018

2 voti

Create a 100 by 100 numeric matrix, M. Put -1 into the locations that are not cropland.
As you simulate the flying drone, if you are at location (J, K) test M(J, K) >= 0 & M(J, K) < maximum spray. If the test is satisfied then M(J, K) =M(J, K) +1 and reduce the amount of chemical stored on the drone.
Also at each step reduce the stored fuel by an amount that depends on the remaining amount of chemical, because fuel consumption decreases as the drone gets lighter.
This does not assume that each location is to be sprayed only once but it does assume that there is a maximum amount to spray for any location.

4 Commenti

jongju an
jongju an il 21 Apr 2018
Thank you your answer
but I have never used MATLAB before, so I am having difficulty implementing it.
I am really sorry, but I would really appreciate it if you could give me a rough code.
maxspray = 2;
fuel = 20;
chemsupply = 6;
N = 5;
M = [ 0 -1 -1  0 -1;
     -1  0  -1 0 -1;
     -1  0   0 0  0;
     -1  0  -1 -1 -1
      0  0   0 -1  0;
    ];
I = 1; J = 1;
while fuel > 0 && chemsupply > 0
  if chemsupply > 0 && M(I,J) >= 0 && M(I,J) <= maxspray
    M(I,J) = M(I,J) + 1;
    chemsupply = chemsupply - 1;
  end
  fuel = fuel - 1 - chemsupply*0.1;
  I = min(max(I + randi([-1 1]), 1),N);
  J = min(max(J + randi([-1 1]), 1),N);
end
fprintf('Drone ended at (%d,%d)\n', I, J);
if fuel > 0 & chemsupply <= 0
  fprintf('ran out of spray before we ran out of fuel\n');
elseif fuel <= 0 & chemsupply > 0
  fprintf('ran out of fuel before we ran out of spray\n');
else
 fprintf('ran out of fuel and spray at the same time\n');
end
fprintf('Final map:\n')
disp(M);
jongju an
jongju an il 21 Apr 2018
Thank you so much. I wonder that the spraying range is scattered widely in elliptical form. We have to +1 the part of the range in the matrix. Drone is move in this way [1,1]> [2,1]> [3,1]........[n,n] (ㄹ form) So I'm wondering about the code that increases the elements of a matrix that belongs to an ellipse. You are really helping me.

The position moved to is controlled by the lines

I = min(max(I + randi([-1 1]), 1),N);
J = min(max(J + randi([-1 1]), 1),N);

At present this is done by moving to a random adjacent location (it can also end up staying in the same place, especially if it would go outside of the map.) You can change the code to follow any pattern you want.

You will need to enhance the simulation by having the drone notice when it is getting low on fuel and having it fly back for refueling.

Then, once it refuels, if it just flies the same pattern again then it will run out of fuel even sooner (because it will be dropping less spray on the places that already have enough, so it will be flying heavier than on the original pass.)

So your code should be doing path planning.

Simple example: when the drone is getting low on fuel, then flying directly back might take it back over places that have already been sprayed enough. But if the drone moves over to the next row or column and follows that back, perhaps it will encounter fewer places that have already been done. On the other hand, if the drone runs out of spray then it should fly the most fuel-efficient route back to refill. This should be part of your calculations, not just choosing a good "starting" point but also how it is eventually going to get back.

Accedi per commentare.

Più risposte (0)

Categorie

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by