PiMotion Python Software Interface¶
Classes¶
General Methods¶
-
Pidev.
pidev_scan
(ifaddr, timeout_ms, max_results)¶ Scan for pidev devices
Parameters: - ifaddr – interface address (ip address of which network card to use), or “all” for all network cards
- timeout_ms – timeout (milliseconds) to wait for devices on each network card
- max_results – maximum number of results requested
Returns: an array of dictionaries containing address, name, version, device type, software type, password status, and ip port.
-
Pidev.
pidev_trigger
(group_trigger, timer1_relative, timer2_relative, timer1_time, timer2_time, manual_trigger)¶ Multiple/complex triggering
Parameters: - group_trigger – enable group trigger (0: disabled, 1: enabled)
- timer1_relative – enable relative trigger based on timer 1 (0: disabled, 1: enabled)
- timer2_relative – enable relative trigger based on timer 2 (0: disabled, 1: enabled)
- timer1_time – nanosecond time for timer 1 (absolute or relative), 0: ignore)
- timer2_time – nanosecond time for timer 2 (absolute or relative), 0: ignore)
- manual_trigger – manually trigger (0: ignored, 1: trigger now)
-
Pidev.
pidev_trigger_manual
()¶ Manual trigger
-
Pidev.
pidev_trigger_timer1
(relative, time)¶ Arm timer 1 trigger
Parameters: - relative – relative trigger time (0: absolute, 1: relative)
- time – nanosecond time
-
Pidev.
pidev_trigger_timer2
(relative, time)¶ Arm timer 2 trigger
Parameters: - relative – relative trigger time (0: absolute, 1: relative)
- time – nanosecond time
-
Pidev.
pidev_trigger_group
(timer1_relative, timer2_relative, timer1_time, timer2_time, manual_trigger)¶ Group trigger
Parameters: - timer1_relative – enable relative trigger based on timer 1 (0: disabled, 1: enabled)
- timer2_relative – enable relative trigger based on timer 2 (0: disabled, 1: enabled)
- timer1_time – nanosecond time for timer 1 (absolute or relative), 0: ignore)
- timer2_time – nanosecond time for timer 2 (absolute or relative), 0: ignore)
- manual_trigger – manually trigger (0: ignored, 1: trigger now)
-
Pidev.
pidev_info
()¶ Get information about the device
Returns: dictionary containing software app running, version number, build number, error mask, serial number, and manufacture date
-
Pidev.
pidev_set_password
(password)¶ Change device password
Parameters: password – password string
-
Pidev.
pidev_set_ptp_password
(password)¶ Change device ptp password
Parameters: password – password string
-
Pidev.
pidev_set_timeout_offset
(timeout_offset_ms)¶ Add additional timeout time to all library calls
Parameters: timeout_offset_ms – additional time (milliseconds)
-
Pidev.
pidev_get_temperature
()¶ Get device internal temperature
-
Pidev.
err_register_callback
(ifaddr, port, f)¶ Register error/vmsg callback
Parameters: - ifaddr – interface address (ip address of which network card to use), or “all” for all network cards
- port – ip port
- f – callback function
-
Pidev.
pidev_clear_faults
()¶ Clear faults bit field
-
Pidev.
pidev_get_connected_devices
()¶
Configuration Methods¶
-
Pidev.
config_commit
()¶ Commit configuration changes to flash
-
Pidev.
config_reset
()¶ Reset the device
Time Methods¶
-
Pidev.
vtrigger_set
()¶ Manually trigger waiting operations
-
Pidev.
time_get_offset_from_master
()¶ Clock offset/difference from master
-
Pidev.
time_get_drift
()¶
-
Pidev.
time_get_kp
()¶
-
Pidev.
time_get_ki
()¶
Motor Methods¶
-
Pidev.
mtr_start
(start_segment, trigger)¶ Start the motor starting at start_segment (usually 0) using the trigger condition specified.
Parameters: - start_segment – starting segment
- trigger – trigger type. See Trigger Source
-
Pidev.
mtr_reset
()¶ Reset the motor
-
Pidev.
mtr_write_phase_mem
(fields, shift_value)¶ Write motor phase waveform
Parameters: - fields – fields array
- shift_value – shift value
-
Pidev.
mtr_write_phase_mem_default
(phases, poles, enc_cnts_per_rot)¶ Write default motor phase waveform to controller
Parameters: - phases – number of motor phases
- poles – number of motor poles
- enc_cnts_per_rot – number of encoder counts per rotation
-
Pidev.
mtr_write_phase_mem_default_buffer
(phases, poles, enc_cnts_per_rot, buf)¶ Write default motor phase waveform to a buffer
Parameters: - phases – number of motor phases
- poles – number of motor poles
- enc_cnts_per_rot – number of encoder counts per rotation
- buf – numpy preallocated buffer of type np.ndarray[np.uint32_t, ndim=1]
-
Pidev.
mtr_write_phase_mem_stepper
(microstep_multiplier)¶ Write phase memory for stepper motor
Parameters: microstep_multiplier – TODO
-
Pidev.
mtr_write_table
(start_segment, segments)¶ Write motion table
Parameters: - start_segment – starting segment
- segments – segments array
-
Pidev.
mtr_read_table
(start_segment, num_segments)¶ Read motion table
Parameters: - start_segment – starting segment
- num_segments – number of segments
-
Pidev.
mtr_write_target_position
(position, servomode=0)¶ Write target position
Parameters: - position – position
- servomode=0 –
-
Pidev.
mtr_create_velocity_profile
(start_velocity, profile, servomode, elec_cycle_div)¶ Create a velocity profile
Parameters: - start_velocity – starting velocity
- profile –
- servomode – servo mode. See Servo Mode
- elec_cycle_div – electrical cycles divisor
-
Pidev.
mtr_create_trapezoidal_profile
(start_position, profile, servomode, elec_cycle_div)¶ Create a trapezoidal profile
Parameters: - start_position – starting position
- profile –
- servomode – servo mode. See Servo Mode
- elec_cycle_div – electrical cycles divisor
-
Pidev.
mtr_get_elec_cycle_div
()¶ Get the electrical cycle time divisor. this value is used to set the electrical cycle time clock. it is calculated by dividing the base clock rate default_clk_pimotion by this value. example: elec_cycle_div = default_clk_pimotion * 0.001.
Returns: the electrical cycle time divisor. Return type: int
-
Pidev.
mtr_set_elec_cycle_div
(val)¶ Set the electrical cycle time divisor. this value is used to set the electrical cycle time clock. the electrical cycle time is calculated by dividing the base clock rate default_clk_pimotion by this value.
Parameters: val (int) – the electrical cycle time divisor. To calculate the divisor do the following: divisor = DEFAULT_CLK_PIMOTION * 0.001 where 0.001 is the period in seconds.
-
Pidev.
mtr_get_kp
()¶ Get the servo loop kp term. see PID Algorithm
Returns: the active Kp value. Return type: float
-
Pidev.
mtr_set_kp
(val)¶ Set the servo loop kp term. this value acts upon the servo loop immediately. see PID Algorithm
Parameters: val (float) – value of the Kp. Range of 0.0 to 32768.0
-
Pidev.
mtr_get_ki
()¶ Get the servo loop ki term. see PID Algorithm
Returns: the active Ki value. Return type: float
-
Pidev.
mtr_set_ki
(val)¶ Set the servo loop ki term. this value acts upon the servo loop immediately. see PID Algorithm
Parameters: val (float) – value of the Ki. Range of 0.0 to 32768.0. A value of 0 disables the Ki component.
-
Pidev.
mtr_get_kd
()¶ Get the servo loop kd term. see PID Algorithm
Returns: the active Kd value. Return type: float
-
Pidev.
mtr_set_kd
(val)¶ Set the servo loop kd term. this value acts upon the servo loop immediately. see PID Algorithm
Parameters: val (float) – value of the Ki. Range of 0.0 to 32768.0. A value of 0 disables the Kd component.
-
Pidev.
mtr_get_ilim
()¶ Get the servo loop integration limit. see PID Algorithm
Returns: the active integration limit value. Return type: int
-
Pidev.
mtr_set_ilim
(val)¶ Set the servo loop integration limit. see PID Algorithm
Parameters: val (int) – value of the integration limit.
-
Pidev.
mtr_get_kvff
()¶ Get the servo loop velocity feed forward. see PID Algorithm
Returns: value of the velocity feed forwarf (vff) Return type: float
-
Pidev.
mtr_set_kvff
(val)¶ Set the servo loop velocity feed forward. see PID Algorithm
Parameters: val (float) – value of the velocity feed forward (vff)
-
Pidev.
mtr_get_kaff
()¶ Get the servo loop acceleration feed forward. see PID Algorithm
Returns: value of the acceleration feed forwarf (vff) Return type: float
-
Pidev.
mtr_set_kaff
(val)¶ Set the servo loop acceleration feed forward. see PID Algorithm
Parameters: val (float) – value of the acceleration feed forwarfd(vff)
-
Pidev.
mtr_get_max_pid_output
()¶ Get the maximum pid (servo loop) output. see PID Algorithm
Returns: the maximum output of the PID loop. Return type: int
-
Pidev.
mtr_set_max_pid_output
(val)¶ Set the maximum pid (servo loop) current output. this sets the positive and negative outputs. example: 10000 would set a limit of positive limit of 10000 and a negative limit of -10000. see PID Algorithm
Parameters: val (int) – current in terms of DAC output.
-
Pidev.
mtr_set_aux_enc_counts_per_rot
(val)¶ Set the auxiliary encoder counts per rotation. this is the number of counts for a full rotation of the encoder. for example, if the encoder was a 512 line encoder, the number of counts per rotation would be 512 * 4 = 1024.
Parameters: val (int) – encoder counts per rotation in terms of counts.
-
Pidev.
mtr_get_aux_enc_index_count
()¶ Get the auxiliary encoder index counter. every time an index pulse is detected on the auxiliary encoder, (either forward rotation or reverse rotation) the auxiliary encoder index count is incremented. note: this value will not change on encoders that do not have an index option.
Returns: index count. Number of times the encoder has passed the index line. Return type: int
-
Pidev.
mtr_get_aux_enc_glitch_count
()¶ Get the auxiliary encoder glitch count. any time the auxiliary encoder enters a state that is unexpected, the encoder glitch count is incremented. the encoder glitch count should remain at zero unless there is a bad connection or faulty encoder.
Returns: glitch count. Return type: int
-
Pidev.
mtr_set_use_aux_enc_for_servo
(val)¶ Sets which encoder is used for the trajectory generator and servo loop (pid). defaultly the trajectory generator and the servo loop use the first encoder input (not the auxiliary).
Parameters: val (int) – select to use the auxiliary encoder as the input to the trajectory generator and servo loop. 0 - first encoder (default), 1 -auxiliary encoder.
-
Pidev.
mtr_get_loop_mode
()¶
-
Pidev.
mtr_get_manual_loop_current
()¶
-
Pidev.
mtr_get_traj_gen_busy
()¶ Get the busy state of the trajectory generator.
-
Pidev.
mtr_get_phase_mem_shift
()¶
-
Pidev.
mtr_get_phase_offset
()¶ Gets the phase offset.
-
Pidev.
mtr_get_phase_mem_address
()¶
-
Pidev.
mtr_get_vel_error
()¶ Get the velocity error in counts per second.
-
Pidev.
mtr_restore_defaults
()¶ Restore motor configuration to power on defaults.
-
Pidev.
mtr_get_actual_index_pos
()¶ Get the actual (64bit) position of the index. every time an index pulse is detected, the actual position of the index is recorded. see actual position.
Returns: the actual position of the index (64 bit position). Return type: int
-
Pidev.
mtr_get_aux_actual_index_pos
()¶ Get the actual (64bit) position of the auxiliary encoder index. every time an index pulse of the auxiliary encoder is detected, the auxiliary actual position of the index is recorded. see actual position.
Returns: the auxiliary actual position of the index (64 bit position). Return type: int
-
Pidev.
mtr_get_kvff_shift
()¶ Gets the amount of bits to shift the kvff (velocity feed forward) term right. velocity_feed_forward = kvff >> kvff_shift. see PID Algorithm and velocity feed forward.
Returns: the value of kvff_shift. Return type: int
-
Pidev.
mtr_set_kvff_shift
(val)¶ Sets the amount of bits to shift the kvff (velocity feed forward) term right. velocity_feed_forward = kvff >> kvff_shift. see PID Algorithm and velocity feed forward.
Parameters: val (int) – the amount to shift Kvff right. Valid values of 0 - 15.
-
Pidev.
mtr_get_kaff_shift
()¶ Gets the amount of bits to shift the kaff (velocity feed forward) term left. acceleration_feed_forward = kaff << kaff_shift. see PID Algorithm and acceleration feed forward.
Returns: the value of kaff_shift. Return type: int
-
Pidev.
mtr_set_kaff_shift
(val)¶ Sets the amount of bits to shift the kaff (velocity feed forward) term left. acceleration_feed_forward = kaff << kaff_shift. see PID Algorithm and acceleration feed forward.
Parameters: val (int) – the amount to shift Kaff left. Valid values of 0 - 15.
-
Pidev.
mtr_set_biquad_shiftby
(val)¶ Sets the amount of bits to shift the kaff (velocity feed forward) term left. acceleration_feed_forward = kaff << kaff_shift. see PID Algorithm and acceleration feed forward.
Parameters: val (int) – the amount to shift Kaff left. Valid values of 0 - 15.
-
Pidev.
mtr_set_biquad_a0
(val)¶ Set the maximum pid (servo loop) current output. this sets the positive and negative outputs. example: 10000 would set a limit of positive limit of 10000 and a negative limit of -10000. see PID Algorithm
Parameters: val (int) – current in terms of DAC output.
-
Pidev.
mtr_set_biquad_a1
(val)¶ Set the maximum pid (servo loop) current output. this sets the positive and negative outputs. example: 10000 would set a limit of positive limit of 10000 and a negative limit of -10000. see PID Algorithm
Parameters: val (int) – current in terms of DAC output.
-
Pidev.
mtr_set_biquad_a2
(val)¶ Set the maximum pid (servo loop) current output. this sets the positive and negative outputs. example: 10000 would set a limit of positive limit of 10000 and a negative limit of -10000. see PID Algorithm
Parameters: val (int) – current in terms of DAC output.
-
Pidev.
mtr_set_biquad_b1
(val)¶ Set the maximum pid (servo loop) current output. this sets the positive and negative outputs. example: 10000 would set a limit of positive limit of 10000 and a negative limit of -10000. see PID Algorithm
Parameters: val (int) – current in terms of DAC output.
-
Pidev.
mtr_set_biquad_b2
(val)¶ Set the maximum pid (servo loop) current output. this sets the positive and negative outputs. example: 10000 would set a limit of positive limit of 10000 and a negative limit of -10000. see PID Algorithm
Parameters: val (int) – current in terms of DAC output.
Data Acquisition Methods¶
Analog to Digital Converter Methods¶
-
Pidev.
daq_start
(chan_id, divisor, start_sample, num_samples, trigger)¶ Start the data acquisition channel
Parameters: - chan_id – channel identifier
- divisor – clock divisor, to derive sampling rate (divisor of 0.001 gives 1kHz sample rate
- start_sample – post-trigger sample number
- num_samples – number of samples
- trigger – trigger type. See Trigger Source
-
Pidev.
daq_listen
(chan_id)¶ Receive data acquisition channel that has already been started by a different connection
Parameters: chan_id – channel identifier
-
Pidev.
daq_register_callback
(chan_id, samples, milliseconds, f)¶ Listen for data acquisition. only needs to be registered once.
Parameters: - chan_id – channel identifier
- samples –
- milliseconds – milliseconds before callback
- f – callback function
-
Pidev.
daq_acquire_data
(chan_id, samples, np.ndarray[np.int32_t, ndim=1] buf)¶ Listen for data acquisition
Parameters: - chan_id – channel identifier
- samples –
- np.ndarray[np.int32_t –
- buf – numpy preallocated buffer of type np.ndarray[np.int32_t, ndim=1]
-
Pidev.
daq_get_sample
(chan_id)¶ Get a single data acquistion sample
Parameters: chan_id – channel identifier