# Behavior-Based Control Architecture for Legged-and-Climber Robots
## 3 The Climber Hexapod Robot ROMHEX
### Optimization of the Leg Positions  
Making use of genetic algorithms (in this case, MatLab's _ga_ function), it is possible to find the best position of the robot's legs' initial configuration according to a criterion. The algorithm uses a combination of the distance the robot can walk and the forces produced at the legs as a cost function. Because the objective is to obtain the optimal initial position of the legs to walk, the \"genes\" or decision variables are the initial positions of the legs (X and Y for each leg and a global \(Z\) with respect to the center of the robot, this is, 13 positions in total).  
An analysis has been carried out on the center of mass and how its position affects the forces produced in the different legs to improve the results. The objective of the cost function is to obtain a genetic individual (legs position configuration) that achieves the greatest distance while walking with a given number of movements following a predefined pattern, keeping the robot safe. It considers the distance that the robot moves, as well as the maximum permissible forces in the legs, as indicated in (1), where \(C\) is the cost function, \(D\) is the distance traveled, and \(F\) is a matrix where each row corresponds to a moment in the execution of the walking movement and each element of the row corresponds to each leg. The cost function is negative because it is required to minimize the value. Both \(f(x)\) and  
Figure 1: Joint axis and reference systems of the legs. (**a**) ROMHEX with the reference system of the body and legs, and leg identifier. (**b**) Axis of ROMHEX joints.  
\(D\) are positive values, being a single \(S\) calculated in (2), where \(S\) represents the vector of forces applied over a leg, and \(S(2)\) is the force applied over the \(z\) axis.  
\[C =-min(f(max(F)),f(min(F)))\cdot D \tag{1}\] \[S =norm(S)\cdot sign(S(2)) \tag{2}\]  
Function \(f(x)\) is distance scaling and piecewise defined, as shown in Figure 2. The objective of scaling the distance obtained by the factor produced by the function is to penalize the individuals that produce the highest forces, even if they manage to move a greater distance. The function takes into account the sign on the \(z\) axis, to differentiate the dangerous forces. Both signs are considered to eliminate individuals that make the suction cups detach and reduce extreme forces on a single leg to reduce unequal wearing.  
To obtain the value of _dist_, the developed walking movement has been simulated in the following way: First, it is checked that the individual is valid, this is, (a) the position of all the legs is reachable with the inverse kinematics, (b) the position of the motors is within the specified ranges, and (c) there is no collision between legs. Second, the cost function value is obtained.  
The results of the genetic algorithm are an increase of 107% in the distance traveled (from 355 mm to 735 mm) and a decrease of 10% in the force. Figure 3 shows a representation of the optimized version over the previous one. As illustrated in that picture, the position of the legs has undergone a slight variation to achieve an initial position that optimizes the evaluation criteria. Table 1 denotes the joint initial position increment between before and after the optimization, with the references in the motor encoder origins. Furthermore, both tables show the end-effector positions (feet) when the motors are in the given initial position.  
Figure 2: Distance scaling function.