Skip to content

Instantly share code, notes, and snippets.

@WesleyAC
Created January 2, 2017 05:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WesleyAC/861da6df9b172603536f8b01a9469e79 to your computer and use it in GitHub Desktop.
Save WesleyAC/861da6df9b172603536f8b01a9469e79 to your computer and use it in GitHub Desktop.
A hacky script to generate a plot of a trapezoidal motion profile
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 10, 1000)
pdot = np.piecewise(x, [x < 4, (x >= 4) & (x <= 6), x > 6], [lambda x: x/2, 2, lambda x: -x/2 + 5])
p = []
psum = 0
for v in pdot:
p.append(psum)
psum += v
plt.plot(pdot)
plt.ylim([0,2.5])
plt.show()
plt.plot(p)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment