You can use MATLAB's "monostable" block for your use case. It will create an output that stays "on" for a specific time after being triggered.
First, detect the moment the gear changes by comparing its current value to its previous value:
- Unit Delay block: Feed the current gear signal into it.
- Relational Operator block: Compare the current gear with the output of the Unit Delay. Set the operator to "not equal" (~=). The output will be a pulse (1) when the gear changes.
Now, use the Monostable block to create the 3-second hold:
- Connect the output of your Relational Operator (the change pulse) to the input of the Monostable block.
- Double-click the Monostable block and set the Pulse duration to 3.
The output of this Monostable block is now your "lock" signal. It will become 1 as soon as it's triggered by a gear change and will automatically return to 0 after 3 seconds.
Use the "lock" signal from the Monostable block to control a Switch that allows or blocks the shift commands.
- Get your shift_command (+1 or -1 from your up/downshift logic).
- Connect the shift_command to the bottom input of a Switch block.
- Connect a Constant block (value 0) to the top input of the Switch.
- Connect the "lock" signal (from the Monostable block) to the middle control input of the Switch.
Here is the documentation:
Hope it helped!