Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jrbergen/2669d84c2e2849d3855d2366f937b7e9 to your computer and use it in GitHub Desktop.
Save jrbergen/2669d84c2e2849d3855d2366f937b7e9 to your computer and use it in GitHub Desktop.
Steering throttle snippet stackoverflow question
# Refers to https://stackoverflow.com/questions/67591201/iterating-over-a-numpy-array-returns-only-the-last-item/67591403?noredirect=1#comment119478801_67591403
import numpy as np
def case2(samples: int = 50,
time_interval: int = 5,
time_req: float = 5.0,
steering_ampl: int = 900,
throttle_ampl: int = 1050,
steering_offset: int = 1024):
vector = np.vectorize(np.int)
t = np.linspace(0, time_interval, samples)
vec_steering = vector(
steering_ampl * np.sin(2 * (np.pi) * t / time_req) + steering_offset
)
# throttle_vec = throttle_ampl * np.ones(vec_steering.size,
# dtype=np.int)
# return np.vstack([throttle_vec, vec_steering])
return [(throttle_ampl, steering,) for steering in vec_steering]
throttle_steering_tuples = case2()
print(throttle_steering_tuples)
# for me it prints:
# [(1050, 1024), (1050, 1139), (1050, 1252), (1050, 1361), (1050, 1465), (1050, 1562), (1050, 1650), (1050, 1727), (1050, 1793), (1050, 1846), (1050, 1886), (1050, 1912), (1050, 1923), (1050, 1919), (1050, 1901), (1050, 1868), (1050, 1821), (1050, 1762), (1050, 1690), (1050, 1607), (1050, 1514), (1050, 1414), (1050, 1307), (1050, 1196), (1050, 1081), (1050, 966), (1050, 851), (1050, 740), (1050, 633), (1050, 533), (1050, 440), (1050, 357), (1050, 285), (1050, 226), (1050, 179), (1050, 146), (1050, 128), (1050, 124), (1050, 135), (1050, 161), (1050, 201), (1050, 254), (1050, 320), (1050, 397), (1050, 485), (1050, 582), (1050, 686), (1050, 795), (1050, 908), (1050, 1023)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment