next up previous contents
Next: Implementation Up: Constraints and Update Rules Previous: Language Syntax

The Generated Code

As mentioned before, this compiler generates C++ code which is integrated with the CI system to check the constraint or apply the update rule. Each variable in the input to the compiler corresponds to one design parameter. For example, ``link1_length'' corresponds to the variable in the CI system that represents the length of link number one in the robot configuration. The code generator uses a lookup table to find the corresponding variable name, and this table is part of the CI database. A simple flat file is used to store this table since the number of the design parameters is small.

The generated code for the constraints is the function ``pe.check_constraints'' that returns true if all constraints are satisfied, else it returns false, and reports which constraints are not satisfied. For the rules, the code generated is the function ``pe.apply_rules'' which calculates all corresponding design variables according to the given rules. The following examples are the code generated for the two examples shown in the previous section.

bool 
ci::check_constraints()
{    
    bool status[no_of_constraints] ;
    int i = 0 ;

    status[i++] = robot.configuration.link[0].length > 1.2 ;
    status[i++] = robot.configuration.link[1].length > 1.5 ;
    status[i++] = robot.configuration.link[2].length > 0.8 ;
    status[i++] = robot.configuration.link[1].length +
                  robot.configuration.link[2].length < 3.0 ;
    status[i++] = robot.configuration.link[0].mass < 1.4 ;
    status[i++] = robot.configuration.link[1].mass +
                  robot.configuration.link[2].mass  < 4.0 ;
    status[i]   = robot.configuration.joint[1].gear_ratio < 5.0 ;
    
    constraints.generate_report(status) ;   // report the result
    
    return (and_all(status)) ;
}


void
ci::apply_rules()
{
    robot.configuration.link[0].mass = 
        robot.configuration.link[0].length *
        robot.configuration.link[0].cross_area *
        robot.configuration.link[0].density ;
    robot.configuration.link[1].mass = 
        robot.configuration.link[1].length *
        robot.configuration.link[1].cross_area *
        robot.configuration.link[1].density ;
    robot.configuration.link[2].mass = 
        robot.configuration.link[2].length *
        robot.configuration.link[2].cross_area *
        robot.configuration.link[2].density ;
    robot.configuration.joint[0].gear_ratio =
        robot.motor[0].speed /
        robot.configuration.joint[0].max_speed ;
}

In the first example, the function generate_report reports the results of checking the constraints; if all constraints are satisfied it reports that, otherwise, it will generate a list of the unsatisfied constraints. The function and_all is obvious. It returns the result of ANDing the elements in the array status.

In the second example, some of the design parameters are calculated given the values of some other parameters. The compiler should not allow the change of any parameter that should not be changed by the CI system. This can be detected using the alter_flag in the design parameters table.

To update the constraints or the update rules the file containing the old definition will be displayed and the user can add, delete, or update any of the old definitions. Then the new file will be compiled and integrated with the system.


next up previous contents
Next: Implementation Up: Constraints and Update Rules Previous: Language Syntax

Matanya Elchanani
Wed Dec 18 17:00:21 EST 1996