import numpy as np
from [Link] import solve
import [Link] as plt
def main():
# Get user inputs for initial and final conditions
# Eslabón 1
theta0r = float(input("Enter initial angular position in degree: "))
theta0 = [Link](theta0r)
omega0 = float(input("Enter initial angular velocity in radians/s: "))
alpha0 = float(input("Enter initial angular acceleration in radians/s^2: "))
thetafr = float(input("Enter final angular position in degree: "))
thetaf = [Link](thetafr)
omegaf = float(input("Enter final angular velocity in radians/s: "))
alphaf = float(input("Enter final angular acceleration in radians/s^2: "))
# Eslabón 2
theta0r2 = float(input("2 Enter initial angular position in degree: "))
theta02 = [Link](theta0r2)
omega02 = float(input("2 Enter initial angular velocity in radians/s: "))
alpha02 = float(input("2 Enter initial angular acceleration in radians/s^2: "))
thetafr2 = float(input("2 Enter final angular position in degree: "))
thetaf2 = [Link](thetafr2)
omegaf2 = float(input("2 Enter final angular velocity in radians/s: "))
alphaf2 = float(input("2 Enter final angular acceleration in radians/s^2: "))
# Tiempo
t0 = float(input("Enter initial time: "))
tf = float(input("Enter final time: "))
# Longitudes de los eslabones
L = float(input("Enter the length of the arm 1: "))
L2 = float(input("Enter the length of the arm 2: "))
Lg = L / 2
Lg2 = L2 / 2
# Solve for the polynomial coefficients
coefficients1 = solve_motion_equations(theta0, omega0, alpha0, thetaf, omegaf,
alphaf, t0, tf)
coefficients2 = solve_motion_equations(theta02, omega02, alpha02, thetaf2,
omegaf2, alphaf2, t0, tf)
# Print the equations for angular position, velocity, and acceleration Eslabón
1
print(f"Angular Position Equation 1: θ(t) = {coefficients1[0]:.6f} +
{coefficients1[1]:.6f}t + {coefficients1[2]:.6f}t^2 + {coefficients1[3]:.6f}t^3 +
{coefficients1[4]:.6f}t^4 + {coefficients1[5]:.6f}t^5")
print(f"Angular Velocity Equation 1: ω(t) = {coefficients1[1]:.6f} +
{2*coefficients1[2]:.6f}t + {3*coefficients1[3]:.6f}t^2 +
{4*coefficients1[4]:.6f}t^3 + {5*coefficients1[5]:.6f}t^4")
print(f"Angular Acceleration Equation 1: α(t) = {2*coefficients1[2]:.6f} +
{6*coefficients1[3]:.6f}t + {12*coefficients1[4]:.6f}t^2 +
{20*coefficients1[5]:.6f}t^3")
# Print the equations for angular position, velocity, and acceleration Eslabón
2
print(f"Angular Position Equation 2: θ(t) = {coefficients2[0]:.6f} +
{coefficients2[1]:.6f}t + {coefficients2[2]:.6f}t^2 + {coefficients2[3]:.6f}t^3 +
{coefficients2[4]:.6f}t^4 + {coefficients2[5]:.6f}t^5")
print(f"Angular Velocity Equation 2: ω(t) = {coefficients2[1]:.6f} +
{2*coefficients2[2]:.6f}t + {3*coefficients2[3]:.6f}t^2 +
{4*coefficients2[4]:.6f}t^3 + {5*coefficients2[5]:.6f}t^4")
print(f"Angular Acceleration Equation 2: α(t) = {2*coefficients2[2]:.6f} +
{6*coefficients2[3]:.6f}t + {12*coefficients2[4]:.6f}t^2 +
{20*coefficients2[5]:.6f}t^3")
# Plot the graphs for angular position, velocity, and acceleration
plot_motion_graphs(coefficients1, t0, tf, Lg, 'Eslabón 1')
plot_motion_graphs2(coefficients2, t0, tf, Lg2, coefficients1, L)
def solve_motion_equations(theta0, omega0, alpha0, thetaf, omegaf, alphaf, t0, tf):
# Create the matrix using the boundary conditions
M = [Link]([
[1, t0, t0**2, t0**3, t0**4, t0**5],
[0, 1, 2*t0, 3*t0**2, 4*t0**3, 5*t0**4],
[0, 0, 2, 6*t0, 12*t0**2, 20*t0**3],
[1, tf, tf**2, tf**3, tf**4, tf**5],
[0, 1, 2*tf, 3*tf**2, 4*tf**3, 5*tf**4],
[0, 0, 2, 6*tf, 12*tf**2, 20*tf**3]
])
# Create the vector for the boundary conditions
b = [Link]([theta0, omega0, alpha0, thetaf, omegaf, alphaf])
# Solve the linear system for the coefficients
return solve(M, b)
def plot_motion_graphs(coefficients, t0, tf, Lg, title):
# Generate time values for the plots
t_values = [Link](t0, tf, 300)
# Calculate the angular position, velocity, and acceleration values
theta_values = [Link](coefficients[::-1], t_values)
omega_values = [Link]([Link](coefficients[::-1]), t_values)
alpha_values = [Link]([Link](coefficients[::-1], 2), t_values)
# Calculate the linear velocity and acceleration
vx_values = -Lg * omega_values * [Link](theta_values)
vy_values = Lg * omega_values * [Link](theta_values)
ax_values = -Lg * (alpha_values * [Link](theta_values) - omega_values**2 *
[Link](theta_values))
ay_values = Lg * (alpha_values * [Link](theta_values) - omega_values**2 *
[Link](theta_values))
# Calculate magnitudes of linear velocities and accelerations
v_magnitudes = [Link](vx_values**2 + vy_values**2)
a_magnitudes = [Link](ax_values**2 + ay_values**2)
# Find maximum magnitudes and their components
max_v_index = [Link](v_magnitudes)
max_a_index = [Link](a_magnitudes)
max_v_magnitude = v_magnitudes[max_v_index]
max_a_magnitude = a_magnitudes[max_a_index]
max_vx = vx_values[max_v_index]
max_vy = vy_values[max_v_index]
max_ax = ax_values[max_a_index]
max_ay = ay_values[max_a_index]
# Print maximum magnitudes and their components
print(f"Maximum Linear Velocity Magnitude {title}: {max_v_magnitude:.6f} m/s")
print(f"Components at Maximum Linear Velocity {title}: vx = {max_vx:.6f} m/s,
vy = {max_vy:.6f} m/s")
print(f"Maximum Linear Acceleration Magnitude {title}: {max_a_magnitude:.6f}
m/s^2")
print(f"Components at Maximum Linear Acceleration {title}: ax = {max_ax:.6f}
m/s^2, ay = {max_ay:.6f} m/s^2")
# Plot the results for angular motion
fig, axs = [Link](5, 1, figsize=(10, 25))
axs[0].plot(t_values, theta_values, label=f'Angular Position {title} (θ(t))')
axs[1].plot(t_values, omega_values, label=f'Angular Velocity {title} (ω(t))',
color='orange')
axs[2].plot(t_values, alpha_values, label=f'Angular Acceleration {title}
(α(t))', color='red')
axs[3].plot(t_values, v_magnitudes, label=f'Linear Velocity Magnitude {title}',
color='green')
axs[4].plot(t_values, a_magnitudes, label=f'Linear Acceleration Magnitude
{title}', color='purple')
for ax in axs:
[Link]()
[Link](True)
axs[0].set_title(f'Angular Position {title} (θ(t))')
axs[1].set_title(f'Angular Velocity {title} (ω(t))')
axs[2].set_title(f'Angular Acceleration {title} (α(t))')
axs[3].set_title(f'Linear Velocity Magnitude {title}')
axs[4].set_title(f'Linear Acceleration Magnitude {title}')
axs[4].set_xlabel('Time (t)')
plt.tight_layout()
[Link]()
def plot_motion_graphs2(coefficients, t0, tf, Lg2, coefficients1, L):
# Generate time values for the plots
t_values = [Link](t0, tf, 300)
# Calculate the angular position, velocity, and acceleration values
theta_values = [Link](coefficients[::-1], t_values)
omega_values = [Link]([Link](coefficients[::-1]), t_values)
alpha_values = [Link]([Link](coefficients[::-1], 2), t_values)
theta_values1 = [Link](coefficients1[::-1], t_values)
omega_values1 = [Link]([Link](coefficients1[::-1]), t_values)
alpha_values1 = [Link]([Link](coefficients1[::-1], 2), t_values)
# Calculate the linear velocity and acceleration
vx_values = -Lg2 * omega_values * [Link](theta_values) - L * omega_values1 *
[Link](theta_values1)
vy_values = Lg2 * omega_values * [Link](theta_values) + L * omega_values1 *
[Link](theta_values1)
ax_values = -Lg2 * (alpha_values * [Link](theta_values) + omega_values**2 *
[Link](theta_values)) - L * (alpha_values1 * [Link](theta_values1) +
omega_values1**2 * [Link](theta_values1))
ay_values = Lg2 * (alpha_values * [Link](theta_values) - omega_values**2 *
[Link](theta_values)) + L * (alpha_values1 * [Link](theta_values1) -
omega_values1**2 * [Link](theta_values1))
# Calculate magnitudes of linear velocities and accelerations
v_magnitudes = [Link](vx_values**2 + vy_values**2)
a_magnitudes = [Link](ax_values**2 + ay_values**2)
# Find maximum magnitudes and their components
max_v_index = [Link](v_magnitudes)
max_a_index = [Link](a_magnitudes)
max_v_magnitude = v_magnitudes[max_v_index]
max_a_magnitude = a_magnitudes[max_a_index]
max_vx = vx_values[max_v_index]
max_vy = vy_values[max_v_index]
max_ax = ax_values[max_a_index]
max_ay = ay_values[max_a_index]
# Print maximum magnitudes and their components
print(f"Maximum Linear Velocity Magnitude Eslabón 2: {max_v_magnitude:.6f}
m/s")
print(f"Components at Maximum Linear Velocity Eslabón 2: vx = {max_vx:.6f} m/s,
vy = {max_vy:.6f} m/s")
print(f"Maximum Linear Acceleration Magnitude Eslabón 2: {max_a_magnitude:.6f}
m/s^2")
print(f"Components at Maximum Linear Acceleration Eslabón 2: ax = {max_ax:.6f}
m/s^2, ay = {max_ay:.6f} m/s^2")
# Plot the results for angular motion
fig, axs = [Link](5, 1, figsize=(10, 25))
axs[0].plot(t_values, theta_values, label='Angular Position Eslabón 2 (θ(t))')
axs[1].plot(t_values, omega_values, label='Angular Velocity Eslabón 2 (ω(t))',
color='orange')
axs[2].plot(t_values, alpha_values, label='Angular Acceleration Eslabón 2
(α(t))', color='red')
axs[3].plot(t_values, v_magnitudes, label='Linear Velocity Magnitude Eslabón
2', color='green')
axs[4].plot(t_values, a_magnitudes, label='Linear Acceleration Magnitude
Eslabón 2', color='purple')
for ax in axs:
[Link]()
[Link](True)
axs[0].set_title('Angular Position Eslabón 2 (θ(t))')
axs[1].set_title('Angular Velocity Eslabón 2 (ω(t))')
axs[2].set_title('Angular Acceleration Eslabón 2 (α(t))')
axs[3].set_title('Linear Velocity Magnitude Eslabón 2')
axs[4].set_title('Linear Acceleration Magnitude Eslabón 2')
axs[4].set_xlabel('Time (t)')
plt.tight_layout()
[Link]()
if __name__ == '__main__':
main()