Simulating a robotic action
1 view (last 30 days)
Show older comments
I am doing a simple simulation. I have three stages a robot can be 'Search','Assess' or 'Recruit'. If the robot is in any of these stages there are certain actions to be performed. If the robot finished 'Search', it should go to 'Assess'. If it finished 'Assess', then it should go to 'Recruit'. When the robot reached the stage 'Recruit', the initial population of robots should reduced by 1. When i am trying to run the code, its not stopping. Any help to solve this will be appreciated.
for_distribution = @(mean_time) log(1/(1-rand))/mean_time;
current_time = 0;
counter = 1;
state ='search';
mean_search_duration = 1998.849773195878;
mean_assessment_duration = [93.63,99.050];
mean_recruitment_duration = 136.756;
mean_threshold_time_to_pick_nest = [1309.01,1905.4];
while true
switch state
case 'search'
t = for_distribution(mean_search_duration);
current_time(counter+1) = current_time(counter) + t; %#ok<SAGROW>
state = 'assessing';
case 'assessing'
t = for_distribution(mean_assessment_duration(1));
current_time(counter+1) = current_time(counter) + t; %#ok<SAGROW>
if current_time > mean_time_to_pick_nest(1)
state = 'recruiting';
else
state = 'search';
end
case 'recruiting'
t = for_distribution(mean_recruitment_duration);
current_time(counter+1) = current_time(counter) + t; %#ok<SAGROW>
number_of_robots_in_nest_initial(current_time(counter+1)) = number_of_robots_in_nest_initial(current_time(counter)) - 1;
if number_of_robots_in_nest_initial(current_time) == 0
break
end
end
counter = counter+1;
end
0 Comments
Answers (1)
Cam Salzberger
on 30 Oct 2018
Hello Hari,
I would highly suggest putting a breakpoint into the loop, and checking the values for your various variables at each timestep to make sure they are updating correctly. You can narrow down on the problem, and change the condition on the breakpoint so that it only stops on certain situations if you want a more advanced maneuver.
From looking at the code though, I can see a few potential issues. One is that your only possible way to get out of the loop is by hitting a breakpoint in a conditional. So clearly the conditional is never true. I suspect you need to index into current_time like you do everywhere else, otherwise number_of_robots_in_nest_initial(current_time) is probably an array. I also suspect that there are better ways of storing information than indexing an array by a time array indexed by a counter. Doesn't make a lot of sense.
Finally, I'd suggest reconsidering your program flow. Since it seems like you always search then assess, and never go back from recruiting to searching or assessing, you could do something like:
while <time is low enough>
% Search
% Assess
end
while <not enough robots>
% Recruit
end
-Cam
0 Comments
See Also
Categories
Find more on Robotics System Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!