Code covered by the BSD License  

Highlights from
NXT-LTD: Line Tracking Dancing Robot Demo

NXT-LTD: Line Tracking Dancing Robot Demo

by

 

23 May 2013 (Updated )

Modeling Logic for Robot Control with Simulink and Stateflow

( ...
classdef( ...
        Enumeration, ...
        Hidden = false,          ... % = [false]|true
        InferiorClasses = {},    ... % = {}
        ConstructOnLoad = false, ... % = [false]|true
        Sealed = false           ... % = [false]|true
        ) ...
        OperationModeType < Simulink.IntEnumType
    %% OperationModeType: Is an enumeration that lists all possible
    % mutually-exclusive states that the robot can have.
    
    
    % When adding or removing an enumeration from this list, please
    % double-check the following:
    %
    % * Ensure that its number is unique (there are a lot of enumerations).
    %
    % * Confirm that added enumerations are properly represented in the
    %  "getInnerTrackTaskExecutionList( )",
    %  "getOuterTrackTaskExecutionList( )", and
    %  "getCommonTaskExecutionList( )" methods.
    %
    % * Confirm that removed enumerations are no longer used in the
    %  "getInnerTrackTaskExecutionList( )",
    %  "getOuterTrackTaskExecutionList( )", and
    %  "getCommonTaskExecutionList( )" methods.
    %
    % Copyright 2013 The MathWorks, Inc.    
    enumeration
        PRE_EMERGENCY_STOP_TRANSITION            (  1 ), ...
            EMERGENCY_STOP                           (  2 ), ...
            POST_EMERGENCY_STOP_TRANSITION           (  3 ), ...
            ...
            PRE_STATIONARY_BALANCE_TRANSITION        (  4 ), ...
            STATIONARY_BALANCE                       (  5 ), ...
            POST_STATIONARY_BALANCE_TRANSITION       (  6 ), ...
            ...
            PRE_GYRO_SENSOR_CALIBRATION_TRANSITION   (  7 ), ...
            GYRO_SENSOR_CALIBRATION                  (  8 ), ...
            POST_GYRO_SENSOR_CALIBRATION_TRANSITION  (  9 ), ...
            ...
            PRE_LIGHT_SENSOR_CALIBRATION_TRANSITION  ( 10 ), ...
            LIGHT_SENSOR_CALIBRATION                 ( 11 ), ...
            POST_LIGHT_SENSOR_CALIBRATION_TRANSITION ( 12 ), ...
            ...
            PRE_LINE_TRACKING_TRANSITION             ( 13 ), ...
            LINE_TRACKING                            ( 14 ), ...
            POST_LINE_TRACKING_TRANSITION            ( 15 ), ...
            ...
            PRE_RAMP_TRANSITION                      ( 16 ), ...
            RAMP                                     ( 17 ), ...
            POST_RAMP_TRANSITION                     ( 18 ), ...
            ...
            PRE_LIMBO_TRANSITION                     ( 19 ), ...
            LIMBO                                    ( 20 ), ...
            POST_LIMBO_TRANSITION                    ( 21 ), ...
            ...
            PRE_BOTTLE_SEARCH_TRANSITION             ( 22 ), ...
            BOTTLE_SEARCH                            ( 23 ), ...
            POST_BOTTLE_SEARCH_TRANSITION            ( 24 ), ...
            ...
            PRE_DRIFT_TURN_TRANSITION                ( 25 ), ...
            DRIFT_TURN                               ( 26 ), ...
            POST_DRIFT_TURN_TRANSITION               ( 27 ), ...
            ...
            PRE_SEESAW_TRANSITION                    ( 28 ), ...
            SEESAW                                   ( 29 ), ...
            POST_SEESAW_TRANSITION                   ( 30 ), ...
            ...
            PRE_STEP_TRANSITION                      ( 31 ), ...
            STEP                                     ( 32 ), ...
            POST_STEP_TRANSITION                     ( 33 ), ...
            ...
            PRE_PARKING_TRANSITION                   ( 34 ), ...
            PARKING                                  ( 35 ), ...
            POST_PARKING_TRANSITION                  ( 36 ), ...
            ...
            BUTTON_PRESS_WAIT                        ( 37 ), ...
            ...
            TAIL_CALIBRATION                         ( 38 ),...
            ...
            LIGHT_SENSOR_ON_TAIL_CALIBRATION         ( 39 )
    end
    
    
    methods( ...
            Abstract = false,     ... % = [false]|true
            Access   = public,    ... % = [public]|protected|private
            Hidden   = false,     ... % = [false]|true
            Static   = true,      ... % = [false]|true
            Sealed   = false      ... % = [false]|true
            )
        function [ default_value ] = getDefaultValue( )
            %% getDefaultValue: returns the default enumerated value.
            
            default_value = OperationModeType.STATIONARY_BALANCE;
            
            return;
        end
        
        function [ description_text ] = getDescription( )
            %% getDescription: returns a text string describing the
            % class/enumeration.
            
            description_text = ...
                'This is a class that enumerates the possible modes of operation.';
            
            return;
        end
        
        function [ data_scope ] = getDataScope( )
            %% getDataScope: returns a text string indicating whether the
            % "typedef" for the enumeration is imported or exported.
            
            data_scope = 'Exported';
            
            return;
        end
        
        function [ header_file_name ] = getHeaderFile( )
            %% getHeaderFile: returns a text string of the name of the
            %header file to be used.
            
            [ ~, this_files_short_name ] = fileparts( mfilename );
            
            this_files_lower_case_short_name = ...
                lower( this_files_short_name );
            
            header_file_name = [ this_files_lower_case_short_name, '.h' ];
            
            return;
        end
        
        function [ class_name_addition_enabled ] = addClassNameToEnumNames( )
            %% addClassNameToEnumNames: returns a Boolean value indicating
            % whether the generated names for the enumeration values should
            % be prefixed with the class name.
            
            class_name_addition_enabled = false;
            
            return;
        end
        %% To be deleted:
        %         function [ enumeration_cellstr ] = getEnumerationCellArray( )
        %             %% getEnumerationCellArray: This function returns a cell array
        %             % of all elements within the enumeration for use within
        %             % Simulink "Switch" blocks. This function shouldn't need to
        %             % exist because, theoretically, the "enumeration" function
        %             % ought to produce the same thing. Unfortunately, it does not
        %             % and would result in a single "case" for all enumerated
        %             % values.
        %
        %             [ ~, enumeration_cellstr ] = enumeration( 'OperationModeType' );
        %             return;
        %         end
        
        function [ inner_track_task_execution_list ] = getInnerTrackTaskExecutionList( )
            %% getInnerTrackTaskExecutionList: Returns a list of the
            % OperationModeType enumerations for the inner track.
            
            common_task_execution_list = ...
                OperationModeType.getCommonTaskExecutionList( );
            
            inner_track_specific_tasks = ...
                [
                OperationModeType.PRE_LIMBO_TRANSITION, ...
                OperationModeType.LIMBO, ...
                OperationModeType.POST_LIMBO_TRANSITION, ...
                ...
                OperationModeType.PRE_BOTTLE_SEARCH_TRANSITION, ...
                OperationModeType.BOTTLE_SEARCH, ...
                OperationModeType.POST_BOTTLE_SEARCH_TRANSITION, ...
                ...
                OperationModeType.PRE_DRIFT_TURN_TRANSITION, ...
                OperationModeType.DRIFT_TURN, ...
                OperationModeType.POST_DRIFT_TURN_TRANSITION, ...
                ...
                OperationModeType.PRE_STEP_TRANSITION, ...
                OperationModeType.STEP , ...
                OperationModeType.POST_STEP_TRANSITION, ...
                ...
                OperationModeType.PRE_PARKING_TRANSITION, ...
                OperationModeType.PARKING, ...
                OperationModeType.POST_PARKING_TRANSITION ...
                ];
            
            inner_track_task_execution_list = ...
                [ ...
                common_task_execution_list, ...
                inner_track_specific_tasks ...
                ];
            
            return;
        end
        
        function [ outer_task_execution_list ] = getOuterTrackTaskExecutionList( )
            %% getOuterTrackTaskExecutionList: Returns a list of the
            % OperationModeType enumerations for the outer track.
            
            common_task_execution_list = ...
                OperationModeType.getCommonTaskExecutionList( );
            
            outer_track_specific_tasks = ...
                [ ...
                OperationModeType.PRE_STEP_TRANSITION, ...
                OperationModeType.STEP , ...
                OperationModeType.POST_STEP_TRANSITION, ...
                ...
                OperationModeType.PRE_SEESAW_TRANSITION, ...
                OperationModeType.SEESAW, ...
                OperationModeType.POST_SEESAW_TRANSITION, ...
                ...
                OperationModeType.PRE_PARKING_TRANSITION, ...
                OperationModeType.PARKING, ...
                OperationModeType.POST_PARKING_TRANSITION ...
                ];
            
            outer_task_execution_list = ...
                [ ...
                common_task_execution_list, ...
                outer_track_specific_tasks ...
                ];
            
            return;
        end
        
    end
    methods( ...
            Abstract = false,     ... % = [false]|true
            Access   = private,    ... % = [public]|protected|private
            Hidden   = false,     ... % = [false]|true
            Static   = true,      ... % = [false]|true
            Sealed   = false      ... % = [false]|true
            )
        function [ common_task_execution_list ] = getCommonTaskExecutionList( )
            %% getCommonTaskExecutionList: Returns a list of the
            % OperationModeType enumerations that are common to both the
            % inner and outer tracks.
            
            common_task_execution_list = ...
                [ ...
                OperationModeType.PRE_STATIONARY_BALANCE_TRANSITION, ...
                OperationModeType.STATIONARY_BALANCE, ...
                OperationModeType.POST_STATIONARY_BALANCE_TRANSITION, ...
                ...
                OperationModeType.PRE_GYRO_SENSOR_CALIBRATION_TRANSITION, ...
                OperationModeType.GYRO_SENSOR_CALIBRATION, ...
                OperationModeType.POST_GYRO_SENSOR_CALIBRATION_TRANSITION, ...
                ...
                OperationModeType.PRE_LIGHT_SENSOR_CALIBRATION_TRANSITION, ...
                OperationModeType.LIGHT_SENSOR_CALIBRATION, ...
                OperationModeType.POST_LIGHT_SENSOR_CALIBRATION_TRANSITION, ...
                ...
                OperationModeType.PRE_LINE_TRACKING_TRANSITION, ...
                OperationModeType.LINE_TRACKING, ...
                OperationModeType.POST_LINE_TRACKING_TRANSITION, ...
                ...
                OperationModeType.PRE_RAMP_TRANSITION, ...
                OperationModeType.RAMP, ...
                OperationModeType.POST_RAMP_TRANSITION, ...
                ...
                ];
            return;
        end
        
        %% To be deleted:
        %         function [ description_string ]  = getNXTLCDDisplayString( enumerationInstance )
        %             %% getNXTLCDDisplayString: This was all for nothing...
        %
        %             % This ought to be a property of the class, but the inheritance
        %             % rules of enumerations prevent it.
        %             NXT_MAXIMUM_DISPLAY_LENGTH = 8;
        %
        %             class_validity = ...
        %                 isa( enumerationInstance, 'OperationModeType' );
        %
        %             assert( ( true == class_validity ), ...
        %                 'The object/first argument must be an instance of "OperationModeType".' );
        %
        %             switch( enumerationInstance )
        %                 case OperationModeType.DRIFT_TURN
        %                     description_string = 'Drift';
        %
        %                 case OperationModeType.EMERGENCY_STOP
        %                     description_string = 'E Stop';
        %
        %                 case OperationModeType.GYRO_SENSOR_CALIBRATION
        %                     description_string = 'G Cal';
        %
        %                 case OperationModeType.LIGHT_SENSOR_CALIBRATION
        %                     description_string = 'LS Cal';
        %
        %                 case OperationModeType.LIMBO
        %                     description_string = 'Limbo';
        %
        %                 case OperationModeType.LINE_TRACKING
        %                     description_string = 'Line T';
        %
        %                 case OperationModeType.PARKING
        %                     description_string = 'Park';
        %
        %                 case OperationModeType.STATIONARY_BALANCE
        %                     description_string = 'Bal.';
        %
        %                 case OperationModeType.STEP
        %                     description_string = 'Step';
        %
        %                 otherwise
        %                     error( 'Invalid enumeration value.' );
        %             end
        %             string_length = numel( description_string );
        %             string_length_validity = ...
        %                 ( string_length < NXT_MAXIMUM_DISPLAY_LENGTH );
        %
        %             assert( ( true == string_length_validity ), ...
        %                 [ 'The description string must be fewer than ', num2str( NXT_MAXIMUM_DISPLAY_LENGTH ), ' characters.' ] );
        %
        %             return;
        %         end
        
    end
    
    
end

Contact us