def run_open_loop(ax, dt, method='time-stepping'): ''' Carry out an open-loop simulation of a DC motor with Coulomb friction given an input signal obtained by the sum of a constant term, a linear term (in time), and a sinusoidal term. ''' from dc_motor import get_motor_parameters T = 2 # simulation time V_b = 0.0 # initial motor input V_a = 0.0 # linear increase in motor input per second V_w = .5 # frequency of the sinusoidal motor input V_A = 1.1 # amplitude of the sinusoidal motor input params = get_motor_parameters('Focchi2013') params.tau_coulomb = 1 # simulate motor with linear+sinusoidal input torque N = int(T / dt) # number of time steps motor = MotorCoulomb(dt, params) # motor.set_state(np.array([0.0, 1e-5])) q = np.zeros(N + 1) dq = np.zeros(N + 1) tau_f = np.zeros(N + 1) tau = np.zeros(N) for i in range(N): tau[i] = V_a * i * dt + V_b + V_A * np.sin(2 * np.pi * V_w * i * dt) motor.simulate_torque(tau[i], method) # motor.simulate(tau[i], method) q[i + 1] = motor.q() dq[i + 1] = motor.dq() tau_f[i] = motor.tau_f / dt tau[i] = motor.tau() # plot motor angle, velocity and current time = np.arange(0.0, T + dt, dt) time = time[:N + 1] alpha = 0.8 ax[0].plot(time, q, label='q ' + method, alpha=alpha) ax[1].plot(time, dq, label='dq ' + method, alpha=alpha) ax[2].plot(time[:-1], tau, label='tau ' + method, alpha=alpha) ax[-1].plot(time, tau_f, '--', label='tau_f ' + method, alpha=alpha) for i in range(len(ax)): ax[i].legend() plt.xlabel('Time [s]')
def run_open_loop(ax, dt, method='time-stepping'): from dc_motor import get_motor_parameters T = 2 # simulation time V_b = 0.0 # initial motor voltage V_a = 0.0 # linear increase in motor voltage per second V_w = .5 V_A = 1.1 params = get_motor_parameters('Focchi2013') params.tau_coulomb = 1 # simulate motor with linear+sinusoidal input torque N = int(T/dt) # number of time steps motor = MotorCoulomb(dt, params) # motor.set_state(np.array([0.0, 1e-5])) q = np.zeros(N+1) dq = np.zeros(N+1) tau_f = np.zeros(N+1) tau = np.zeros(N) for i in range(N): tau[i] = V_a*i*dt + V_b + V_A*np.sin(2*np.pi*V_w*i*dt) motor.simulate_torque(tau[i], method) # motor.simulate(tau[i], method) q[i+1] = motor.q() dq[i+1] = motor.dq() tau_f[i] = motor.tau_f/dt tau[i] = motor.tau() # plot motor angle, velocity and current time = np.arange(0.0, T+dt, dt) time = time[:N+1] alpha = 0.8 ax[0].plot(time, q, label ='q '+method, alpha=alpha) ax[1].plot(time, dq, label ='dq '+method, alpha=alpha) ax[2].plot(time[:-1], tau, label ='tau '+method, alpha=alpha) ax[-1].plot(time, tau_f, '--', label ='tau_f '+method, alpha=alpha) for i in range(len(ax)): ax[i].legend() plt.xlabel('Time [s]')
simulate_coulomb = 0 # flag to decide whether to simulate Coulomb friction motor_name = 'Maxon148877' if motor_name == 'Focchi2013': # gains for motor Focchi2013 kp = 5000.0 # proportional gain kd = 10.0 # derivative gain elif motor_name == 'Maxon148877': kp = .1 # proportional gain kd = .01 # derivative gain ki = 0.0 # integral gain q_b = 1.0 # initial motor angle q_a = 0.0 # linear increase in motor angle per second q_w = 0.0 # frequency of sinusoidal reference motor angle q_A = 0.0 # amplitude of sinusoidal reference motor angle params = get_motor_parameters(motor_name) # create motor and position controller if simulate_coulomb: motor = MotorCoulomb(dt, params) else: motor = Motor(dt, params) controller = PositionControl(kp, kd, ki, dt) # simulate motor with linear+sinusoidal reference motor angle N = int(T / dt) # number of time steps q = np.zeros(N) dq = np.zeros(N) current = np.zeros(N) tau = np.zeros(N) V = np.zeros(N)