Using a Latching Combination Trigger for Hysteresis

This is a continuation from the Stopping a Robot if It Tips Over example. In this page, we'll set up an additional threshold trigger and combination trigger which will perform the E-stop "reset" function. The GPIO action will need to be modified to no longer use the oneshot mode.

 

NOTE: This example can be easily adapted to the 3DM-CV7 by substituting GPIO 1 or GPIO 2 for GPIO 4.

 

GPIO Action Modification

For this method to work, the combination trigger must directly control the GPIO state. To do so, the GPIO action must use one of the ACTIVE_ modes, in this case ACTIVE_HIGH. Additionally, it will use a new trigger. The configuration command from the original example is changed to the following.

Command: Event Action Configuration (0x0C,0x2F)

  • Function: WRITE (0x01)
  • Instance: 1
  • Trigger ID: 3 (must match the combo trigger below)
  • Type: GPIO (0x01)
  • Parameters:
    • Pin: 4
    • Mode: ACTIVE_HIGH (0x01)

Command bytes: 010103010401
MIP Packet: 75650c08 082f010103010401 303f

 

Additional Threshold Trigger

Just like the other hysteresis example, Using Two GPIO Actions in Oneshot mode, we'll set up another threshold trigger.

We'll set up another threshold trigger just like the first but with a narrower window and the opposite logic. This will trigger when the robot is returned to the upright position, plus or minus 10 degrees. The trigger will be similar to the original one, but have a different instance ID, different thresholds, and reversed logic. This is identical to the one in the Using Two GPIO Actions in Oneshot mode example.

Command: 

  • Function: WRITE (0x01)
  • Instance: 2 (must be different from the original)
  • Type: Threshold (0x02)
  • Parameters:
    • Descriptor Set: 0x80 (Sensor Dataset)
    • Field Descriptor: 0x0C (Euler Angles)
    • Parameter ID: 1 (Roll)
    • Mode: WINDOW (0x01)
    • Low Threshold: -0.1745329 (-10 degrees)
    • High Threshold: +0.1745329 (+10 degrees)

Command bytes: 010202800c0101bfc6571814c9bba03fc6571814c9bba0
MIP Packet: 75650c19 192e010202800c0101bfc6571814c9bba03fc6571814c9bba0 b1fa

Enable the new threshold trigger

Command: Event Control (0x0C,0x2B)

  • Function: WRITE (0x01)
  • Instance: 2
  • Mode: ENABLE (0x01)

Command bytes: 010201
MIP Command: 75650c05 052b010201 1f84

Combination Trigger

Now comes the final part which makes it all work. We need a latching combination trigger which will control the E-stop signal. Two inputs are needed, the original "stop" trigger (instance #1), and the new "reset" trigger (instance #2). The logic should follow these rules:

  • If the "stop" trigger is active, the state will be active.
  • If the "reset" trigger is active, the state will be inactive.
  • If neither are active, the state doesn't change. It will be the same as the last event cycle.
  • If both are active, the state will be active. This can't happen if the other triggers are set up properly because the thresholds do not overlap. However, it's good practice to specify all possible conditions.

An extra input is needed to obtain the state from the last event cycle to implement the third bullet point. We'll assign this "feedback" input to slot A. The "stop" and "reset" triggers will be assigned to slots B and C respectively. Input D is not needed, so it will be set to 0.

According to the rules above, this produces the following logic table:

C B A Output Comment
0 0 0 0 Neither "stop" nor "reset" active - no change in state so the output must match input A.
0 0 1 1
0 1 0 1 "Stop" signal active - state should be active regardless of the other two
0 1 1 1
1 0 0 0 "Reset" signal active - state should be inactive regardless of the previous state.
1 0 1 0
1 1 0 1 Both signals active (impossible) - default to active
1 1 1 1

The logic value for this table is 11001110 binary, or CE hexadecimal. To build the full u16 value, we'll duplicate the logic for the case where input D would theoretically be active. This results in 0xCECE. Now we have everything needed to build the command.

Command: Event Trigger Configuration (0x0C,0x2E)

  • Function: WRITE (0x01)
  • Instance: 3
  • Type: Combination (0x03)
  • Parameters:
    • Logic Table: 0xCECE
    • Inputs: [3 (this trigger), 1 (reset), 2 (stop), 0 (unused)]

Command bytes: 010303cece03010200
MIP Packet: 75650c0b 0b2e010303cece03010200 d3e9

Enable the combo trigger

Command: Event Control (0x0C,0x2B)

  • Function: WRITE (0x01)
  • Instance: 3
  • Mode: ENABLE (0x01)

Command bytes: 010301
MIP Command: 75650c05 052b010301 2086

 

Test it

Now tilt the 3DM-CV7 as before. The buzzer should sound but once the device is returned to level it should stop. The result will be identical to the Using Two GPIO Actions in Oneshot mode example except if the pin is manually changed with the GPIO State (0x0C,0x42) command. In this case, the pin state may glitch briefly but will quickly return to the state determined by the event system.