Skip to content

Commit d172cad

Browse files
authored
Merge pull request #183 from Steakkk/master
[WIP] Actualized actuators in pyomecaman
2 parents 73c788d + 6f9592a commit d172cad

File tree

8 files changed

+415
-363
lines changed

8 files changed

+415
-363
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ language: cpp
22
matrix:
33
include:
44
- os: linux
5-
dist: bionic
5+
dist: focal
66
compiler: gcc
77
env:
88
- COMPILER=gcc
@@ -39,7 +39,7 @@ before_install:
3939
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
4040
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y;
4141
sudo apt update;
42-
sudo apt install gcc-6 g++-6 -y;
42+
sudo apt install gcc g++ -y;
4343
fi
4444

4545
install:

binding/python3/CMakeLists.txt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,8 @@ INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/${BIORBD_NAME}.py"
8787
DESTINATION "${Python3_SITELIB}/${BIORBD_NAME}"
8888
)
8989

90-
INSTALL(FILES "${CMAKE_CURRENT_SOURCE_DIR}/__init__.py"
91-
DESTINATION "${Python3_SITELIB}/${BIORBD_NAME}"
92-
)
93-
94-
# Install the version file
95-
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/_version.py"
90+
file(GLOB PYTHON_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.py")
91+
INSTALL(FILES ${PYTHON_FILES}
9692
DESTINATION "${Python3_SITELIB}/${BIORBD_NAME}"
9793
)
9894

binding/python3/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from .biorbd import *
22
from ._version import __version__
3-
3+
from .surface_max_torque_actuator import surface_max_torque_actuator
44

55
if biorbd.currentLinearAlgebraBackend() == 1:
66
from casadi import Function, MX
7+
78
def to_casadi_func(name, func, *all_param):
89
mx_param = []
910
for p in all_param:
@@ -14,4 +15,3 @@ def to_casadi_func(name, func, *all_param):
1415
if not isinstance(func_evaluated, MX):
1516
func_evaluated = func_evaluated.to_mx()
1617
return Function(name, mx_param, [func_evaluated]).expand()
17-
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
from .biorbd import currentLinearAlgebraBackend
2+
3+
import numpy as np
4+
5+
try:
6+
from matplotlib import pyplot as plt
7+
8+
matplotlib_found = True
9+
except ModuleNotFoundError:
10+
matplotlib_found = False
11+
if currentLinearAlgebraBackend() == 1:
12+
from casadi import Function, MX
13+
14+
15+
def surface_max_torque_actuator(model, dof, resolution=40):
16+
if not matplotlib_found:
17+
raise ModuleNotFoundError("matplotlib must be installed to use biorbd.surface_max_torque_actuator")
18+
19+
d2r = np.pi / 180
20+
min_bound_q = -200 * d2r
21+
max_bound_q = 200 * d2r
22+
min_bound_qdot = -500 * d2r
23+
max_bound_qdot = 500 * d2r
24+
nbq = model.nbQ()
25+
26+
if currentLinearAlgebraBackend() == 1:
27+
torque_act = MX.sym("act", nbq, 1)
28+
q_sym = MX.sym("q", nbq, 1)
29+
qdot_sym = MX.sym("q_dot", nbq, 1)
30+
torque_func = Function(
31+
"torque_func",
32+
[torque_act, q_sym, qdot_sym],
33+
[model.torque(torque_act, q_sym, qdot_sym).to_mx()],
34+
["activation", "Q", "Qdot"],
35+
["Tau"],
36+
)
37+
else:
38+
torque_func = model.torque
39+
40+
max_act = np.ones(nbq)
41+
q = np.arange(min_bound_q, max_bound_q, (max_bound_q - min_bound_q) / resolution)
42+
qdot = np.arange(min_bound_qdot, max_bound_qdot, (max_bound_qdot - min_bound_qdot) / resolution)
43+
44+
tau_pos = np.zeros((resolution, resolution))
45+
tau_neg = np.zeros((resolution, resolution))
46+
for i in range(resolution):
47+
for j in range(resolution):
48+
pos = torque_func(max_act, np.ones(nbq) * q[i], np.ones(nbq) * qdot[j])
49+
neg = torque_func(-max_act, np.ones(nbq) * q[i], np.ones(nbq) * qdot[j])
50+
if currentLinearAlgebraBackend() == 0:
51+
pos = pos.to_array()
52+
neg = neg.to_array()
53+
tau_pos[i, j] = pos[dof]
54+
tau_neg[i, j] = neg[dof]
55+
56+
q = q / d2r
57+
qdot = qdot / d2r
58+
q, qdot = np.meshgrid(qdot, q)
59+
60+
def plot_surface(tau):
61+
fig = plt.figure()
62+
ax = fig.gca(projection="3d")
63+
ax.plot_surface(q, qdot, tau)
64+
ax.set_xlabel("Qdot", fontsize=15)
65+
ax.set_ylabel("Q", fontsize=15)
66+
ax.set_zlabel("Tau", fontsize=15)
67+
68+
plot_surface(tau_pos)
69+
plot_surface(tau_neg)
70+
71+
plt.show()

0 commit comments

Comments
 (0)