SetCondition()

Description

Sets an input channel condition to handle on entering a state

  • Each condition is true if an input channel's state matches the condition's value.

  • The number of possible conditions is a configurable parameter specified in the state machine firmware.

Syntax

NewStateMachine = SetCondition(StateMachineStruct, ConditionNumber, ConditionChannel, ConditionValue)

Parameters

  • StateMachineStruct: The state machine description whose global timer you are setting.

  • ConditionNumber: The number of the condition you are setting (an integer).

  • ConditionChannel: The name of the input channel attached to the condition.

    • Input channel names are listed in BpodSystem.StateMachineInfo.InputChannelNames

    • The channel can also be a global timer, indicated as 'GlobalTimerN' where N is the index of the global timer.

  • ConditionValue: The value of the condition channel if the condition is met (1 = high, 0 = low)

    • If using a global timer, the timer is "high" (1) between its "start" and "end" events, and 0 otherwise.

Returns

  • A state machine struct, updated with the new condition description.

Example

% This code generates a state machine with three states. Each state lights up a behavior port. A condition is set to be valid if the IR channel of port2 is high (1). It is then used to skip state 2 if true.

sma = NewStateMachine;

sma = SetCondition(sma, 2, 'Port2', 1);

sma = AddState(sma, 'Name', 'Port1Light', ...

'Timer', 1,...

'StateChangeConditions', {'Tup', 'Port2Light'},...

'OutputActions', {'PWM1', 255});

sma = AddState(sma, 'Name', 'Port2Light', ...

'Timer', 1,...

'StateChangeConditions', {'Tup', 'Port3Light', 'Condition2', 'Port3Light'},...

'OutputActions', {'PWM2', 255});

sma = AddState(sma, 'Name', 'Port3Light', ...

'Timer', 1,...

'StateChangeConditions', {'Tup', 'exit'},...

'OutputActions', {'PWM3', 255});