Skip to content
Snippets Groups Projects
Commit 8f2e7bd3 authored by ARMAR-DE User's avatar ARMAR-DE User
Browse files

feat: Cleanup, provide linear plot

parent 9aa697de
No related branches found
No related tags found
No related merge requests found
Pipeline #9360 passed
......@@ -97,22 +97,17 @@ def convert_value(
def plot_joint_polar(fig, joint: "Calibration"):
def hrticks(ticks):
ticksk = round(float(ticks) / 1000)
return f"{ticksk}k ticks"
fig.suptitle(f"Range of Motion Analysis {joint.name}", fontsize=16, y=1.1)
fig.set_size_inches(10, 5)
ax = fig.add_subplot(projection="polar") # Previously: 122.
ax.grid(False)
ax.set_theta_zero_location("N")
origin_radius = 0.01
radius = 1
y_low, y_high = joint.joint_limits_rad
if y_low is None or y_high is None:
y_low = -np.pi
y_high = np.pi
def hrticks(ticks, units: bool = True):
unit = "ticks" if units else ""
value = ticks
ks = ""
while True:
value = round(float(value) / 1000)
ks += "k"
if value < 1000:
break
return f"{value}{ks} {unit}"
value_map = {}
nearest_to_zero = None
......@@ -129,24 +124,82 @@ def plot_joint_polar(fig, joint: "Calibration"):
farthest_from_zero = abs(rad_value)
farthest_from_zero_ticks = i
measured_zero_style = {
"color": "green",
"linestyle": "dashed",
"linewidth": 2
}
measured_lo_style = {
"color": "blue",
"linestyle": "dashed",
"linewidth": 2
}
measured_hi_style = {
"color": "red",
"linestyle": "dashed",
"linewidth": 2
}
discontinuity_style = {
"color": "green",
}
absolute_encoder_discontinuity_style = {
"color": "grey",
"linestyle": "dotted"
}
fig.suptitle(f"Range of Motion Analysis {joint.name}", fontsize=16, y=1.1)
fig.set_size_inches(10, 5)
linear_ax = fig.add_subplot(121)
linear_ax.plot(value_map.values(), value_map.keys())
linear_ax.axhline(y=0)
linear_ax.set_xlabel("Raw Encoder Value [Ticks]")
linear_ax.set_ylabel("Joint Angle [rad]")
xticks = range(0, joint.ticks_max + 1, joint.ticks_max // 4)
linear_ax.set_xticks(xticks)
linear_ax.set_xticklabels([hrticks(t, units=False) for t in xticks])
polar_ax = fig.add_subplot(122, projection="polar")
polar_ax.grid(False)
polar_ax.set_theta_zero_location("N")
polar_ax.set_title("Joint Angle [°]", size=11)
origin_radius = 0.01
radius = 1
y_low, y_high = joint.joint_limits_rad
if y_low is None or y_high is None:
y_low = -np.pi
y_high = np.pi
# Zero (actual and corrected) according to absolute encoder.
zero_model_appendix = ""
if joint.measured_zero_ticks is not None:
measured_zero = joint.convert_value(0)
measured_zero_shifted = joint.convert_value(farthest_from_zero_ticks)
ax.vlines([measured_zero], [origin_radius], [radius], 'grey', 'dotted',
linear_ax.axvline(x=0, **absolute_encoder_discontinuity_style)
polar_ax.vlines([measured_zero], [origin_radius], [radius],
label="Zero, abs. enc (0 ticks)",
clip_on=False)
clip_on=False,
**absolute_encoder_discontinuity_style)
if joint.discontinuity_offset != 0:
ax.vlines([measured_zero_shifted], [origin_radius], [radius], 'green',
linear_ax.axvline(x=farthest_from_zero_ticks, **discontinuity_style)
polar_ax.vlines([measured_zero_shifted], [origin_radius], [radius],
label=f"Zero, abs. enc (corrected)",
clip_on=False)
clip_on=False,
**discontinuity_style)
zero_model_appendix = f" ({hrticks(joint.measured_zero_ticks)})"
# Zero according to model.
ax.vlines([joint.convert_value(nearest_to_zero_ticks)], [origin_radius], [radius], 'green', 'dashed',
linear_ax.axvline(x=nearest_to_zero_ticks, **measured_zero_style)
polar_ax.vlines([joint.convert_value(nearest_to_zero_ticks)], [origin_radius], [radius],
label=f"Zero, model{zero_model_appendix}",
clip_on=False, linewidth=2.0)
clip_on=False, **measured_zero_style)
# Joint limits (measured).
if joint.joint_limits_degree != (None, None):
......@@ -155,12 +208,15 @@ def plot_joint_polar(fig, joint: "Calibration"):
y_low_m = joint.convert_value(y_low_raw_t)
y_high_m = joint.convert_value(y_high_raw_t)
ax.vlines([y_low_m], [origin_radius], [radius], 'blue', 'dashed',
linear_ax.axvline(x=joint.measured_lo_ticks, **measured_lo_style)
polar_ax.vlines([y_low_m], [origin_radius], [radius],
label=f"Joint limit low ({hrticks(y_low_raw_t)})",
clip_on=False, linewidth=2.0)
ax.vlines([y_high_m], [origin_radius], [radius], 'red', 'dashed',
clip_on=False, **measured_lo_style)
linear_ax.axvline(x=joint.measured_hi_ticks, **measured_hi_style)
polar_ax.vlines([y_high_m], [origin_radius], [radius],
label=f"Joint limit high ({hrticks(y_high_raw_t)})",
clip_on=False, linewidth=2.0)
clip_on=False, **measured_hi_style)
# Labels and ticks.
angles = list(np.linspace(-180, 180, 24 + 1))
......@@ -177,22 +233,15 @@ def plot_joint_polar(fig, joint: "Calibration"):
angle_xticklabels = f"{int(angle)}°"
angles_xticks.append(angle_xticks)
angles_xticklabels.append(angle_xticklabels)
ax.set_xticks(angles_xticks)
ax.set_xticklabels(angles_xticklabels)
ax.set_yticklabels([])
ax.set_xlim(y_low, y_high)
ax.set_ylim(0, radius)
#ax2 = fig.add_subplot(121)
#ax2.plot(value_map.values(), value_map.keys())
#ax2.axhline(y=0)
#ax2.axvline(x=joint.measured_lo_ticks, color="blue", linestyle="dashed")
#ax2.axvline(x=joint.measured_hi_ticks, color="red", linestyle="dashed")
#ax2.axvline(x=joint.measured_zero_ticks, color="green", linestyle="dashed")
polar_ax.set_xticks(angles_xticks)
polar_ax.set_xticklabels(angles_xticklabels)
polar_ax.set_yticklabels([])
polar_ax.set_xlim(y_low, y_high)
polar_ax.set_ylim(0, radius)
# Legend.
angle = np.deg2rad(45)
ax.legend(loc="lower left", bbox_to_anchor=(.75 + np.cos(angle) / 2, .5 + np.sin(angle) / 2))
polar_ax.legend(loc="lower left", bbox_to_anchor=(.75 + np.cos(angle) / 2, .5 + np.sin(angle) / 2))
def inspect(joint: "Calibration"):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment