Source code for firmware.motor_utils.motor_factory
"""Motor factory module. Contains a factory class to create motor objects based on configuration."""fromtypingimportAnyfromfirmware.bionic_motors.motorsimportBionicMotor,ControlParamsfromfirmware.motor_utils.motor_utilsimportMotorInterfacefromfirmware.robstride_motors.motorsimportRobstrideMotor,RobstrideParams
[docs]@staticmethoddefcreate_motor(motor:str,motor_id:int,control_params:Any,communication_interface:Any)->MotorInterface:ifmotor=="bionic":bionic_params=ControlParams(kp=control_params["kp"],kd=control_params["kd"],)returnBionicMotor(motor_id,bionic_params,communication_interface)elifmotor=="robstride":robstride_params=RobstrideParams(limit_torque=control_params["limit_torque"],cur_kp=control_params["cur_kp"],cur_ki=control_params["cur_ki"],cur_fit_gain=control_params["cur_fit_gain"],limit_spd=control_params["limit_spd"],limit_cur=control_params["limit_cur"],loc_kp=control_params["loc_kp"],spd_kp=control_params["spd_kp"],spd_ki=control_params["spd_ki"],spd_filt_gain=control_params["spd_filt_gain"],)returnRobstrideMotor(motor_id,robstride_params,communication_interface)else:raiseValueError(f"Motor type {motor} not recognized.")