I am trying to implement a fuzzy logic controller for manipulator control using genetic algorithm. I have seven membership function defined for each of the following parameters, position of link 1, velocity of link 1, position of link 2 and velocity of link 2. I am trying to use genetic algorithm to change the value obtained from my membership function in order to provide better control. I am adding a certain value 'x' to the degree of membership for each of these values. That makes a total of 7×4, 28 variables in 'x'.
1. I only want to impose upper and lower bounds on the values of x and no other non-linear constraints. What should be the format of my contrarians function? and is there an easier way to do it without making a constraints function? Here is how I am trying to implement it. Please let me know if its correct.
%%constraint function
function [c_eq] = myConstraints(x)c_eq = [];endObjFcn = @myFitness;nvars = 28;LB = [-0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2];UB = [0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2];ConsFcn = @myConstraints;[x, fval] = ga(ObjFcn,nvars);
2. I have a global variables, position1 and position2 declared inside my fitness function which are matrices storing the values of positions for every passing iteration. These variables are not getting reflected in my workspace. How can I get them to show up there? I tried initialising it inside my main function using:
global n position1 position2n=1;position1(n)=0;
and then my n gets incremented inside my fitness function and the new value of position is supposed to be added to position1 and position2 inside my fitness function. Now these new values are not getting reflected in my workspace and the only value contained by these variables in my workspace is the one I initialised it to have.
3. If I have some extra variables (which I have declared as global in both, main and the fitness function) and I make changes to them inside my fitness function (for the purpose of calculation of the parameter I wish to minimise), will these changes be reflected in my main function when I call ga or will ga simply tell me the values of 'x' that I should use inside main to make these respective changes to my extra variables?
Some extra information about my code that might help you understand my questions better- I am slowly increasing the value of position in roughly 600 iterations in my main program. I am calling ga in every iteration. I am using ga to minimise the total error in position (abs(desired_val_position1-actual_val_position1) + abs(desired_val_position2-actual_val_position2). The value of the current positions are being updated only inside the fitness function. (I have presumed that the changes I make to some extra variables inside my fitness function will be reflected in my main function and the workspace.
Best Answer