|
259 | 259 | "from numpy.linalg import norm as norm\n", |
260 | 260 | "import os\n", |
261 | 261 | "import time as tmp\n", |
262 | | - "import commands\n", |
263 | 262 | "\n", |
264 | 263 | "# import the library TSID for the Whole-Body Controller\n", |
265 | 264 | "import tsid\n", |
|
343 | 342 | "source": [ |
344 | 343 | "# Creation of the robot wrapper for gepetto viewer (graphical interface)\n", |
345 | 344 | "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", |
349 | 345 | "tmp.sleep(1)\n", |
350 | 346 | "cl = gepetto.corbaserver.Client()\n", |
351 | 347 | "gui = cl.gui\n", |
|
681 | 677 | "source": [ |
682 | 678 | "# Initialisation of the plot variables which will be updated during the simulation loop \n", |
683 | 679 | "# 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" |
692 | 688 | ] |
693 | 689 | }, |
694 | 690 | { |
|
697 | 693 | "metadata": {}, |
698 | 694 | "outputs": [], |
699 | 695 | "source": [ |
700 | | - "# Parametes of the sinusoid\n", |
| 696 | + "# Parameters of the sinusoid\n", |
701 | 697 | "\n", |
702 | 698 | "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", |
705 | 701 | "two_pi_f_amp = np.multiply(two_pi_f,amp) # 2π function times amplitude function\n", |
706 | 702 | "two_pi_f_squared_amp = np.multiply(two_pi_f, two_pi_f_amp) # 2π function times squared amplitude function" |
707 | 703 | ] |
|
887 | 883 | " print (\"\\ttracking err %s: %.3f\"%(comTask.name.ljust(20,'.'), norm(comTask.position_error, 2)))\n", |
888 | 884 | " print (\"\\t||v||: %.3f\\t ||dv||: %.3f\"%(norm(v, 2), norm(dv)))\n", |
889 | 885 | "\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", |
892 | 888 | " q = pin.integrate(model, q, dt*v_mean)\n", |
893 | 889 | " t += dt\n", |
894 | 890 | " \n", |
|
931 | 927 | "\n", |
932 | 928 | "(f, ax) = plut.create_empty_figure(3, 1, figsize=(10,10))\n", |
933 | 929 | "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", |
936 | 932 | " ax[i].set_xlabel('Time [s]')\n", |
937 | 933 | " ax[i].set_ylabel('CoM [m]')\n", |
938 | 934 | " leg = ax[i].legend()\n", |
|
964 | 960 | "\n", |
965 | 961 | "(f, ax) = plut.create_empty_figure(3, 1, figsize=(10,10))\n", |
966 | 962 | "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", |
969 | 965 | " ax[i].set_xlabel('Time [s]')\n", |
970 | 966 | " ax[i].set_ylabel('CoM Vel [m/s]')\n", |
971 | 967 | " leg = ax[i].legend()\n", |
|
999 | 995 | "\n", |
1000 | 996 | "(f, ax) = plut.create_empty_figure(3, 1, figsize=(10,10))\n", |
1001 | 997 | "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", |
1005 | 1001 | " ax[i].set_xlabel('Time [s]')\n", |
1006 | 1002 | " ax[i].set_ylabel('CoM Acc [m/s^2]')\n", |
1007 | 1003 | " leg = ax[i].legend()\n", |
|
1020 | 1016 | ], |
1021 | 1017 | "metadata": { |
1022 | 1018 | "kernelspec": { |
1023 | | - "display_name": "Python 2", |
| 1019 | + "display_name": "Python 3", |
1024 | 1020 | "language": "python", |
1025 | | - "name": "python2" |
| 1021 | + "name": "python3" |
1026 | 1022 | }, |
1027 | 1023 | "language_info": { |
1028 | 1024 | "codemirror_mode": { |
1029 | 1025 | "name": "ipython", |
1030 | | - "version": 2 |
| 1026 | + "version": 3 |
1031 | 1027 | }, |
1032 | 1028 | "file_extension": ".py", |
1033 | 1029 | "mimetype": "text/x-python", |
1034 | 1030 | "name": "python", |
1035 | 1031 | "nbconvert_exporter": "python", |
1036 | | - "pygments_lexer": "ipython2", |
1037 | | - "version": "2.7.12" |
| 1032 | + "pygments_lexer": "ipython3", |
| 1033 | + "version": "3.6.9" |
1038 | 1034 | } |
1039 | 1035 | }, |
1040 | 1036 | "nbformat": 4, |
1041 | | - "nbformat_minor": 2 |
| 1037 | + "nbformat_minor": 4 |
1042 | 1038 | } |
0 commit comments