()
| 341 | ###################################################################### |
| 342 | |
| 343 | def plot_motion(): |
| 344 | # Nominal motion |
| 345 | positions = gen_positions() |
| 346 | velocities = gen_deriv(positions) |
| 347 | accels = gen_deriv(velocities) |
| 348 | # Updated motion |
| 349 | upd_positions = gen_updated_position(positions) |
| 350 | upd_velocities = gen_deriv(upd_positions) |
| 351 | upd_accels = gen_deriv(upd_velocities) |
| 352 | # Estimated position with model of belt as spring |
| 353 | spring_orig = estimate_spring(positions) |
| 354 | spring_upd = estimate_spring(upd_positions) |
| 355 | spring_diff_orig = [n-o for n, o in zip(spring_orig, positions)] |
| 356 | spring_diff_upd = [n-o for n, o in zip(spring_upd, positions)] |
| 357 | head_velocities = gen_deriv(spring_orig) |
| 358 | head_accels = gen_deriv(head_velocities) |
| 359 | head_upd_velocities = gen_deriv(spring_upd) |
| 360 | head_upd_accels = gen_deriv(head_upd_velocities) |
| 361 | # Build plot |
| 362 | times = [SEG_TIME * i for i in range(len(positions))] |
| 363 | trim_lists(times, velocities, accels, |
| 364 | upd_velocities, upd_velocities, upd_accels, |
| 365 | spring_diff_orig, spring_diff_upd, |
| 366 | head_velocities, head_upd_velocities, |
| 367 | head_accels, head_upd_accels) |
| 368 | fig, (ax1, ax2, ax3) = matplotlib.pyplot.subplots(nrows=3, sharex=True) |
| 369 | ax1.set_title("Simulation: resonance freq=%.1f Hz, damping_ratio=%.3f,\n" |
| 370 | "configured freq=%.1f Hz, damping_ratio = %.3f" |
| 371 | % (SPRING_FREQ, DAMPING_RATIO, CONFIG_FREQ |
| 372 | , CONFIG_DAMPING_RATIO)) |
| 373 | ax1.set_ylabel('Velocity (mm/s)') |
| 374 | ax1.plot(times, upd_velocities, 'r', label='New Velocity', alpha=0.8) |
| 375 | ax1.plot(times, velocities, 'g', label='Nominal Velocity', alpha=0.8) |
| 376 | ax1.plot(times, head_velocities, label='Head Velocity', alpha=0.4) |
| 377 | ax1.plot(times, head_upd_velocities, label='New Head Velocity', alpha=0.4) |
| 378 | fontP = matplotlib.font_manager.FontProperties() |
| 379 | fontP.set_size('x-small') |
| 380 | ax1.legend(loc='best', prop=fontP) |
| 381 | ax1.grid(True) |
| 382 | ax2.set_ylabel('Acceleration (mm/s^2)') |
| 383 | ax2.plot(times, upd_accels, 'r', label='New Accel', alpha=0.8) |
| 384 | ax2.plot(times, accels, 'g', label='Nominal Accel', alpha=0.8) |
| 385 | ax2.plot(times, head_accels, alpha=0.4) |
| 386 | ax2.plot(times, head_upd_accels, alpha=0.4) |
| 387 | ax2.set_ylim([-5. * ACCEL, 5. * ACCEL]) |
| 388 | ax2.legend(loc='best', prop=fontP) |
| 389 | ax2.grid(True) |
| 390 | ax3.set_ylabel('Deviation (mm)') |
| 391 | ax3.plot(times, spring_diff_upd, 'r', label='New', alpha=0.8) |
| 392 | ax3.plot(times, spring_diff_orig, 'g', label='Nominal', alpha=0.8) |
| 393 | ax3.grid(True) |
| 394 | ax3.legend(loc='best', prop=fontP) |
| 395 | ax3.set_xlabel('Time (s)') |
| 396 | return fig |
| 397 | |
| 398 | def setup_matplotlib(output_to_file): |
| 399 | global matplotlib |
no test coverage detected