Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I want the graph to look like the left one and I want the pendulum to turn from thet _ in to thet _ out.

I want the graph to look like the left one and I want the pendulum to turn from thet_in to thet_out. The pendulum is run by the motor so that it could turn, but i'm not sure why it is not working as expected (the graph produimport numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import solve_ivp
from Pendulum_Animations import animate_pendulum
#Known parameters
g =9.81 #m/s^2
L =1.2 #m
m =20#kg
thet_in =120*(np.pi /180) #starting angle of mechanism (rad)
thet_out =210*(np.pi /180) #Finishing angle (rad)
#Motor constants
T_s =0.69 #Stall Torque, FROM CATALOGUE (Nm)
omega_m =2750*(2* np.pi/60) #No load angular speed (rad/s)
k = T_s / omega_m #motor gradient constant
#Range of gear ratios to try
#G_r =[295.503]
G_r =[320]
#Equation of motion (of a pendulum)
def f_new(t,z, vr):
def f(t, z):
theta = z[0]
omega = z[1]
if theta thet_out:
T_m = vr * k *(thet_out - theta) #motor torque
elif theta > thet_in:
T_m = vr * k *(thet_in - theta)
else:
T_m =0
alpha =(T_m +(m*g*L*np.sin(theta)))/(m*L**2) #+ so will rotate upwards
dz =[omega, alpha]
return dz
return f(t, z)
#Creating events function (to terminate exactly where we specificy)
def my_event(t,z, vr):#t = time, z = state (displacement)
return z[0]- np.pi/2 #returns the first state (displacement)
my_event.terminal = True #solve_ivp will stop when this condition is met
my_event.direction =+1 #controls the way in which the evnt is triggered
#the event will only trigger when the event function output reaches zero in a positive direction
#Solver parameters
T =8 #Time for it to run for (s)
IC =[thet_in,0] # Initial conditions (position in angle, velocity)
t_out =[] #time array
z_out =[] #data array [position, velocity]
#Solvers
for i in range(len(G_r)):
vr = G_r[i] #iterate ranges of gear ratios
sol = solve_ivp(f_new, (0,T), IC, rtol =1e-4, max_step =1e-2, args =(vr,), events = my_event)
t = sol.t
z = sol.y
t_out.append(t)
z_out.append(z)
#animate
animate = True #will only animate when its true
#thet_gr
if animate == True:
thet = z_out[-1]
ani = animate_pendulum(t_out[-1], thet[0,:])
#Plots
fig, ax1= plt.subplots(2)
for i in range(len(t_out)):
ax1[0].plot(t_out[i], z_out[i][0,:], label = str(G_r[i]))
ax1[0].axhline(y = thet_out, linestyle ='-.', label = 'Finishing angle', color = 'red')
ax1[0].set_xlabel('Time (s)')
ax1[0].set_ylabel('Angle (rad)')
ax1[0].legend()
#Velocity
for i in range(len(t_out)):
ax1[1].plot(t_out[i], z_out[i][1,:], label = str(G_r[i]))
ax1[1].set_xlabel('Time (s)')
ax1[1].set_ylabel('Velocity (rad/s)')
ax1[1].legend()ced is not the same). Here is my code:
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions