Triggering Examples

This section provides examples related to triggering PiMotion™ devices.

Manual Triggering

This python code example shows how to manually trigger a motor to start.

[source code]

# note: excluding code for configuring motor and sending motion profile

# arm the motor to wait for manual trigger
pm.mtr_start(0,pilib.TRIG_SRC_MANUAL)

print 'Waiting for manual trigger...'
time.sleep(2)
print 'Okay, go!'

pm.pidev_trigger_manual()

Timer-based Triggering

This Python code shows how to trigger a motor based on timer #1.

[source code]

# note: excluding code for configuring motor and sending motion profile

# start motor to wait for timer trigger
pm.mtr_start(0,pilib.TRIG_SRC_TIMER_1)

print 'Motor will go in 5 seconds (relative).'
pm.pidev_trigger_timer1(1, 5000000000)

Group Triggering

This Python code shows how to trigger a PiMotion™ group based on timer #1.

[source code]

This first snippet shows how to configure two PiMotion™ devices as a group.

import time
import pilib

addr1 = '192.168.1.201'
addr2 = '192.168.1.200'
group_id = 22 #just a unique group number

pm1 = pilib.Pidev(addr1)
pm2 = pilib.Pidev(addr2)

"""
Configure group operation
"""
def configure_group(pm, device_group, device_id, heartbeat_mask, ptp_master):
    prev = {}
    prev['device_group'] = pm.config_get_device_group()
    prev['device_id'] = pm.config_get_device_id()
    prev['heartbeat_mask'] = pm.config_get_heartbeat_mask()
    prev['ptp_master'] = pm.config_get_ptp_master()  

    if (prev['device_group'] != device_group or \
        prev['device_id'] != device_id or \
        prev['heartbeat_mask'] != heartbeat_mask or \
        prev['ptp_master'] != ptp_master):
        
        pm.config_set_device_group(device_group)
        pm.config_set_device_id(device_id)
        pm.config_set_heartbeat_mask(heartbeat_mask) #device 0 and 1 only
        pm.config_set_ptp_master(ptp_master)
        pm.config_commit()
        try:
            print ("Resetting device.")
            pm.config_reset()
        except:
            pass

    return prev
    
print ("Setting group configuration.")

pm1_prev = configure_group(pm1, 22, 0, 0b11, 1)
pm2_prev = configure_group(pm2, 22, 1, 0b11, 0)

This second snippet shows how to trigger the group based on timer #1.

# note: excluding code for configuring motors and sending motion profiles
pm1.mtr_start(0,pilib.TRIG_SRC_TIMER_1)
pm2.mtr_start(0,pilib.TRIG_SRC_TIMER_1)

print 'Motors will go in 1 sec.'
pm1.pidev_trigger_group(1, 0, 1000000000, 0, 0)