Skip to content

Commit adc8c6e

Browse files
ABonnefoynim65s
authored andcommitted
Mise à jour pour python3 (#82)
Authored by: Aurélie Bonnefoy <[email protected]>
1 parent ebc2966 commit adc8c6e

File tree

2 files changed

+49
-56
lines changed

2 files changed

+49
-56
lines changed

exercizes/notebooks/TSID_ex1.ipynb

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,6 @@
259259
"from numpy.linalg import norm as norm\n",
260260
"import os\n",
261261
"import time as tmp\n",
262-
"import commands\n",
263262
"\n",
264263
"# import the library TSID for the Whole-Body Controller\n",
265264
"import tsid\n",
@@ -343,9 +342,6 @@
343342
"source": [
344343
"# Creation of the robot wrapper for gepetto viewer (graphical interface)\n",
345344
"robot_display = pin.RobotWrapper.BuildFromURDF(urdf, [path, ], pin.JointModelFreeFlyer())\n",
346-
"l = commands.getstatusoutput(\"ps aux |grep 'gepetto-gui'|grep -v 'grep'|wc -l\")\n",
347-
"if int(l[1]) == 0:\n",
348-
" os.system('gepetto-gui &')\n",
349345
"tmp.sleep(1)\n",
350346
"cl = gepetto.corbaserver.Client()\n",
351347
"gui = cl.gui\n",
@@ -680,14 +676,14 @@
680676
"source": [
681677
"# Initialisation of the plot variables which will be updated during the simulation loop \n",
682678
"# These variables describe the behavior of the CoM of the robot (reference and real position, velocity and acceleration)\n",
683-
"com_pos = matlib.empty((3, N_SIMULATION))*nan\n",
684-
"com_vel = matlib.empty((3, N_SIMULATION))*nan\n",
685-
"com_acc = matlib.empty((3, N_SIMULATION))*nan\n",
679+
"com_pos = np.zeros((3, N_SIMULATION))*nan\n",
680+
"com_vel = np.zeros((3, N_SIMULATION))*nan\n",
681+
"com_acc = np.zeros((3, N_SIMULATION))*nan\n",
686682
"\n",
687-
"com_pos_ref = matlib.empty((3, N_SIMULATION))*nan\n",
688-
"com_vel_ref = matlib.empty((3, N_SIMULATION))*nan\n",
689-
"com_acc_ref = matlib.empty((3, N_SIMULATION))*nan\n",
690-
"com_acc_des = matlib.empty((3, N_SIMULATION))*nan "
683+
"com_pos_ref = np.zeros((3, N_SIMULATION))*nan\n",
684+
"com_vel_ref = np.zeros((3, N_SIMULATION))*nan\n",
685+
"com_acc_ref = np.zeros((3, N_SIMULATION))*nan\n",
686+
"com_acc_des = np.zeros((3, N_SIMULATION))*nan "
691687
]
692688
},
693689
{
@@ -863,8 +859,9 @@
863859
" print (\"\\ttracking err %s: %.3f\"%(comTask.name.ljust(20,'.'), norm(comTask.position_error, 2)))\n",
864860
" print (\"\\t||v||: %.3f\\t ||dv||: %.3f\"%(norm(v, 2), norm(dv)))\n",
865861
"\n",
866-
" v_mean = v + 0.5*dt*dv\n",
867-
" v += dt*dv\n",
862+
" \n",
863+
" v_mean = v + 0.5*np.resize(dt*dv, np.shape(v))\n",
864+
" v += np.resize(dt*dv, np.shape(v))\n",
868865
" q = pin.integrate(model, q, dt*v_mean)\n",
869866
" t += dt\n",
870867
" \n",
@@ -909,8 +906,8 @@
909906
"\n",
910907
"(f, ax) = plut.create_empty_figure(3, 1, figsize=(10,10))\n",
911908
"for i in range(3):\n",
912-
" ax[i].plot(time, com_pos[i,:].A1, label='CoM '+str(i))\n",
913-
" ax[i].plot(time, com_pos_ref[i,:].A1, 'r:', label='CoM Ref '+str(i))\n",
909+
" ax[i].plot(time, com_pos[i,:], label='CoM '+str(i))\n",
910+
" ax[i].plot(time, com_pos_ref[i,:], 'r:', label='CoM Ref '+str(i))\n",
914911
" ax[i].set_xlabel('Time [s]')\n",
915912
" ax[i].set_ylabel('CoM [m]')\n",
916913
" leg = ax[i].legend()\n",
@@ -942,8 +939,8 @@
942939
"\n",
943940
"(f, ax) = plut.create_empty_figure(3, 1, figsize=(10,10))\n",
944941
"for i in range(3):\n",
945-
" ax[i].plot(time, com_vel[i,:].A1, label='CoM Vel '+str(i))\n",
946-
" ax[i].plot(time, com_vel_ref[i,:].A1, 'r:', label='CoM Vel Ref '+str(i))\n",
942+
" ax[i].plot(time, com_vel[i,:], label='CoM Vel '+str(i))\n",
943+
" ax[i].plot(time, com_vel_ref[i,:], 'r:', label='CoM Vel Ref '+str(i))\n",
947944
" ax[i].set_xlabel('Time [s]')\n",
948945
" ax[i].set_ylabel('CoM Vel [m/s]')\n",
949946
" leg = ax[i].legend()\n",
@@ -975,9 +972,9 @@
975972
"\n",
976973
"(f, ax) = plut.create_empty_figure(3, 1, figsize=(10,10))\n",
977974
"for i in range(3):\n",
978-
" ax[i].plot(time, com_acc[i,:].A1, label='CoM Acc '+str(i))\n",
979-
" ax[i].plot(time, com_acc_ref[i,:].A1, 'r:', label='CoM Acc Ref '+str(i))\n",
980-
" ax[i].plot(time, com_acc_des[i,:].A1, 'g--', label='CoM Acc Des '+str(i))\n",
975+
" ax[i].plot(time, com_acc[i,:], label='CoM Acc '+str(i))\n",
976+
" ax[i].plot(time, com_acc_ref[i,:], 'r:', label='CoM Acc Ref '+str(i))\n",
977+
" ax[i].plot(time, com_acc_des[i,:], 'g--', label='CoM Acc Des '+str(i))\n",
981978
" ax[i].set_xlabel('Time [s]')\n",
982979
" ax[i].set_ylabel('CoM Acc [m/s^2]')\n",
983980
" leg = ax[i].legend()\n",
@@ -996,23 +993,23 @@
996993
],
997994
"metadata": {
998995
"kernelspec": {
999-
"display_name": "Python 2",
996+
"display_name": "Python 3",
1000997
"language": "python",
1001-
"name": "python2"
998+
"name": "python3"
1002999
},
10031000
"language_info": {
10041001
"codemirror_mode": {
10051002
"name": "ipython",
1006-
"version": 2
1003+
"version": 3
10071004
},
10081005
"file_extension": ".py",
10091006
"mimetype": "text/x-python",
10101007
"name": "python",
10111008
"nbconvert_exporter": "python",
1012-
"pygments_lexer": "ipython2",
1013-
"version": "2.7.12"
1009+
"pygments_lexer": "ipython3",
1010+
"version": "3.6.9"
10141011
}
10151012
},
10161013
"nbformat": 4,
1017-
"nbformat_minor": 2
1014+
"nbformat_minor": 4
10181015
}

exercizes/notebooks/TSID_ex2.ipynb

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,6 @@
259259
"from numpy.linalg import norm as norm\n",
260260
"import os\n",
261261
"import time as tmp\n",
262-
"import commands\n",
263262
"\n",
264263
"# import the library TSID for the Whole-Body Controller\n",
265264
"import tsid\n",
@@ -343,9 +342,6 @@
343342
"source": [
344343
"# Creation of the robot wrapper for gepetto viewer (graphical interface)\n",
345344
"robot_display = pin.RobotWrapper.BuildFromURDF(urdf, [path, ], pin.JointModelFreeFlyer())\n",
346-
"l = commands.getstatusoutput(\"ps aux |grep 'gepetto-gui'|grep -v 'grep'|wc -l\")\n",
347-
"if int(l[1]) == 0:\n",
348-
" os.system('gepetto-gui &')\n",
349345
"tmp.sleep(1)\n",
350346
"cl = gepetto.corbaserver.Client()\n",
351347
"gui = cl.gui\n",
@@ -681,14 +677,14 @@
681677
"source": [
682678
"# Initialisation of the plot variables which will be updated during the simulation loop \n",
683679
"# These variables describe the behavior of the CoM of the robot (reference and real position, velocity and acceleration)\n",
684-
"com_pos = matlib.empty((3, N_SIMULATION))*nan\n",
685-
"com_vel = matlib.empty((3, N_SIMULATION))*nan\n",
686-
"com_acc = matlib.empty((3, N_SIMULATION))*nan\n",
687-
"\n",
688-
"com_pos_ref = matlib.empty((3, N_SIMULATION))*nan\n",
689-
"com_vel_ref = matlib.empty((3, N_SIMULATION))*nan\n",
690-
"com_acc_ref = matlib.empty((3, N_SIMULATION))*nan\n",
691-
"com_acc_des = matlib.empty((3, N_SIMULATION))*nan \n"
680+
"com_pos = np.zeros((3, N_SIMULATION))*nan\n",
681+
"com_vel = np.zeros((3, N_SIMULATION))*nan\n",
682+
"com_acc = np.zeros((3, N_SIMULATION))*nan\n",
683+
"\n",
684+
"com_pos_ref = np.zeros((3, N_SIMULATION))*nan\n",
685+
"com_vel_ref = np.zeros((3, N_SIMULATION))*nan\n",
686+
"com_acc_ref = np.zeros((3, N_SIMULATION))*nan\n",
687+
"com_acc_des = np.zeros((3, N_SIMULATION))*nan \n"
692688
]
693689
},
694690
{
@@ -697,11 +693,11 @@
697693
"metadata": {},
698694
"outputs": [],
699695
"source": [
700-
"# Parametes of the sinusoid\n",
696+
"# Parameters of the sinusoid\n",
701697
"\n",
702698
"offset = robot.com(data) # offset of the mesured CoM \n",
703-
"amp = np.matrix([0.0, 0.05, 0.0]).T # amplitude function of 0.05 along the y axis \n",
704-
"two_pi_f = 2*np.pi*np.matrix([0.0, 0.5, 0.0]).T # 2π function along the y axis with 0.5 amplitude\n",
699+
"amp = np.array([0.0, 0.05, 0.0]).T # amplitude function of 0.05 along the y axis \n",
700+
"two_pi_f = 2*np.pi*np.array([0.0, 0.5, 0.0]).T # 2π function along the y axis with 0.5 amplitude\n",
705701
"two_pi_f_amp = np.multiply(two_pi_f,amp) # 2π function times amplitude function\n",
706702
"two_pi_f_squared_amp = np.multiply(two_pi_f, two_pi_f_amp) # 2π function times squared amplitude function"
707703
]
@@ -887,8 +883,8 @@
887883
" print (\"\\ttracking err %s: %.3f\"%(comTask.name.ljust(20,'.'), norm(comTask.position_error, 2)))\n",
888884
" print (\"\\t||v||: %.3f\\t ||dv||: %.3f\"%(norm(v, 2), norm(dv)))\n",
889885
"\n",
890-
" v_mean = v + 0.5*dt*dv\n",
891-
" v += dt*dv\n",
886+
" v_mean = v + 0.5*np.resize(dt*dv, np.shape(v))\n",
887+
" v += np.resize(dt*dv, np.shape(v))\n",
892888
" q = pin.integrate(model, q, dt*v_mean)\n",
893889
" t += dt\n",
894890
" \n",
@@ -931,8 +927,8 @@
931927
"\n",
932928
"(f, ax) = plut.create_empty_figure(3, 1, figsize=(10,10))\n",
933929
"for i in range(3):\n",
934-
" ax[i].plot(time, com_pos[i,:].A1, label='CoM '+str(i))\n",
935-
" ax[i].plot(time, com_pos_ref[i,:].A1, 'r:', label='CoM Ref '+str(i))\n",
930+
" ax[i].plot(time, com_pos[i,:], label='CoM '+str(i))\n",
931+
" ax[i].plot(time, com_pos_ref[i,:], 'r:', label='CoM Ref '+str(i))\n",
936932
" ax[i].set_xlabel('Time [s]')\n",
937933
" ax[i].set_ylabel('CoM [m]')\n",
938934
" leg = ax[i].legend()\n",
@@ -964,8 +960,8 @@
964960
"\n",
965961
"(f, ax) = plut.create_empty_figure(3, 1, figsize=(10,10))\n",
966962
"for i in range(3):\n",
967-
" ax[i].plot(time, com_vel[i,:].A1, label='CoM Vel '+str(i))\n",
968-
" ax[i].plot(time, com_vel_ref[i,:].A1, 'r:', label='CoM Vel Ref '+str(i))\n",
963+
" ax[i].plot(time, com_vel[i,:], label='CoM Vel '+str(i))\n",
964+
" ax[i].plot(time, com_vel_ref[i,:], 'r:', label='CoM Vel Ref '+str(i))\n",
969965
" ax[i].set_xlabel('Time [s]')\n",
970966
" ax[i].set_ylabel('CoM Vel [m/s]')\n",
971967
" leg = ax[i].legend()\n",
@@ -999,9 +995,9 @@
999995
"\n",
1000996
"(f, ax) = plut.create_empty_figure(3, 1, figsize=(10,10))\n",
1001997
"for i in range(3):\n",
1002-
" ax[i].plot(time, com_acc[i,:].A1, label='CoM Acc '+str(i))\n",
1003-
" ax[i].plot(time, com_acc_ref[i,:].A1, 'r:', label='CoM Acc Ref '+str(i))\n",
1004-
" ax[i].plot(time, com_acc_des[i,:].A1, 'g--', label='CoM Acc Des '+str(i))\n",
998+
" ax[i].plot(time, com_acc[i,:], label='CoM Acc '+str(i))\n",
999+
" ax[i].plot(time, com_acc_ref[i,:], 'r:', label='CoM Acc Ref '+str(i))\n",
1000+
" ax[i].plot(time, com_acc_des[i,:], 'g--', label='CoM Acc Des '+str(i))\n",
10051001
" ax[i].set_xlabel('Time [s]')\n",
10061002
" ax[i].set_ylabel('CoM Acc [m/s^2]')\n",
10071003
" leg = ax[i].legend()\n",
@@ -1020,23 +1016,23 @@
10201016
],
10211017
"metadata": {
10221018
"kernelspec": {
1023-
"display_name": "Python 2",
1019+
"display_name": "Python 3",
10241020
"language": "python",
1025-
"name": "python2"
1021+
"name": "python3"
10261022
},
10271023
"language_info": {
10281024
"codemirror_mode": {
10291025
"name": "ipython",
1030-
"version": 2
1026+
"version": 3
10311027
},
10321028
"file_extension": ".py",
10331029
"mimetype": "text/x-python",
10341030
"name": "python",
10351031
"nbconvert_exporter": "python",
1036-
"pygments_lexer": "ipython2",
1037-
"version": "2.7.12"
1032+
"pygments_lexer": "ipython3",
1033+
"version": "3.6.9"
10381034
}
10391035
},
10401036
"nbformat": 4,
1041-
"nbformat_minor": 2
1037+
"nbformat_minor": 4
10421038
}

0 commit comments

Comments
 (0)