blob: 9b6ffb197fcf72baa34dfbd2d05d560b70d0e21c [file] [log] [blame]
Austin Schuhf173eb82018-01-20 23:32:30 -08001#!/usr/bin/python3
2
3# This code was used to select the gear ratio for the intake.
4# Run it from the command line and it displays the time required
5# to rotate the intake 180 degrees.
6#
7# Michael Schuh
8# January 20, 2018
9
10import math
11import numpy
12import scipy.integrate
13
14pi = math.pi
15pi2 = 2.0 * pi
16rad_to_deg = 180.0 / pi
17inches_to_meters = 0.0254
18lbs_to_kg = 1.0 / 2.2
19newton_to_lbf = 0.224809
20newton_meters_to_ft_lbs = 0.73756
21run_count = 0
22theta_travel = 0.0
23
24def to_deg(angle):
25 return angle * rad_to_deg
26
27def to_rad(angle):
28 return angle / rad_to_deg
29
30def to_rotations(angle):
31 return angle / pi2
32
33def time_derivative(x, t, voltage, c1, c2, c3):
34 global run_count
35 theta, omega = x
36 dxdt = [omega, -c1 * omega + c3 * math.sin(theta) + c2 * voltage]
37 run_count = run_count + 1
38
39 return dxdt
40
41def get_distal_angle(theta_proximal):
42 # For the proximal angle = -50 degrees, the distal angle is -180 degrees
43 # For the proximal angle = 10 degrees, the distal angle is -90 degrees
44 distal_angle = to_rad(-180.0 - (-50.0 - to_deg(theta_proximal)) * \
45 (180.0 - 90.0) / (50.0 + 10.0))
46 return distal_angle
47
48
49def get_180_degree_time(c1, c2, c3, voltage, gear_ratio, motor_free_speed):
50 global run_count
51 global theta_travel
52
53 if ( True ):
54 # Gravity is assisting the motion.
55 theta_start = 0.0
56 theta_target = pi
57 elif ( False ):
58 # Gravity is assisting the motion.
59 theta_start = 0.0
60 theta_target = -pi
61 elif ( False ):
62 # Gravity is slowing the motion.
63 theta_start = pi
64 theta_target = 0.0
65 elif ( False ):
66 # Gravity is slowing the motion.
67 theta_start = -pi
68 theta_target = 0.0
69 elif ( False ):
70 # This is for the proximal arm motion.
71 theta_start = to_rad(-50.0)
72 theta_target = to_rad(10.0)
73
74 theta_half = 0.5 * (theta_start + theta_target)
75 if theta_start > theta_target:
76 voltage = -voltage
77 theta = theta_start
78 theta_travel = theta_start - theta_target
79 if run_count == 0:
80 print("# Theta Start = %.2f radians End = %.2f Theta travel %.2f "
81 "Theta half = %.2f Voltage = %.2f" % (
82 theta_start, theta_target, theta_travel, theta_half, voltage))
83 print("# Theta Start = %.2f degrees End = %.2f Theta travel %.2f "
84 "Theta half = %.2f Voltage = %.2f" % (
85 to_deg(theta_start), to_deg(theta_target), to_deg(theta_travel),
86 to_deg(theta_half), voltage))
87 omega = 0.0
88 time = 0.0
89 delta_time = 0.01 # time step in seconds
90 for step in range(1, 5000):
91 t = numpy.array([time, time + delta_time])
92 time = time + delta_time
93 x = [theta, omega]
94 angular_acceleration = -c1 * omega + c2 * voltage
95 x_n_plus_1 = scipy.integrate.odeint(time_derivative, x, t,
96 args=(voltage, c1, c2, c3))
97 theta, omega = x_n_plus_1[1]
98
99 if ( False ):
100 print("%4d %8.4f %8.2f %8.4f %8.4f %8.3f "
101 "%8.3f %8.3f %8.3f" % (
102 step, time, theta, omega, angular_acceleration,
103 to_rotations(theta), to_rotations(omega),
104 omega * gear_ratio * 60.0 / pi2,
105 omega * gear_ratio / motor_free_speed))
106 if theta_start < theta_target:
107 # Angle is increasing through the motion.
108 if theta > theta_half:
109 break
110 else:
111 # Angle is decreasing through the motion.
112 if (theta < theta_half):
113 break
114
115 return 2.0 * time
116
117def main():
118 # m/sec^2 Gravity Constant
119 gravity = 9.8
120 # m/sec^2 Gravity Constant - Use 0.0 for the intake. It is horizontal.
121 gravity = 0.0
122 # Volts
123 voltage_nominal = 12
124
125 # Vex 775 Pro motor specs from http://banebots.com/p/M2-RS550-120
126 motor_name = "Vex 775 Pro motor specs from http://banebots.com/p/M2-RS550-120"
127 current_stall = 134 # amps stall current
128 current_no_load = 0.7 # amps no load current
129 torque_stall = 710/1000.0 # N-m Stall Torque
130 speed_no_load_rpm = 18730 # RPM no load speed
131
132 if ( True ):
133 # Bag motor from https://www.vexrobotics.com/217-3351.html
134 motor_name = "Bag motor from https://www.vexrobotics.com/217-3351.html"
135 current_stall = 53.0 # amps stall current
136 current_no_load = 1.8 # amps no load current
137 torque_stall = 0.4 # N-m Stall Torque
138 speed_no_load_rpm = 13180.0 # RPM no load speed
139
140 if ( False ):
141 # Mini CIM motor from https://www.vexrobotics.com/217-3371.html
142 motor_name = "Mini CIM motor from https://www.vexrobotics.com/217-3371.html"
143 current_stall = 89.0 # amps stall current
144 current_no_load = 3.0 # amps no load current
145 torque_stall = 1.4 # N-m Stall Torque
146 speed_no_load_rpm = 5840.0 # RPM no load speed
147
148 # How many motors are we using?
149 num_motors = 1
150
151 # Motor values
152 print("# Motor: %s" % (motor_name))
153 print("# Number of motors: %d" % (num_motors))
154 print("# Stall torque: %.1f n-m" % (torque_stall))
155 print("# Stall current: %.1f amps" % (current_stall))
156 print("# No load current: %.1f amps" % (current_no_load))
157 print("# No load speed: %.0f rpm" % (speed_no_load_rpm))
158
159 # Constants from motor values
160 resistance_motor = voltage_nominal / current_stall
161 speed_no_load_rps = speed_no_load_rpm / 60.0 # Revolutions per second no load speed
162 speed_no_load = speed_no_load_rps * 2.0 * pi
163 Kt = num_motors * torque_stall / current_stall # N-m/A torque constant
164 Kv_rpm = speed_no_load_rpm / (voltage_nominal -
165 resistance_motor * current_no_load) # rpm/V
166 Kv = Kv_rpm * 2.0 * pi / 60.0 # rpm/V
167
168 # Robot Geometry and physics
169 # m Length of arm connected to the robot base
170 length_proximal_arm = inches_to_meters * 47.34
171 # m Length of arm that holds the cube
172 length_distal_arm = inches_to_meters * 44.0
173 # m Length of intake arm from the pivot point to where the big roller contacts a cube.
174 length_intake_arm = inches_to_meters * 9.0
175 mass_cube = 6.0 * lbs_to_kg # Weight of the cube in Kgrams
176 mass_proximal_arm = 5.5 * lbs_to_kg # Weight of proximal arm
177 mass_distal_arm = 3.5 * lbs_to_kg # Weight of distal arm
178 mass_distal = mass_cube + mass_distal_arm
179 mass_proximal = mass_proximal_arm + mass_distal
180 # m Length from arm pivot point to arm CG
181 radius_to_proximal_arm_cg = 22.0 * inches_to_meters
182 # m Length from arm pivot point to arm CG
183 radius_to_distal_arm_cg = 10.0 * inches_to_meters
184
185 radius_to_distal_cg = (length_distal_arm * mass_cube +
186 radius_to_distal_arm_cg * mass_distal_arm) / \
187 mass_distal
188 radius_to_proximal_cg = (length_proximal_arm * mass_distal +
189 radius_to_proximal_arm_cg * mass_proximal_arm) / \
190 mass_proximal
191 J_cube = length_distal_arm * length_distal_arm*mass_cube
192 # Kg m^2 Moment of inertia of the proximal arm
193 J_proximal_arm = radius_to_proximal_arm_cg * radius_to_proximal_arm_cg * \
194 mass_distal_arm
195 # Kg m^2 Moment of inertia distal arm and cube at end of proximal arm.
196 J_distal_arm_and_cube_at_end_of_proximal_arm = length_proximal_arm * \
197 length_proximal_arm * mass_distal
198 # Kg m^2 Moment of inertia of the distal arm
199 J_distal_arm = radius_to_distal_arm_cg * radius_to_distal_arm_cg * mass_distal_arm
200 # Moment of inertia of the arm with the cube on the end
201 J = J_distal_arm_and_cube_at_end_of_proximal_arm + J_proximal_arm
202 # Intake claw
203 J_intake = 0.295 # Kg m^2 Moment of inertia of intake
204 J = J_intake
205
206 gear_ratio = 140.0 # Guess at the gear ratio
207 gear_ratio = 100.0 # Guess at the gear ratio
208 gear_ratio = 90.0 # Guess at the gear ratio
209
210 error_margine = 1.0
211 voltage = 10.0 # voltage for the motor. Assuming a loaded robot so not using 12 V.
212 # It might make sense to use a lower motor frees peed when the voltage is not a full 12 Volts.
213 # motor_free_speed = Kv * voltage
214 motor_free_speed = speed_no_load
215
216 print("# Kt = %f N-m/A\n# Kv_rpm = %f rpm/V\n# Kv = %f radians/V" % (Kt, Kv_rpm, Kv))
217 print("# %.2f Ohms Resistance of the motor " % (resistance_motor))
218 print("# %.2f kg Cube weight" % (mass_cube))
219 print("# %.2f kg Proximal Arm mass" % (mass_proximal_arm))
220 print("# %.2f kg Distal Arm mass" % (mass_distal_arm))
221 print("# %.2f kg Distal Arm and Cube weight" % (mass_distal))
222 print("# %.2f m Length from distal arm pivot point to arm CG" % (
223 radius_to_distal_arm_cg))
224 print("# %.2f m Length from distal arm pivot point to arm and cube cg" % (
225 radius_to_distal_cg))
226 print("# %.2f kg-m^2 Moment of inertia of the cube about the arm pivot point" % (J_cube))
227 print("# %.2f m Length from proximal arm pivot point to arm CG" % (radius_to_proximal_arm_cg))
228 print("# %.2f m Length from proximal arm pivot point to arm and cube cg" % (
229 radius_to_proximal_cg))
230 print("# %.2f m Proximal arm length" % (length_proximal_arm))
231 print("# %.2f m Distal arm length" % (length_distal_arm))
232
233 print("# %.2f kg-m^2 Moment of inertia of the intake about the intake pivot point" % (
234 J_intake))
235 print("# %.2f kg-m^2 Moment of inertia of the distal arm about the arm pivot point" % (
236 J_distal_arm))
237 print("# %.2f kg-m^2 Moment of inertia of the proximal arm about the arm pivot point" % (
238 J_proximal_arm))
239 print("# %.2f kg-m^2 Moment of inertia of the distal arm and cube mass about "
240 "the proximal arm pivot point" % (
241 J_distal_arm_and_cube_at_end_of_proximal_arm))
242 print("# %.2f kg-m^2 Moment of inertia of the intake the intake pivot point "
243 "(J value used in simulation)" % (J))
244 print("# %d Number of motors" % (num_motors))
245
246 print("# %.2f V Motor voltage" % (voltage))
247 for gear_ratio in range(60, 241, 10):
248 c1 = Kt * gear_ratio * gear_ratio / (Kv * resistance_motor * J)
249 c2 = gear_ratio * Kt / (J * resistance_motor)
250 c3 = radius_to_proximal_cg * mass_proximal * gravity / J
251
252 if ( False ):
253 print("# %.8f 1/sec C1 constant" % (c1))
254 print("# %.2f 1/sec C2 constant" % (c2))
255 print("# %.2f 1/(V sec^2) C3 constant" % (c3))
256 print("# %.2f RPM Free speed at motor voltage" % (voltage * Kv_rpm))
257
258 torque_90_degrees = radius_to_distal_cg * mass_distal * gravity
259 voltage_90_degrees = resistance_motor * torque_90_degrees / (gear_ratio * Kt)
260 torque_peak = gear_ratio * num_motors * torque_stall
261 torque_peak_ft_lbs = torque_peak * newton_meters_to_ft_lbs
262 normal_force = torque_peak / length_intake_arm
263 normal_force_lbf = newton_to_lbf * normal_force
264 time_required = get_180_degree_time(c1, c2, c3, voltage,
265 gear_ratio, motor_free_speed)
266 print("Time for %.1f degrees for gear ratio %3.0f is %.2f seconds. "
267 "Peak (stall) torque %3.0f nm %3.0f ft-lb Normal force at intake "
268 "end %3.0f N %2.0f lbf" % \
269 (to_deg(theta_travel), gear_ratio, time_required,
270 torque_peak, torque_peak_ft_lbs, normal_force, normal_force_lbf))
271
272if __name__ == '__main__':
273 main()