forked from kyleschultz0/hebi_arm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrajectory_functions.py
67 lines (59 loc) · 2.02 KB
/
trajectory_functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import pandas as pd
import os
import glob
import numpy as np
#def initialize_trajectory(frequency):
# retval = os.getcwd()
# print("Current working directory", retval)
# os.chdir("trajectories")
# if os.path.exists("combined_trajectories.csv"):
# os.remove("combined_trajectories.csv")
# else:
# print("The file does not exist")
# extension = 'csv'
# all_filenames = [i for i in glob.glob('*.{}'.format(extension))]
# print(all_filenames)
# #combine all files in the list
# combined_csv = pd.concat([pd.read_csv(f) for f in all_filenames ], sort=False, ignore_index=True)
# length = len(combined_csv)
# times = np.linspace(0, (1/frequency)*length, length, endpoint=False)
# timesdf = pd.DataFrame(times, columns = ['t'])
# print("Times", timesdf)
# print("CSV", combined_csv)
# # combined_csv_times = pd.concat([timesdf, combined_csv], sort=False)
# combined_csv['t'] = timesdf
# print(combined_csv)
# #export to csv
# combined_csv.to_csv( "combined_trajectories.csv", index=False, encoding='utf-8-sig')
# os.chdir('..')
def initialize_trajectory(filepath):
df = pd.read_csv(filepath, names=["t", "theta1", "theta2"])
# print(df)
return(df)
def trajectoryold(t, filepath):
df = pd.read_csv(filepath)
tTraj = df.t
theta1 = df.theta1
theta2 = df.theta2
theta1 = np.interp(t, tTraj, theta1)
theta2 = np.interp(t, tTraj, theta2)
theta = np.array([theta1, theta2])
print("Trajectory output:", theta)
return theta
def trajectory(t, df):
#df = pd.read_csv(filepath,
# names=["t", "omega1", "omega2", "theta1", "theta2"])
# print(df)
tTraj = df.t
theta1 = df.theta1
theta2 = df.theta2
theta1d = np.interp(t, tTraj, theta1)
theta2d = np.interp(t, tTraj, theta2)
theta = np.array([theta1d, theta2d])
return theta
# to test functions:
if __name__ == "__main__":
t, theta_d, omega_d = trajectory(1, "trajectories/cstar_20_20.csv")
print(t)
print(theta_d)
print(omega_d)