Skip to content

Commit

Permalink
ruff fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nim65s committed Aug 26, 2024
1 parent b68a3ee commit 2b7e12a
Show file tree
Hide file tree
Showing 16 changed files with 73 additions and 110 deletions.
9 changes: 4 additions & 5 deletions demo/demo_quadruped.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,18 +183,17 @@
com_acc_des[:, i] = comTask.getDesiredAcceleration

if i % PRINT_N == 0:
print("Time %.3f" % (t))
print(f"Time {t:.3f}")
print("\tNormal forces: ", end=" ")
for contact in contacts:
if invdyn.checkContact(contact.name, sol):
f = invdyn.getContactForce(contact.name, sol)
print("%4.1f" % (contact.getNormalForce(f)), end=" ")
print(f"{contact.getNormalForce(f):4.1f}", end=" ")

print(
"\n\ttracking err %s: %.3f"
% (comTask.name.ljust(20, "."), norm(comTask.position_error, 2))
"\n\ttracking err {}: {:.3f}".format(comTask.name.ljust(20, "."), norm(comTask.position_error, 2))
)
print("\t||v||: %.3f\t ||dv||: %.3f" % (norm(v, 2), norm(dv)))
print(f"\t||v||: {norm(v, 2):.3f}\t ||dv||: {norm(dv):.3f}")

v_mean = v + 0.5 * dt * dv
v += dt * dv
Expand Down
2 changes: 1 addition & 1 deletion demo/demo_tsid_talos_gripper_closed_kinematic_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
dv = invdyn.getAccelerations(sol)

if i % PRINT_N == 0:
print("Time %.3f" % (t))
print(f"Time {t:.3f}")

v_mean = v + 0.5 * dt * dv
v += dt * dv
Expand Down
7 changes: 3 additions & 4 deletions exercizes/ex_0_ur5_joint_space_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,17 @@
HQPData = formulation.computeProblemData(t, q[:, i], v[:, i])
sol = solver.solve(HQPData)
if sol.status != 0:
print("Time %.3f QP problem could not be solved! Error code:" % t, sol.status)
print(f"Time {t:.3f} QP problem could not be solved! Error code:", sol.status)
break

tau[:, i] = formulation.getActuatorForces(sol)
dv[:, i] = formulation.getAccelerations(sol)
dv_des[:, i] = postureTask.getDesiredAcceleration

if i % conf.PRINT_N == 0:
print("Time %.3f" % (t))
print(f"Time {t:.3f}")
print(
"\ttracking err %s: %.3f"
% (postureTask.name.ljust(20, "."), norm(postureTask.position_error, 2))
"\ttracking err {}: {:.3f}".format(postureTask.name.ljust(20, "."), norm(postureTask.position_error, 2))
)

# numerical integration
Expand Down
13 changes: 5 additions & 8 deletions exercizes/ex_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,23 @@
com_acc_des[:, i] = tsid.comTask.getDesiredAcceleration

if i % conf.PRINT_N == 0:
print("Time %.3f" % (t))
print(f"Time {t:.3f}")
if tsid.formulation.checkContact(tsid.contactRF.name, sol):
f = tsid.formulation.getContactForce(tsid.contactRF.name, sol)
print(
"\tnormal force %s: %.1f"
% (tsid.contactRF.name.ljust(20, "."), tsid.contactRF.getNormalForce(f))
"\tnormal force {}: {:.1f}".format(tsid.contactRF.name.ljust(20, "."), tsid.contactRF.getNormalForce(f))
)

if tsid.formulation.checkContact(tsid.contactLF.name, sol):
f = tsid.formulation.getContactForce(tsid.contactLF.name, sol)
print(
"\tnormal force %s: %.1f"
% (tsid.contactLF.name.ljust(20, "."), tsid.contactLF.getNormalForce(f))
"\tnormal force {}: {:.1f}".format(tsid.contactLF.name.ljust(20, "."), tsid.contactLF.getNormalForce(f))
)

print(
"\ttracking err %s: %.3f"
% (tsid.comTask.name.ljust(20, "."), norm(tsid.comTask.position_error, 2))
"\ttracking err {}: {:.3f}".format(tsid.comTask.name.ljust(20, "."), norm(tsid.comTask.position_error, 2))
)
print("\t||v||: %.3f\t ||dv||: %.3f" % (norm(v, 2), norm(dv)))
print(f"\t||v||: {norm(v, 2):.3f}\t ||dv||: {norm(dv):.3f}")

q, v = tsid.integrate_dv(q, v, dv, conf.dt)
t += conf.dt
Expand Down
11 changes: 5 additions & 6 deletions exercizes/ex_1_ur5.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@

sol = tsid.solver.solve(HQPData)
if sol.status != 0:
print(("Time %.3f QP problem could not be solved! Error code:" % t, sol.status))
print((f"Time {t:.3f} QP problem could not be solved! Error code:", sol.status))
break

tau[:, i] = tsid.formulation.getActuatorForces(sol)
Expand All @@ -89,20 +89,19 @@
ee_acc_des[:, i] = tsid.eeTask.getDesiredAcceleration[:3]

if i % conf.PRINT_N == 0:
print("Time %.3f" % (t))
print(f"Time {t:.3f}")
print(
"\ttracking err %s: %.3f"
% (tsid.eeTask.name.ljust(20, "."), norm(tsid.eeTask.position_error, 2))
"\ttracking err {}: {:.3f}".format(tsid.eeTask.name.ljust(20, "."), norm(tsid.eeTask.position_error, 2))
)

q[:, i + 1], v[:, i + 1] = tsid.integrate_dv(q[:, i], v[:, i], dv, conf.dt)
t += conf.dt

if i % conf.DISPLAY_N == 0:
tsid.robot_display.display(q[:, i])
tsid.gui.applyConfiguration("world/ee", ee_pos[:, i].tolist() + [0, 0, 0, 1.0])
tsid.gui.applyConfiguration("world/ee", [*ee_pos[:, i].tolist(), 0, 0, 0, 1.0])
tsid.gui.applyConfiguration(
"world/ee_ref", ee_pos_ref[:, i].tolist() + [0, 0, 0, 1.0]
"world/ee_ref", [*ee_pos_ref[:, i].tolist(), 0, 0, 0, 1.0]
)

time_spent = time.time() - time_start
Expand Down
13 changes: 5 additions & 8 deletions exercizes/ex_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,23 @@
com_acc_des[:, i] = tsid.comTask.getDesiredAcceleration

if i % conf.PRINT_N == 0:
print("Time %.3f" % (t))
print(f"Time {t:.3f}")
if tsid.formulation.checkContact(tsid.contactRF.name, sol):
f = tsid.formulation.getContactForce(tsid.contactRF.name, sol)
print(
"\tnormal force %s: %.1f"
% (tsid.contactRF.name.ljust(20, "."), tsid.contactRF.getNormalForce(f))
"\tnormal force {}: {:.1f}".format(tsid.contactRF.name.ljust(20, "."), tsid.contactRF.getNormalForce(f))
)

if tsid.formulation.checkContact(tsid.contactLF.name, sol):
f = tsid.formulation.getContactForce(tsid.contactLF.name, sol)
print(
"\tnormal force %s: %.1f"
% (tsid.contactLF.name.ljust(20, "."), tsid.contactLF.getNormalForce(f))
"\tnormal force {}: {:.1f}".format(tsid.contactLF.name.ljust(20, "."), tsid.contactLF.getNormalForce(f))
)

print(
"\ttracking err %s: %.3f"
% (tsid.comTask.name.ljust(20, "."), norm(tsid.comTask.position_error, 2))
"\ttracking err {}: {:.3f}".format(tsid.comTask.name.ljust(20, "."), norm(tsid.comTask.position_error, 2))
)
print("\t||v||: %.3f\t ||dv||: %.3f" % (norm(v, 2), norm(dv)))
print(f"\t||v||: {norm(v, 2):.3f}\t ||dv||: {norm(dv):.3f}")

q, v = tsid.integrate_dv(q, v, dv, conf.dt)
t += conf.dt
Expand Down
15 changes: 7 additions & 8 deletions exercizes/ex_3_biped_balance_with_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self, master, name, from_, to, tickinterval, length, orient, comman
for i in range(3):
self.s[i] = Scale(
master,
label="%s %s" % (name, AXES[i]),
label=f"{name} {AXES[i]}",
from_=from_[i],
to=to[i],
tickinterval=tickinterval[i],
Expand All @@ -45,7 +45,7 @@ class Entry3d:
def __init__(self, master, name):
self.s = 3 * [None]
for i in range(3):
Label(master, text="%s %s" % (name, AXES[i])).pack() # side=tk.TOP)
Label(master, text=f"{name} {AXES[i]}").pack() # side=tk.TOP)
self.s[i] = Entry(master, width=5)
self.s[i].pack() # side=tk.BOTTOM)
separator = Frame(height=1, bd=1, relief=tk.SUNKEN)
Expand Down Expand Up @@ -222,10 +222,10 @@ def run_simu():
x_lf_ref = tsid.trajLF.getSample(t).pos()[:3]
x_rf_ref = tsid.trajRF.getSample(t).pos()[:3]
vizutils.applyViewerConfiguration(
tsid.viz, "world/com", x_com.tolist() + [0, 0, 0, 1.0]
tsid.viz, "world/com", [*x_com.tolist(), 0, 0, 0, 1.0]
)
vizutils.applyViewerConfiguration(
tsid.viz, "world/com_ref", x_com_ref.tolist() + [0, 0, 0, 1.0]
tsid.viz, "world/com_ref", [*x_com_ref.tolist(), 0, 0, 0, 1.0]
)
vizutils.applyViewerConfiguration(
tsid.viz, "world/rf", pin.SE3ToXYZQUATtuple(H_rf)
Expand All @@ -234,16 +234,15 @@ def run_simu():
tsid.viz, "world/lf", pin.SE3ToXYZQUATtuple(H_lf)
)
vizutils.applyViewerConfiguration(
tsid.viz, "world/rf_ref", x_rf_ref.tolist() + [0, 0, 0, 1.0]
tsid.viz, "world/rf_ref", [*x_rf_ref.tolist(), 0, 0, 0, 1.0]
)
vizutils.applyViewerConfiguration(
tsid.viz, "world/lf_ref", x_lf_ref.tolist() + [0, 0, 0, 1.0]
tsid.viz, "world/lf_ref", [*x_lf_ref.tolist(), 0, 0, 0, 1.0]
)

if i % 1000 == 0:
print(
"Average loop time: %.1f (expected is %.1f)"
% (1e3 * time_avg, 1e3 * conf.dt)
f"Average loop time: {1e3 * time_avg:.1f} (expected is {1e3 * conf.dt:.1f})"
)

time_spent = time.time() - time_start
Expand Down
18 changes: 7 additions & 11 deletions exercizes/ex_4_walking.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@
elif i > 0 and i < N - 1:
if contact_phase[i] != contact_phase[i - 1]:
print(
"Time %.3f Changing contact phase from %s to %s"
% (t, contact_phase[i - 1], contact_phase[i])
f"Time {t:.3f} Changing contact phase from {contact_phase[i - 1]} to {contact_phase[i]}"
)
if contact_phase[i] == "left":
tsid_biped.add_contact_LF()
Expand All @@ -151,7 +150,7 @@
print("QP problem could not be solved! Error code:", sol.status)
break
if norm(v, 2) > 40.0:
print("Time %.3f Velocities are too high, stop everything!" % (t), norm(v))
print(f"Time {t:.3f} Velocities are too high, stop everything!", norm(v))
break

if i > 0:
Expand Down Expand Up @@ -190,33 +189,30 @@
cop_LF[1, i] = -f_LF[3, i] / f_LF[2, i]

if i % conf.PRINT_N == 0:
print("Time %.3f" % (t))
print(f"Time {t:.3f}")
if (
tsid_biped.formulation.checkContact(tsid_biped.contactRF.name, sol)
and i >= 0
):
print(
"\tnormal force %s: %.1f"
% (tsid_biped.contactRF.name.ljust(20, "."), f_RF[2, i])
"\tnormal force {}: {:.1f}".format(tsid_biped.contactRF.name.ljust(20, "."), f_RF[2, i])
)

if (
tsid_biped.formulation.checkContact(tsid_biped.contactLF.name, sol)
and i >= 0
):
print(
"\tnormal force %s: %.1f"
% (tsid_biped.contactLF.name.ljust(20, "."), f_LF[2, i])
"\tnormal force {}: {:.1f}".format(tsid_biped.contactLF.name.ljust(20, "."), f_LF[2, i])
)

print(
"\ttracking err %s: %.3f"
% (
"\ttracking err {}: {:.3f}".format(
tsid_biped.comTask.name.ljust(20, "."),
norm(tsid_biped.comTask.position_error, 2),
)
)
print("\t||v||: %.3f\t ||dv||: %.3f" % (norm(v, 2), norm(dv)))
print(f"\t||v||: {norm(v, 2):.3f}\t ||dv||: {norm(dv):.3f}")

q, v = tsid_biped.integrate_dv(q, v, dv, conf.dt)
t += conf.dt
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"cells": [
"cells": [
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -264,18 +264,17 @@
" HQPData = formulation.computeProblemData(t, q[:, i], v[:, i])\n",
" sol = solver.solve(HQPData)\n",
" if sol.status != 0:\n",
" print(\"Time %.3f QP problem could not be solved! Error code:\" % t, sol.status)\n",
" print(f\"Time {t:.3f} QP problem could not be solved! Error code:\", sol.status)\n",
" break\n",
"\n",
" tau[:, i] = formulation.getActuatorForces(sol)\n",
" dv[:, i] = formulation.getAccelerations(sol)\n",
" dv_des[:, i] = postureTask.getDesiredAcceleration\n",
"\n",
" if i % conf.PRINT_N == 0:\n",
" print(\"Time %.3f\" % (t))\n",
" print(f\"Time {t:.3f}\")\n",
" print(\n",
" \"\\ttracking err %s: %.3f\"\n",
" % (postureTask.name.ljust(20, \".\"), norm(postureTask.position_error, 2))\n",
" \"\\ttracking err {}: {:.3f}\".format(postureTask.name.ljust(20, \".\"), norm(postureTask.position_error, 2))\n",
" )\n",
"\n",
" # numerical integration\n",
Expand Down
15 changes: 6 additions & 9 deletions exercizes/notebooks/ex_1_com_sin_track_talos.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"cells": [
"cells": [
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -775,26 +775,23 @@
" com_acc_des[:, i] = comTask.getDesiredAcceleration\n",
"\n",
" if i % PRINT_N == 0:\n",
" print(\"Time %.3f\" % t)\n",
" print(f\"Time {t:.3f}\")\n",
" if invdyn.checkContact(contactRF.name, sol):\n",
" f = invdyn.getContactForce(contactRF.name, sol)\n",
" print(\n",
" \"\\tnormal force %s: %.1f\"\n",
" % (contactRF.name.ljust(20, \".\"), contactRF.getNormalForce(f))\n",
" \"\\tnormal force {}: {:.1f}\".format(contactRF.name.ljust(20, \".\"), contactRF.getNormalForce(f))\n",
" )\n",
"\n",
" if invdyn.checkContact(contactLF.name, sol):\n",
" f = invdyn.getContactForce(contactLF.name, sol)\n",
" print(\n",
" \"\\tnormal force %s: %.1f\"\n",
" % (contactLF.name.ljust(20, \".\"), contactLF.getNormalForce(f))\n",
" \"\\tnormal force {}: {:.1f}\".format(contactLF.name.ljust(20, \".\"), contactLF.getNormalForce(f))\n",
" )\n",
"\n",
" print(\n",
" \"\\ttracking err %s: %.3f\"\n",
" % (comTask.name.ljust(20, \".\"), norm(comTask.position_error, 2))\n",
" \"\\ttracking err {}: {:.3f}\".format(comTask.name.ljust(20, \".\"), norm(comTask.position_error, 2))\n",
" )\n",
" print(\"\\t||v||: %.3f\\t ||dv||: %.3f\" % (norm(v, 2), norm(dv)))\n",
" print(f\"\\t||v||: {norm(v, 2):.3f}\\t ||dv||: {norm(dv):.3f}\")\n",
"\n",
" v_mean = v + 0.5 * dt * dv\n",
" v += dt * dv\n",
Expand Down
10 changes: 5 additions & 5 deletions exercizes/notebooks/ex_3_biped_balance_with_gui.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"cells": [
"cells": [
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -121,10 +121,10 @@
" x_lf_ref = tsid.trajLF.getSample(t).pos()[:3]\n",
" x_rf_ref = tsid.trajRF.getSample(t).pos()[:3]\n",
" vizutils.applyViewerConfiguration(\n",
" tsid.viz, \"world/com\", x_com.tolist() + [0, 0, 0, 1.0]\n",
" tsid.viz, \"world/com\", [*x_com.tolist(), 0, 0, 0, 1.0]\n",
" )\n",
" vizutils.applyViewerConfiguration(\n",
" tsid.viz, \"world/com_ref\", x_com_ref.tolist() + [0, 0, 0, 1.0]\n",
" tsid.viz, \"world/com_ref\", [*x_com_ref.tolist(), 0, 0, 0, 1.0]\n",
" )\n",
" vizutils.applyViewerConfiguration(\n",
" tsid.viz, \"world/rf\", pin.SE3ToXYZQUATtuple(H_rf)\n",
Expand All @@ -133,10 +133,10 @@
" tsid.viz, \"world/lf\", pin.SE3ToXYZQUATtuple(H_lf)\n",
" )\n",
" vizutils.applyViewerConfiguration(\n",
" tsid.viz, \"world/rf_ref\", x_rf_ref.tolist() + [0, 0, 0, 1.0]\n",
" tsid.viz, \"world/rf_ref\", [*x_rf_ref.tolist(), 0, 0, 0, 1.0]\n",
" )\n",
" vizutils.applyViewerConfiguration(\n",
" tsid.viz, \"world/lf_ref\", x_lf_ref.tolist() + [0, 0, 0, 1.0]\n",
" tsid.viz, \"world/lf_ref\", [*x_lf_ref.tolist(), 0, 0, 0, 1.0]\n",
" )\n",
"\n",
" time_spent = time.time() - time_start\n",
Expand Down
2 changes: 1 addition & 1 deletion exercizes/plot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def movePlotSpines(ax, spinesPos):
def setAxisFontSize(ax, size):
for label in ax.get_xticklabels() + ax.get_yticklabels():
label.set_fontsize(size)
label.set_bbox(dict(facecolor="white", edgecolor="None", alpha=0.65))
label.set_bbox({"facecolor": "white", "edgecolor": "None", "alpha": 0.65})


mpl.rcdefaults()
Expand Down
Loading

0 comments on commit 2b7e12a

Please sign in to comment.