Why fixed values are not working in randomstart function of trainDDPGrobot program?

조회 수: 2 (최근 30일)
I am new to reinforcement learning and have run the programs given in online ramp course of reinforcement learning. In the randomstart function I made only a single change as given in the code below but the program is giving the error shown in the attached image. I have seen the documentation of environment reset function, where all examples are given with random numbers. But I want all input variables i.e. x0, y0, theta0, v0, and w0 to be fix and should be picked from the already stored vectors, When I tried with a constant value of only a single variable x0 (given in line#3 of the program given below), the program is generating an error. Line # 4 in the program given below was the one in the original program (% now), while I have added line # 5 in its replacement, which is not working. How can I fix it?
function in = randomstart(in)
mdl = "whrobot";
a=0.5;
% in = setVariable(in,"x0",((-1)^randi([0 1]))*(2.5 + 3.5*rand),"Workspace",mdl);
in = setVariable(in,"x0",a,"Workspace",mdl);
in = setVariable(in,"y0",2.6 + 3.4*rand,"Workspace",mdl);
in = setVariable(in,"theta0",pi*(2*rand-1),"Workspace",mdl);
in = setVariable(in,"v0",randn/3,"Workspace",mdl);
in = setVariable(in,"w0",randn/3,"Workspace",mdl);
disp(x0)
end

채택된 답변

Aneela
Aneela 2024년 8월 21일
편집: Aneela 2024년 8월 21일
The error “Unrecognized function or variable x0” is because of the following:
  • “x0” is not defined in the current workspace but is rather defined as a variable inside the simulation environment using the “setVariable” function.
  • When “x0” is displayed using “disp(x0)”, MATLAB cannot find “x0” in the current workspace because it’s not explicitly defined here.
To display “x0”, store it in a local variable before calling “setVariable”. The following code stores the value of “a” in a local variable ”x0_value”:
function in = randomstart(in)
mdl = "whrobot";
a = 0.5;
% Set x0 and store its value in a local variable
x0_value = a; %will be stored in the current workspace
in = setVariable(in, "x0", x0_value, "Workspace", mdl);
in = setVariable(in, "y0", 2.6 + 3.4*rand, "Workspace", mdl); %will be stored in the simulation environment
in = setVariable(in, "theta0", pi*(2*rand-1), "Workspace", mdl);
in = setVariable(in, "v0", randn/3, "Workspace", mdl);
in = setVariable(in, "w0", randn/3, "Workspace", mdl);
disp(x0_value);
end
Refer to the following MathWorks documentation for more information on “setVariable”: https://www.mathworks.com/help/simulink/slref/simulink.simulationinput.setvariable.html

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Sequence and Numeric Feature Data Workflows에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by