diff --git a/python/abb_egm_pyclient/abb_egm_pyclient/feedback/control_final.py b/python/abb_egm_pyclient/abb_egm_pyclient/feedback/control_final.py index 215e2987c49749717a9b6358ad165203ac29a9e5..96eb26c9f5b95c7e4b4bad3819230ab50e3ab0e5 100644 --- a/python/abb_egm_pyclient/abb_egm_pyclient/feedback/control_final.py +++ b/python/abb_egm_pyclient/abb_egm_pyclient/feedback/control_final.py @@ -85,10 +85,15 @@ timestamp = time.time() cutting = False traj_samples = len(p1[:, 0]) +# arrays to store the results for later plotting +log_realPose_R = np.zeros((traj_samples, 6)) +log_compPose_R = np.zeros((traj_samples, 6)) +log_realJoints_R = np.zeros((traj_samples, 7)) +log_compJoints_R = np.zeros((traj_samples, 7)) -print("\n Force control only to tension the wire...") - +log_force = np.zeros((traj_samples, 1)) +print("\n Force control only to tension the wire...") while True and arduino.isOpen(): @@ -164,6 +169,7 @@ while True and arduino.isOpen(): joint7 = robot_msg_R.feedBack.externalJoints.joints[0] conf_R.insert(2, joint7) jointAngles_R = np.radians(np.array(conf_R)) + log_realJoints_R[i, :] = jointAngles_R # compute the resulting jointVelocities if i > 0: @@ -181,12 +187,16 @@ while True and arduino.isOpen(): yumi_left.process() yumi_right.set_jointValues(jointAngles_R, jointVelocities_R) + log_realPose_R[i, :] = yumi_right.get_pose() yumi_right.set_desPoseVel(desPose_R, desVelocities_R) yumi_right.set_force(force) yumi_right.process() + log_compPose_R[i, :] = yumi_right.get_pose() + log_force[i, :] = force ik_jointAngles_L = yumi_left.get_newJointValues() # computed joint values from IK ik_jointAngles_R = yumi_right.get_newJointValues() # computed joint values from IK + log_compJoints_R[i, :] = ik_jointAngles_R # transform to degrees as egm wants it des_conf_L = np.degrees(ik_jointAngles_L) @@ -234,4 +244,8 @@ while n < 10: n += 1 time.sleep(0.1) else: - raise TimeoutError(f"Joint positions for the left arm did not converge.") \ No newline at end of file + raise TimeoutError(f"Joint positions for the left arm did not converge.") + + +experimentLogs = np.hstack((p2, phi_delta, log_compPose_R, log_realPose_R, log_compJoints_R, log_realJoints_R, log_force)) +np.save('./data/experimentLogs', experimentLogs) \ No newline at end of file diff --git a/python/experiment/plots.py b/python/experiment/plots.py new file mode 100644 index 0000000000000000000000000000000000000000..2c1b0dd0df3ef0adfe76ee002bd01bfe25b74a1e --- /dev/null +++ b/python/experiment/plots.py @@ -0,0 +1,71 @@ +from cProfile import label +import numpy as np +import matplotlib.pyplot as plt + + +try: + data = np.load('data/experimentLogs.npy') +except FileNotFoundError: + print('It seems like you need to run the script first that generate the requested data') + +# p2, phi_delta, log_compPose_R, log_realPose_R, log_compJoints_R, log_realJoints_R, force +desPose = data[:, 0:6] +compPose = data[:, 6:12] +realPose = data[:, 12:18] +compJoints = data[:, 8:25] +realJoints = data[2:, 5:32] +force = data[:, 32:33] +noSamples = len(force) + +time = np.linspace(0, round(1.0/80.0 * noSamples), num=noSamples) +#time.shape = (time.size//1, 1) + + + +fig = plt.figure() + +ax1 = fig.add_subplot(121) +ax1.plot(time, force[:, 0]) +ax1.set_title('force') +ax1.set_ylabel('N') +ax1.set_xlabel('s') + +ax2 = fig.add_subplot(122) +ax2.plot(time, compJoints[:, 0], label="J1") +ax2.plot(time, compJoints[:, 1], label="J2") +ax2.plot(time, compJoints[:, 2], label="J3") +ax2.plot(time, compJoints[:, 3], label="J4") + +ax2.plot(time[0:-2], realJoints[:, 0], label="J1", linestyle="dashed") +ax2.plot(time[0:-2], realJoints[:, 1], label="J2", linestyle="dashed") +ax2.plot(time[0:-2], realJoints[:, 2], label="J3", linestyle="dashed") +ax2.plot(time[0:-2], realJoints[:, 3], label="J4", linestyle="dashed") +ax2.set_title('joint angles') +ax2.set_ylabel('rad') +ax2.set_xlabel('s') +ax2.legend() + + +fig = plt.figure() +ax = fig.add_subplot(111, projection='3d') +ax.plot(desPose[1:-1, 0], desPose[1:-1, 1], desPose[1:-1, 2], label="desPose") +ax.plot(compPose[1:-1, 0], compPose[1:-1, 1], compPose[1:-1, 2], label="compPose") +ax.plot(realPose[1:-1, 0], realPose[1:-1, 1], realPose[1:-1, 2], label="realPose") +ax.set_ylabel('y') +ax.set_xlabel('x') +ax.set_zlabel('z') +ax.set_title('trajectory right arm') +ax.legend() + + + + + + + + + +""" axs[1, 0].set_title('Axis [1, 0]') +axs[1, 1].plot(x, -y, 'tab:red') +axs[1, 1].set_title('Axis [1, 1]') """ +plt.show() \ No newline at end of file