Repository navigation
Python API Reference
The sf-motion Python API provides a simple interface for configuring, controlling, and monitoring the FOC motor controller. All motor commands are exposed as Python methods.
sf-motion provides plotter channels that can be used to monitor motor variables.
The available channel names are:
| Channel | Description |
|---|---|
ia |
Phase A current |
ib |
Phase B current |
ic |
Phase C current |
i_alpha |
Alpha-axis current |
i_beta |
Beta-axis current |
id |
d-axis current |
iq |
q-axis current |
va |
Phase A voltage |
vb |
Phase B voltage |
vc |
Phase C voltage |
v_alpha |
Alpha-axis voltage |
v_beta |
Beta-axis voltage |
vd |
d-axis voltage |
vq |
q-axis voltage |
e_rad |
Electrical angle |
actual_rpm |
Actual motor speed |
actual_angle |
Actual motor angle |
Is_ref |
Current reference |
rpm_ref |
Speed reference |
pos_ref |
Position reference |
m_angle_rad |
Mechanical angle |
m_angle_rad_comp |
Compensated mechanical angle |
v_bus |
DC bus voltage |
Add a variable to the plotter.
The channel_name parameter can be specified using a plotter channel name if supported by the Python API.
Example:
motor.plotter_add_line('iq')Remove a variable from the plotter.
Example:
motor.plotter_remove_line('iq')Reset the motor controller configuration to the default configuration.
motor.set_default_config()Save the current configuration.
motor.save_config()Set the motor control mode.
motor.set_foc_motor_mode(mode)Read the motor control mode.
mode = motor.get_foc_motor_mode()The available control mode are:
| Control Mode | Description |
|---|---|
| 0 | current control |
| 1 | speed control |
| 2 | position control |
| 5 | openloop mode |
| 6 | disable |
Set the motor pole-pair count.
motor.set_pole_pairs(value)Read the configured pole-pair count.
pole_pairs = motor.get_pole_pairs()Set the motor KV parameter.
motor.set_kv(value)Read the motor KV parameter.
kv = motor.get_kv()Set the motor stator resistance.
motor.set_rs(value)Read the motor stator resistance.
Rs = motor.get_rs()Set the motor d-axis inductance.
motor.set_ld(value)Read the motor d-axis inductance.
Ld = motor.set_ld()Set the motor q-axis inductance.
motor.set_lq(value)Read the motor q-axis inductance.
Lq = motor.set_lq()Set the motor flux linkage.
motor.set_flux_linkage(value)Read the motor flux linkage.
flux_linkage = motor.get_flux_linkage()Set current d-Axis PI gain.
Example:
motor.set_pid_id(0.02, 12, 0)Read current d-Axis PI gain.
Example:
pid_data = motor.get_pid_id()
kp = pid_data['kp']
ki = pid_data['ki']
db = pid_data['deadband']Set current q-Axis PI gain.
Example:
motor.set_pid_iq(0.02, 12, 0)Read current q-Axis PI gain.
Example:
pid_data = motor.get_pid_iq()
kp = pid_data['kp']
ki = pid_data['ki']
db = pid_data['deadband']Set speed PI controller gain and output limit.
Example:
motor.set_pid_speed(0.01, 0.1, 5, 0)Read speed PI controller gain and output limit.
Example:
pid_data = motor.get_pid_speed()
kp = pid_data['kp']
ki = pid_data['ki']
out_max = pid_data['out_max']
db = pid_data['deadband']set_pid_position(<kp:float>, <ki:float>, <kd:float>, <out_max:float>, <deadband:float>, <d_fc:float>)
Set position PID controller gain.
Example:
motor.set_pid_position(4, 0, 0.2, 500, 0.01, 100)Read position PID controller gain.
Example:
pid_data = motor.get_pid_position()
kp = pid_data['kp']
ki = pid_data['ki']
kd = pid_data['kd']
out_max = pid_data['out_max']
db = pid_data['deadband']
derivative_freq_cutoff = pid_data['d_fc']