├── README.md ├── mujoco210 ├── THIRD_PARTY_NOTICES ├── bin │ ├── libglew.so │ ├── libglewegl.so │ ├── libglewosmesa.so │ ├── libglfw.so.3 │ ├── libglfw3.a │ ├── libmujoco210.so │ └── libmujoco210nogl.so └── include │ ├── glfw3.h │ ├── mjdata.h │ ├── mjmodel.h │ ├── mjrender.h │ ├── mjui.h │ ├── mjvisualize.h │ ├── mjxmacro.h │ ├── mujoco.h │ ├── uitools.c │ └── uitools.h ├── mujoco_ros ├── CMakeLists.txt ├── include │ └── mjros.h ├── package.xml └── src │ ├── main.cpp │ └── mjros.cpp └── mujoco_ros_msgs ├── CMakeLists.txt ├── msg ├── JointInit.msg ├── JointSet.msg ├── JointState.msg ├── SensorBase.msg ├── SensorState.msg ├── SimStatus.msg ├── SimstatusM2C.msg └── applyforce.msg └── package.xml /README.md: -------------------------------------------------------------------------------- 1 | # mujoco_ros_sim 2 | 3 | Simple connect between mujoco with ros. 4 | 5 | Mujoco sends joint and sensor data via rostopic, and receives torque or position command data via rostopic. 6 | 7 | mujoco is based on 2.1 // Mujoco is free now! 8 | 9 | position/torque command available 10 | 11 | ※ubuntu 18.04 is recommended since graphical issue at 16.04 12 | 13 | ## Installation 14 | 15 | clone this git to your_catkin_ws/src, then compile with catkin_make 16 | 17 | with tocabi_ecat package, mujoco can send status , receive commands via shared memory 18 | 19 | ## how to start 20 | 21 | you can test mujoco_ros_sim with dyros_red or dyros_jet 22 | 23 | * [DYROS_RED](https://github.com/saga0619/dyros_red) 24 | * [DYROS_JET](https://github.com/psh117/dyros_jet) 25 | * [DYROS_TOCABI](https://github.com/saga0619/dyros_tocabi) 26 | * [DYROS_TOCABI_V2](https://github.com/saga0619/dyros_tocabi_v2) 27 | 28 | 29 | ## ROS TOPIC LIST 30 | ### Publisher 31 | * /mujoco_ros_interface/sim_command_sim2con : simulator <-> controller connector 32 | * /mujoco_ros_interface/joint_states : publish joint states(d->qpos, d->qvel, d->qacc) 33 | * /mujoco_ros_interface/sensor_states : publish sensor states 34 | * /mujoco_ros_interface/sim_time : publish simulation time 35 | 36 | ### Subscriber 37 | * /mujoco_ros_interface/sim_command_con2sim : simulator <-> controller connector 38 | * /mujoco_ros_interface/joint_set : position/torque command from controller 39 | 40 | ### How to Apply External Force 41 | * /mujoco_ros_interface/applied_ext_force : simulator <-> controller connector. 42 | * mujoco_ros_msgs::applyforce : link index, force(3), torque(3) command from controller. 43 | Modify the controller to recognize applyforce.msg, and configure the publisher to publish as shown below. 44 | ``` 45 | #define DEG2RAD (0.01745329251994329576923690768489) 46 | 47 | ros::Publisher mujoco_ext_force_apply_pub; 48 | mujoco_ext_force_apply_pub = nh_.advertise("/mujoco_ros_interface/applied_ext_force", 10); 49 | mujoco_ros_msgs::applyforce mujoco_applied_ext_force_; 50 | 51 | double force_temp_ = 100, theta_temp_ = 0; //100 N, 0 degree 52 | 53 | if (tick >= 0 && tick < 2000) // (Example) in 2000hz loop, apply force for 1 second. 54 | { 55 | mujoco_applied_ext_force_.wrench.force.x = force_temp_*sin(theta_temp_*DEG2RAD); //x-axis linear force 56 | mujoco_applied_ext_force_.wrench.force.y = -force_temp_*cos(theta_temp_*DEG2RAD); //y-axis linear force 57 | mujoco_applied_ext_force_.wrench.force.z = 0.0; //z-axis linear force 58 | mujoco_applied_ext_force_.wrench.torque.x = 0.0; //x-axis angular moment 59 | mujoco_applied_ext_force_.wrench.torque.y = 0.0; //y-axis angular moment 60 | mujoco_applied_ext_force_.wrench.torque.z = 0.0; //z-axis angular moment 61 | 62 | mujoco_applied_ext_force_.link_idx = 1; //link idx; 1:pelvis 63 | 64 | mujoco_ext_force_apply_pub.publish(mujoco_applied_ext_force_); 65 | } 66 | ``` 67 | 68 | -------------------------------------------------------------------------------- /mujoco210/THIRD_PARTY_NOTICES: -------------------------------------------------------------------------------- 1 | MuJoCo version 2.1 incorporates the following open-source libraries: 2 | 3 | - libccd 4 | - Collisions 5 | - TinyXML 6 | - LodePNG 7 | - Qhull 8 | - GLEW 9 | - GLFW 10 | 11 | Their copyright and license information is included below. 12 | 13 | 14 | MuJoCo is compiled with GCC on Linux. The compilers may incorporate portions of 15 | their standard headers and/or runtime libraries in the resulting MuJoCo binary. 16 | All GCC runtime libraries are linked dynamically and the compilation process is 17 | compliant with the eligibility requirements for the 18 | GCC RUNTIME LIBRARY EXCEPTION to GPLv3, available at: 19 | https://www.gnu.org/licenses/gcc-exception-3.1.en.html 20 | 21 | 22 | 23 | ========================= LIBCCD ============================================ 24 | 25 | Copyright (c) 2010-2012 Daniel Fiser , 26 | Intelligent and Mobile Robotics Group, Department of Cybernetics, 27 | Faculty of Electrical Engineering, Czech Technical University in Prague. 28 | All rights reserved. 29 | 30 | This work was supported by SYMBRION and REPLICATOR projects. 31 | The SYMBRION project is funded by European Commission within the work 32 | "Future and Emergent Technologies Proactive" under grant agreement no. 33 | 216342. 34 | The REPLICATOR project is funded within the work programme "Cognitive 35 | Systems, Interaction, Robotics" under grant agreement no. 216240. 36 | http://www.symbrion.eu/ 37 | http://www.replicators.eu/ 38 | 39 | Redistribution and use in source and binary forms, with or without 40 | modification, are permitted provided that the following conditions are met: 41 | 42 | - Redistributions of source code must retain the above copyright notice, 43 | this list of conditions and the following disclaimer. 44 | 45 | - Redistributions in binary form must reproduce the above copyright 46 | notice, this list of conditions and the following disclaimer in the 47 | documentation and/or other materials provided with the distribution. 48 | 49 | - Neither the name of the University nor the names of its contributors 50 | may be used to endorse or promote products derived from this software 51 | without specific prior written permission. 52 | 53 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 54 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 55 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 56 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 57 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 58 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 59 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 60 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 61 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 62 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 63 | POSSIBILITY OF SUCH DAMAGE. 64 | 65 | 66 | 67 | ========================= COLLISIONS ======================================== 68 | 69 | Copyright (c) 2015 Svetoslav Kolev 70 | 71 | Permission is hereby granted, free of charge, to any person obtaining a copy 72 | of this software and associated documentation files (the "Software"), to deal 73 | in the Software without restriction, including without limitation the rights 74 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 75 | copies of the Software, and to permit persons to whom the Software is 76 | furnished to do so, subject to the following conditions: 77 | 78 | The above copyright notice and this permission notice shall be included in 79 | all copies or substantial portions of the Software. 80 | 81 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 82 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 83 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 84 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 85 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 86 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 87 | THE SOFTWARE. 88 | 89 | 90 | 91 | ========================= TINYXML =========================================== 92 | 93 | TinyXML is released under the zlib license: 94 | 95 | This software is provided 'as-is', without any express or implied warranty. 96 | In no event will the authors be held liable for any damages arising from 97 | the use of this software. 98 | 99 | Permission is granted to anyone to use this software for any purpose, 100 | including commercial applications, and to alter it and redistribute it freely, 101 | subject to the following restrictions: 102 | 103 | 1. The origin of this software must not be misrepresented; you must not claim 104 | that you wrote the original software. If you use this software in a product, 105 | an acknowledgment in the product documentation would be appreciated but is 106 | not required. 107 | 108 | 2. Altered source versions must be plainly marked as such, and must not be 109 | misrepresented as being the original software. 110 | 111 | 3. This notice may not be removed or altered from any source distribution. 112 | 113 | 114 | 115 | ========================= LODEPNG =========================================== 116 | 117 | Copyright (c) 2005-2015 Lode Vandevenne 118 | 119 | This software is provided 'as-is', without any express or implied 120 | warranty. In no event will the authors be held liable for any damages 121 | arising from the use of this software. 122 | 123 | Permission is granted to anyone to use this software for any purpose, 124 | including commercial applications, and to alter it and redistribute it 125 | freely, subject to the following restrictions: 126 | 127 | 1. The origin of this software must not be misrepresented; you must not 128 | claim that you wrote the original software. If you use this software 129 | in a product, an acknowledgment in the product documentation would be 130 | appreciated but is not required. 131 | 132 | 2. Altered source versions must be plainly marked as such, and must not be 133 | misrepresented as being the original software. 134 | 135 | 3. This notice may not be removed or altered from any source 136 | distribution. 137 | 138 | 139 | 140 | ========================= QHULL ============================================= 141 | 142 | Qhull, Copyright (c) 1993-2012 143 | 144 | C.B. Barber 145 | Arlington, MA 146 | 147 | and 148 | 149 | The National Science and Technology Research Center for 150 | Computation and Visualization of Geometric Structures 151 | (The Geometry Center) 152 | University of Minnesota 153 | 154 | email: qhull@qhull.org 155 | 156 | This software includes Qhull from C.B. Barber and The Geometry Center. 157 | Qhull is copyrighted as noted above. Qhull is free software and may 158 | be obtained via http from www.qhull.org. It may be freely copied, modified, 159 | and redistributed under the following conditions: 160 | 161 | 1. All copyright notices must remain intact in all files. 162 | 163 | 2. A copy of this text file must be distributed along with any copies 164 | of Qhull that you redistribute; this includes copies that you have 165 | modified, or copies of programs or other software products that 166 | include Qhull. 167 | 168 | 3. If you modify Qhull, you must include a notice giving the 169 | name of the person performing the modification, the date of 170 | modification, and the reason for such modification. 171 | 172 | 4. When distributing modified versions of Qhull, or other software 173 | products that include Qhull, you must provide notice that the original 174 | source code may be obtained as noted above. 175 | 176 | 5. There is no warranty or other guarantee of fitness for Qhull, it is 177 | provided solely "as is". Bug reports or fixes may be sent to 178 | qhull_bug@qhull.org; the authors may or may not act on them as 179 | they desire. 180 | 181 | 182 | 183 | ========================= GLEW ============================================== 184 | 185 | The OpenGL Extension Wrangler Library 186 | Copyright (C) 2008-2015, Nigel Stewart 187 | Copyright (C) 2002-2008, Milan Ikits 188 | Copyright (C) 2002-2008, Marcelo E. Magallon 189 | Copyright (C) 2002, Lev Povalahev 190 | All rights reserved. 191 | 192 | Redistribution and use in source and binary forms, with or without 193 | modification, are permitted provided that the following conditions are met: 194 | 195 | * Redistributions of source code must retain the above copyright notice, 196 | this list of conditions and the following disclaimer. 197 | * Redistributions in binary form must reproduce the above copyright notice, 198 | this list of conditions and the following disclaimer in the documentation 199 | and/or other materials provided with the distribution. 200 | * The name of the author may be used to endorse or promote products 201 | derived from this software without specific prior written permission. 202 | 203 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 204 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 205 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 206 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 207 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 208 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 209 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 210 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 211 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 212 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 213 | THE POSSIBILITY OF SUCH DAMAGE. 214 | 215 | 216 | 217 | ========================= GLFW ============================================== 218 | 219 | Copyright (c) 2002-2006 Marcus Geelnard 220 | Copyright (c) 2006-2010 Camilla Berglund 221 | 222 | This software is provided 'as-is', without any express or implied 223 | warranty. In no event will the authors be held liable for any damages 224 | arising from the use of this software. 225 | 226 | Permission is granted to anyone to use this software for any purpose, 227 | including commercial applications, and to alter it and redistribute it 228 | freely, subject to the following restrictions: 229 | 230 | 1. The origin of this software must not be misrepresented; you must not 231 | claim that you wrote the original software. If you use this software 232 | in a product, an acknowledgment in the product documentation would 233 | be appreciated but is not required. 234 | 235 | 2. Altered source versions must be plainly marked as such, and must not 236 | be misrepresented as being the original software. 237 | 238 | 3. This notice may not be removed or altered from any source 239 | distribution. 240 | -------------------------------------------------------------------------------- /mujoco210/bin/libglew.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saga0619/mujoco_ros_sim/dcdfd09ac6a4f5fc03c4a0b1a83b3faaf41f94bd/mujoco210/bin/libglew.so -------------------------------------------------------------------------------- /mujoco210/bin/libglewegl.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saga0619/mujoco_ros_sim/dcdfd09ac6a4f5fc03c4a0b1a83b3faaf41f94bd/mujoco210/bin/libglewegl.so -------------------------------------------------------------------------------- /mujoco210/bin/libglewosmesa.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saga0619/mujoco_ros_sim/dcdfd09ac6a4f5fc03c4a0b1a83b3faaf41f94bd/mujoco210/bin/libglewosmesa.so -------------------------------------------------------------------------------- /mujoco210/bin/libglfw.so.3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saga0619/mujoco_ros_sim/dcdfd09ac6a4f5fc03c4a0b1a83b3faaf41f94bd/mujoco210/bin/libglfw.so.3 -------------------------------------------------------------------------------- /mujoco210/bin/libglfw3.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saga0619/mujoco_ros_sim/dcdfd09ac6a4f5fc03c4a0b1a83b3faaf41f94bd/mujoco210/bin/libglfw3.a -------------------------------------------------------------------------------- /mujoco210/bin/libmujoco210.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saga0619/mujoco_ros_sim/dcdfd09ac6a4f5fc03c4a0b1a83b3faaf41f94bd/mujoco210/bin/libmujoco210.so -------------------------------------------------------------------------------- /mujoco210/bin/libmujoco210nogl.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saga0619/mujoco_ros_sim/dcdfd09ac6a4f5fc03c4a0b1a83b3faaf41f94bd/mujoco210/bin/libmujoco210nogl.so -------------------------------------------------------------------------------- /mujoco210/include/mjdata.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 DeepMind Technologies Limited 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef MUJOCO_MJDATA_H_ 16 | #define MUJOCO_MJDATA_H_ 17 | 18 | //---------------------------- primitive types (mjt) ------------------------------------ 19 | 20 | typedef enum _mjtWarning // warning types 21 | { 22 | mjWARN_INERTIA = 0, // (near) singular inertia matrix 23 | mjWARN_CONTACTFULL, // too many contacts in contact list 24 | mjWARN_CNSTRFULL, // too many constraints 25 | mjWARN_VGEOMFULL, // too many visual geoms 26 | mjWARN_BADQPOS, // bad number in qpos 27 | mjWARN_BADQVEL, // bad number in qvel 28 | mjWARN_BADQACC, // bad number in qacc 29 | mjWARN_BADCTRL, // bad number in ctrl 30 | 31 | mjNWARNING // number of warnings 32 | } mjtWarning; 33 | 34 | 35 | typedef enum _mjtTimer 36 | { 37 | // main api 38 | mjTIMER_STEP = 0, // step 39 | mjTIMER_FORWARD, // forward 40 | mjTIMER_INVERSE, // inverse 41 | 42 | // breakdown of step/forward 43 | mjTIMER_POSITION, // fwdPosition 44 | mjTIMER_VELOCITY, // fwdVelocity 45 | mjTIMER_ACTUATION, // fwdActuation 46 | mjTIMER_ACCELERATION, // fwdAcceleration 47 | mjTIMER_CONSTRAINT, // fwdConstraint 48 | 49 | // breakdown of fwdPosition 50 | mjTIMER_POS_KINEMATICS, // kinematics, com, tendon, transmission 51 | mjTIMER_POS_INERTIA, // inertia computations 52 | mjTIMER_POS_COLLISION, // collision detection 53 | mjTIMER_POS_MAKE, // make constraints 54 | mjTIMER_POS_PROJECT, // project constraints 55 | 56 | mjNTIMER // number of timers 57 | } mjtTimer; 58 | 59 | 60 | //------------------------------ mjContact ---------------------------------------------- 61 | 62 | struct _mjContact // result of collision detection functions 63 | { 64 | // contact parameters set by geom-specific collision detector 65 | mjtNum dist; // distance between nearest points; neg: penetration 66 | mjtNum pos[3]; // position of contact point: midpoint between geoms 67 | mjtNum frame[9]; // normal is in [0-2] 68 | 69 | // contact parameters set by mj_collideGeoms 70 | mjtNum includemargin; // include if dist=max: ignore) 217 | }; 218 | 219 | 220 | struct _mjuiItem // UI item 221 | { 222 | // common properties 223 | int type; // type (mjtItem) 224 | char name[mjMAXUINAME]; // name 225 | int state; // 0: disable, 1: enable, 2+: use predicate 226 | void *pdata; // data pointer (type-specific) 227 | int sectionid; // id of section containing item 228 | int itemid; // id of item within section 229 | 230 | // type-specific properties 231 | union 232 | { 233 | struct _mjuiItemSingle single; // check and button 234 | struct _mjuiItemMulti multi; // static, radio and select 235 | struct _mjuiItemSlider slider; // slider 236 | struct _mjuiItemEdit edit; // edit 237 | }; 238 | 239 | // internal 240 | mjrRect rect; // rectangle occupied by item 241 | }; 242 | typedef struct _mjuiItem mjuiItem; 243 | 244 | 245 | struct _mjuiSection // UI section 246 | { 247 | // properties 248 | char name[mjMAXUINAME]; // name 249 | int state; // 0: closed, 1: open 250 | int modifier; // 0: none, 1: control, 2: shift; 4: alt 251 | int shortcut; // shortcut key; 0: undefined 252 | int nitem; // number of items in use 253 | mjuiItem item[mjMAXUIITEM]; // preallocated array of items 254 | 255 | // internal 256 | mjrRect rtitle; // rectangle occupied by title 257 | mjrRect rcontent; // rectangle occupied by content 258 | }; 259 | typedef struct _mjuiSection mjuiSection; 260 | 261 | 262 | struct _mjUI // entire UI 263 | { 264 | // constants set by user 265 | mjuiThemeSpacing spacing; // UI theme spacing 266 | mjuiThemeColor color; // UI theme color 267 | mjfItemEnable predicate; // callback to set item state programmatically 268 | void* userdata; // pointer to user data (passed to predicate) 269 | int rectid; // index of this ui rectangle in mjuiState 270 | int auxid; // aux buffer index of this ui 271 | int radiocol; // number of radio columns (0 defaults to 2) 272 | 273 | // UI sizes (framebuffer units) 274 | int width; // width 275 | int height; // current heigth 276 | int maxheight; // height when all sections open 277 | int scroll; // scroll from top of UI 278 | 279 | // mouse focus 280 | int mousesect; // 0: none, -1: scroll, otherwise 1+section 281 | int mouseitem; // item within section 282 | int mousehelp; // help button down: print shortcuts 283 | 284 | // keyboard focus and edit 285 | int editsect; // 0: none, otherwise 1+section 286 | int edititem; // item within section 287 | int editcursor; // cursor position 288 | int editscroll; // horizontal scroll 289 | char edittext[mjMAXUITEXT]; // current text 290 | mjuiItem* editchanged; // pointer to changed edit in last mjui_event 291 | 292 | // sections 293 | int nsect; // number of sections in use 294 | mjuiSection sect[mjMAXUISECT]; // preallocated array of sections 295 | }; 296 | typedef struct _mjUI mjUI; 297 | 298 | 299 | struct _mjuiDef // table passed to mjui_add() 300 | { 301 | int type; // type (mjtItem); -1: section 302 | char name[mjMAXUINAME]; // name 303 | int state; // state 304 | void* pdata; // pointer to data 305 | char other[mjMAXUITEXT]; // string with type-specific properties 306 | }; 307 | typedef struct _mjuiDef mjuiDef; 308 | 309 | #endif // MUJOCO_MJUI_H_ 310 | -------------------------------------------------------------------------------- /mujoco210/include/mjvisualize.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 DeepMind Technologies Limited 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef MUJOCO_MJVISUALIZE_H_ 16 | #define MUJOCO_MJVISUALIZE_H_ 17 | 18 | #define mjNGROUP 6 // number of geom, site, joint groups with visflags 19 | #define mjMAXOVERLAY 500 // maximum number of characters in overlay text 20 | #define mjMAXLINE 100 // maximum number of lines per plot 21 | #define mjMAXLINEPNT 1000 // maximum number points per line 22 | #define mjMAXPLANEGRID 200 // maximum number of grid divisions for plane 23 | 24 | 25 | typedef enum _mjtCatBit // bitflags for mjvGeom category 26 | { 27 | mjCAT_STATIC = 1, // model elements in body 0 28 | mjCAT_DYNAMIC = 2, // model elements in all other bodies 29 | mjCAT_DECOR = 4, // decorative geoms 30 | mjCAT_ALL = 7 // select all categories 31 | } mjtCatBit; 32 | 33 | 34 | typedef enum _mjtMouse // mouse interaction mode 35 | { 36 | mjMOUSE_NONE = 0, // no action 37 | mjMOUSE_ROTATE_V, // rotate, vertical plane 38 | mjMOUSE_ROTATE_H, // rotate, horizontal plane 39 | mjMOUSE_MOVE_V, // move, vertical plane 40 | mjMOUSE_MOVE_H, // move, horizontal plane 41 | mjMOUSE_ZOOM, // zoom 42 | mjMOUSE_SELECT // selection 43 | } mjtMouse; 44 | 45 | 46 | typedef enum _mjtPertBit // mouse perturbations 47 | { 48 | mjPERT_TRANSLATE = 1, // translation 49 | mjPERT_ROTATE = 2 // rotation 50 | } mjtPertBit; 51 | 52 | 53 | typedef enum _mjtCamera // abstract camera type 54 | { 55 | mjCAMERA_FREE = 0, // free camera 56 | mjCAMERA_TRACKING, // tracking camera; uses trackbodyid 57 | mjCAMERA_FIXED, // fixed camera; uses fixedcamid 58 | mjCAMERA_USER // user is responsible for setting OpenGL camera 59 | } mjtCamera; 60 | 61 | 62 | typedef enum _mjtLabel // object labeling 63 | { 64 | mjLABEL_NONE = 0, // nothing 65 | mjLABEL_BODY, // body labels 66 | mjLABEL_JOINT, // joint labels 67 | mjLABEL_GEOM, // geom labels 68 | mjLABEL_SITE, // site labels 69 | mjLABEL_CAMERA, // camera labels 70 | mjLABEL_LIGHT, // light labels 71 | mjLABEL_TENDON, // tendon labels 72 | mjLABEL_ACTUATOR, // actuator labels 73 | mjLABEL_CONSTRAINT, // constraint labels 74 | mjLABEL_SKIN, // skin labels 75 | mjLABEL_SELECTION, // selected object 76 | mjLABEL_SELPNT, // coordinates of selection point 77 | mjLABEL_CONTACTFORCE, // magnitude of contact force 78 | 79 | mjNLABEL // number of label types 80 | } mjtLabel; 81 | 82 | 83 | typedef enum _mjtFrame // frame visualization 84 | { 85 | mjFRAME_NONE = 0, // no frames 86 | mjFRAME_BODY, // body frames 87 | mjFRAME_GEOM, // geom frames 88 | mjFRAME_SITE, // site frames 89 | mjFRAME_CAMERA, // camera frames 90 | mjFRAME_LIGHT, // light frames 91 | mjFRAME_WORLD, // world frame 92 | 93 | mjNFRAME // number of visualization frames 94 | } mjtFrame; 95 | 96 | 97 | typedef enum _mjtVisFlag // flags enabling model element visualization 98 | { 99 | mjVIS_CONVEXHULL = 0, // mesh convex hull 100 | mjVIS_TEXTURE, // textures 101 | mjVIS_JOINT, // joints 102 | mjVIS_ACTUATOR, // actuators 103 | mjVIS_CAMERA, // cameras 104 | mjVIS_LIGHT, // lights 105 | mjVIS_TENDON, // tendons 106 | mjVIS_RANGEFINDER, // rangefinder sensors 107 | mjVIS_CONSTRAINT, // point constraints 108 | mjVIS_INERTIA, // equivalent inertia boxes 109 | mjVIS_SCLINERTIA, // scale equivalent inertia boxes with mass 110 | mjVIS_PERTFORCE, // perturbation force 111 | mjVIS_PERTOBJ, // perturbation object 112 | mjVIS_CONTACTPOINT, // contact points 113 | mjVIS_CONTACTFORCE, // contact force 114 | mjVIS_CONTACTSPLIT, // split contact force into normal and tanget 115 | mjVIS_TRANSPARENT, // make dynamic geoms more transparent 116 | mjVIS_AUTOCONNECT, // auto connect joints and body coms 117 | mjVIS_COM, // center of mass 118 | mjVIS_SELECT, // selection point 119 | mjVIS_STATIC, // static bodies 120 | mjVIS_SKIN, // skin 121 | 122 | mjNVISFLAG // number of visualization flags 123 | } mjtVisFlag; 124 | 125 | 126 | typedef enum _mjtRndFlag // flags enabling rendering effects 127 | { 128 | mjRND_SHADOW = 0, // shadows 129 | mjRND_WIREFRAME, // wireframe 130 | mjRND_REFLECTION, // reflections 131 | mjRND_ADDITIVE, // additive transparency 132 | mjRND_SKYBOX, // skybox 133 | mjRND_FOG, // fog 134 | mjRND_HAZE, // haze 135 | mjRND_SEGMENT, // segmentation with random color 136 | mjRND_IDCOLOR, // segmentation with segid color 137 | 138 | mjNRNDFLAG // number of rendering flags 139 | } mjtRndFlag; 140 | 141 | 142 | typedef enum _mjtStereo // type of stereo rendering 143 | { 144 | mjSTEREO_NONE = 0, // no stereo; use left eye only 145 | mjSTEREO_QUADBUFFERED, // quad buffered; revert to side-by-side if no hardware support 146 | mjSTEREO_SIDEBYSIDE // side-by-side 147 | } mjtStereo; 148 | 149 | 150 | struct _mjvPerturb // object selection and perturbation 151 | { 152 | int select; // selected body id; non-positive: none 153 | int skinselect; // selected skin id; negative: none 154 | int active; // perturbation bitmask (mjtPertBit) 155 | int active2; // secondary perturbation bitmask (mjtPertBit) 156 | mjtNum refpos[3]; // desired position for selected object 157 | mjtNum refquat[4]; // desired orientation for selected object 158 | mjtNum localpos[3]; // selection point in object coordinates 159 | mjtNum scale; // relative mouse motion-to-space scaling (set by initPerturb) 160 | }; 161 | typedef struct _mjvPerturb mjvPerturb; 162 | 163 | 164 | struct _mjvCamera // abstract camera 165 | { 166 | // type and ids 167 | int type; // camera type (mjtCamera) 168 | int fixedcamid; // fixed camera id 169 | int trackbodyid; // body id to track 170 | 171 | // abstract camera pose specification 172 | mjtNum lookat[3]; // lookat point 173 | mjtNum distance; // distance to lookat point or tracked body 174 | mjtNum azimuth; // camera azimuth (deg) 175 | mjtNum elevation; // camera elevation (deg) 176 | }; 177 | typedef struct _mjvCamera mjvCamera; 178 | 179 | 180 | struct _mjvGLCamera // OpenGL camera 181 | { 182 | // camera frame 183 | float pos[3]; // position 184 | float forward[3]; // forward direction 185 | float up[3]; // up direction 186 | 187 | // camera projection 188 | float frustum_center; // hor. center (left,right set to match aspect) 189 | float frustum_bottom; // bottom 190 | float frustum_top; // top 191 | float frustum_near; // near 192 | float frustum_far; // far 193 | }; 194 | typedef struct _mjvGLCamera mjvGLCamera; 195 | 196 | 197 | struct _mjvGeom // abstract geom 198 | { 199 | // type info 200 | int type; // geom type (mjtGeom) 201 | int dataid; // mesh, hfield or plane id; -1: none 202 | int objtype; // mujoco object type; mjOBJ_UNKNOWN for decor 203 | int objid; // mujoco object id; -1 for decor 204 | int category; // visual category 205 | int texid; // texture id; -1: no texture 206 | int texuniform; // uniform cube mapping 207 | int texcoord; // mesh geom has texture coordinates 208 | int segid; // segmentation id; -1: not shown 209 | 210 | // OpenGL info 211 | float texrepeat[2]; // texture repetition for 2D mapping 212 | float size[3]; // size parameters 213 | float pos[3]; // Cartesian position 214 | float mat[9]; // Cartesian orientation 215 | float rgba[4]; // color and transparency 216 | float emission; // emission coef 217 | float specular; // specular coef 218 | float shininess; // shininess coef 219 | float reflectance; // reflectance coef 220 | char label[100]; // text label 221 | 222 | // transparency rendering (set internally) 223 | float camdist; // distance to camera (used by sorter) 224 | float modelrbound; // geom rbound from model, 0 if not model geom 225 | mjtByte transparent; // treat geom as transparent 226 | }; 227 | typedef struct _mjvGeom mjvGeom; 228 | 229 | 230 | struct _mjvLight // OpenGL light 231 | { 232 | float pos[3]; // position rel. to body frame 233 | float dir[3]; // direction rel. to body frame 234 | float attenuation[3]; // OpenGL attenuation (quadratic model) 235 | float cutoff; // OpenGL cutoff 236 | float exponent; // OpenGL exponent 237 | float ambient[3]; // ambient rgb (alpha=1) 238 | float diffuse[3]; // diffuse rgb (alpha=1) 239 | float specular[3]; // specular rgb (alpha=1) 240 | mjtByte headlight; // headlight 241 | mjtByte directional; // directional light 242 | mjtByte castshadow; // does light cast shadows 243 | }; 244 | typedef struct _mjvLight mjvLight; 245 | 246 | 247 | struct _mjvOption // abstract visualization options 248 | { 249 | int label; // what objects to label (mjtLabel) 250 | int frame; // which frame to show (mjtFrame) 251 | mjtByte geomgroup[mjNGROUP]; // geom visualization by group 252 | mjtByte sitegroup[mjNGROUP]; // site visualization by group 253 | mjtByte jointgroup[mjNGROUP]; // joint visualization by group 254 | mjtByte tendongroup[mjNGROUP]; // tendon visualization by group 255 | mjtByte actuatorgroup[mjNGROUP]; // actuator visualization by group 256 | mjtByte flags[mjNVISFLAG]; // visualization flags (indexed by mjtVisFlag) 257 | }; 258 | typedef struct _mjvOption mjvOption; 259 | 260 | 261 | struct _mjvScene // abstract scene passed to OpenGL renderer 262 | { 263 | // abstract geoms 264 | int maxgeom; // size of allocated geom buffer 265 | int ngeom; // number of geoms currently in buffer 266 | mjvGeom* geoms; // buffer for geoms 267 | int* geomorder; // buffer for ordering geoms by distance to camera 268 | 269 | // skin data 270 | int nskin; // number of skins 271 | int* skinfacenum; // number of faces in skin 272 | int* skinvertadr; // address of skin vertices 273 | int* skinvertnum; // number of vertices in skin 274 | float* skinvert; // skin vertex data 275 | float* skinnormal; // skin normal data 276 | 277 | // OpenGL lights 278 | int nlight; // number of lights currently in buffer 279 | mjvLight lights[8]; // buffer for lights 280 | 281 | // OpenGL cameras 282 | mjvGLCamera camera[2]; // left and right camera 283 | 284 | // OpenGL model transformation 285 | mjtByte enabletransform; // enable model transformation 286 | float translate[3]; // model translation 287 | float rotate[4]; // model quaternion rotation 288 | float scale; // model scaling 289 | 290 | // OpenGL rendering effects 291 | int stereo; // stereoscopic rendering (mjtStereo) 292 | mjtByte flags[mjNRNDFLAG]; // rendering flags (indexed by mjtRndFlag) 293 | 294 | // framing 295 | int framewidth; // frame pixel width; 0: disable framing 296 | float framergb[3]; // frame color 297 | }; 298 | typedef struct _mjvScene mjvScene; 299 | 300 | 301 | struct _mjvFigure // abstract 2D figure passed to OpenGL renderer 302 | { 303 | // enable flags 304 | int flg_legend; // show legend 305 | int flg_ticklabel[2]; // show grid tick labels (x,y) 306 | int flg_extend; // automatically extend axis ranges to fit data 307 | int flg_barplot; // isolated line segments (i.e. GL_LINES) 308 | int flg_selection; // vertical selection line 309 | int flg_symmetric; // symmetric y-axis 310 | 311 | // style settings 312 | float linewidth; // line width 313 | float gridwidth; // grid line width 314 | int gridsize[2]; // number of grid points in (x,y) 315 | float gridrgb[3]; // grid line rgb 316 | float figurergba[4]; // figure color and alpha 317 | float panergba[4]; // pane color and alpha 318 | float legendrgba[4]; // legend color and alpha 319 | float textrgb[3]; // text color 320 | float linergb[mjMAXLINE][3]; // line colors 321 | float range[2][2]; // axis ranges; (min>=max) automatic 322 | char xformat[20]; // x-tick label format for sprintf 323 | char yformat[20]; // y-tick label format for sprintf 324 | char minwidth[20]; // string used to determine min y-tick width 325 | 326 | // text labels 327 | char title[1000]; // figure title; subplots separated with 2+ spaces 328 | char xlabel[100]; // x-axis label 329 | char linename[mjMAXLINE][100]; // line names for legend 330 | 331 | // dynamic settings 332 | int legendoffset; // number of lines to offset legend 333 | int subplot; // selected subplot (for title rendering) 334 | int highlight[2]; // if point is in legend rect, highlight line 335 | int highlightid; // if id>=0 and no point, highlight id 336 | float selection; // selection line x-value 337 | 338 | // line data 339 | int linepnt[mjMAXLINE]; // number of points in line; (0) disable 340 | float linedata[mjMAXLINE][2*mjMAXLINEPNT]; // line data (x,y) 341 | 342 | // output from renderer 343 | int xaxispixel[2]; // range of x-axis in pixels 344 | int yaxispixel[2]; // range of y-axis in pixels 345 | float xaxisdata[2]; // range of x-axis in data units 346 | float yaxisdata[2]; // range of y-axis in data units 347 | }; 348 | typedef struct _mjvFigure mjvFigure; 349 | 350 | #endif // MUJOCO_MJVISUALIZE_H_ 351 | -------------------------------------------------------------------------------- /mujoco210/include/mjxmacro.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 DeepMind Technologies Limited 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef MUJOCO_MJXMACRO_H_ 16 | #define MUJOCO_MJXMACRO_H_ 17 | 18 | //-------------------------------- mjOption --------------------------------------------- 19 | 20 | // scalar fields of mjOption 21 | #define MJOPTION_SCALARS \ 22 | X( mjtNum, timestep ) \ 23 | X( mjtNum, apirate ) \ 24 | X( mjtNum, impratio ) \ 25 | X( mjtNum, tolerance ) \ 26 | X( mjtNum, noslip_tolerance ) \ 27 | X( mjtNum, mpr_tolerance ) \ 28 | X( mjtNum, density ) \ 29 | X( mjtNum, viscosity ) \ 30 | X( mjtNum, o_margin ) \ 31 | X( int, integrator ) \ 32 | X( int, collision ) \ 33 | X( int, cone ) \ 34 | X( int, jacobian ) \ 35 | X( int, solver ) \ 36 | X( int, iterations ) \ 37 | X( int, noslip_iterations ) \ 38 | X( int, mpr_iterations ) \ 39 | X( int, disableflags ) \ 40 | X( int, enableflags ) 41 | 42 | 43 | // vector fields of mjOption 44 | #define MJOPTION_VECTORS \ 45 | X( gravity, 3 ) \ 46 | X( wind, 3 ) \ 47 | X( magnetic, 3 ) \ 48 | X( o_solref, mjNREF ) \ 49 | X( o_solimp, mjNIMP ) 50 | 51 | 52 | 53 | //-------------------------------- mjModel ---------------------------------------------- 54 | 55 | // int fields of mjModel 56 | #define MJMODEL_INTS \ 57 | X( nq ) \ 58 | X( nv ) \ 59 | X( nu ) \ 60 | X( na ) \ 61 | X( nbody ) \ 62 | X( njnt ) \ 63 | X( ngeom ) \ 64 | X( nsite ) \ 65 | X( ncam ) \ 66 | X( nlight ) \ 67 | X( nmesh ) \ 68 | X( nmeshvert ) \ 69 | X( nmeshtexvert ) \ 70 | X( nmeshface ) \ 71 | X( nmeshgraph ) \ 72 | X( nskin ) \ 73 | X( nskinvert ) \ 74 | X( nskintexvert ) \ 75 | X( nskinface ) \ 76 | X( nskinbone ) \ 77 | X( nskinbonevert ) \ 78 | X( nhfield ) \ 79 | X( nhfielddata ) \ 80 | X( ntex ) \ 81 | X( ntexdata ) \ 82 | X( nmat ) \ 83 | X( npair ) \ 84 | X( nexclude ) \ 85 | X( neq ) \ 86 | X( ntendon ) \ 87 | X( nwrap ) \ 88 | X( nsensor ) \ 89 | X( nnumeric ) \ 90 | X( nnumericdata ) \ 91 | X( ntext ) \ 92 | X( ntextdata ) \ 93 | X( ntuple ) \ 94 | X( ntupledata ) \ 95 | X( nkey ) \ 96 | X( nmocap ) \ 97 | X( nuser_body ) \ 98 | X( nuser_jnt ) \ 99 | X( nuser_geom ) \ 100 | X( nuser_site ) \ 101 | X( nuser_cam ) \ 102 | X( nuser_tendon ) \ 103 | X( nuser_actuator ) \ 104 | X( nuser_sensor ) \ 105 | X( nnames ) \ 106 | X( nM ) \ 107 | X( nemax ) \ 108 | X( njmax ) \ 109 | X( nconmax ) \ 110 | X( nstack ) \ 111 | X( nuserdata ) \ 112 | X( nsensordata ) \ 113 | X( nbuffer ) 114 | 115 | 116 | // pointer fields of mjModel 117 | #define MJMODEL_POINTERS \ 118 | X( mjtNum, qpos0, nq, 1 ) \ 119 | X( mjtNum, qpos_spring, nq, 1 ) \ 120 | X( int, body_parentid, nbody, 1 ) \ 121 | X( int, body_rootid, nbody, 1 ) \ 122 | X( int, body_weldid, nbody, 1 ) \ 123 | X( int, body_mocapid, nbody, 1 ) \ 124 | X( int, body_jntnum, nbody, 1 ) \ 125 | X( int, body_jntadr, nbody, 1 ) \ 126 | X( int, body_dofnum, nbody, 1 ) \ 127 | X( int, body_dofadr, nbody, 1 ) \ 128 | X( int, body_geomnum, nbody, 1 ) \ 129 | X( int, body_geomadr, nbody, 1 ) \ 130 | X( mjtByte, body_simple, nbody, 1 ) \ 131 | X( mjtByte, body_sameframe, nbody, 1 ) \ 132 | X( mjtNum, body_pos, nbody, 3 ) \ 133 | X( mjtNum, body_quat, nbody, 4 ) \ 134 | X( mjtNum, body_ipos, nbody, 3 ) \ 135 | X( mjtNum, body_iquat, nbody, 4 ) \ 136 | X( mjtNum, body_mass, nbody, 1 ) \ 137 | X( mjtNum, body_subtreemass, nbody, 1 ) \ 138 | X( mjtNum, body_inertia, nbody, 3 ) \ 139 | X( mjtNum, body_invweight0, nbody, 2 ) \ 140 | X( mjtNum, body_user, nbody, nuser_body ) \ 141 | X( int, jnt_type, njnt, 1 ) \ 142 | X( int, jnt_qposadr, njnt, 1 ) \ 143 | X( int, jnt_dofadr, njnt, 1 ) \ 144 | X( int, jnt_bodyid, njnt, 1 ) \ 145 | X( int, jnt_group, njnt, 1 ) \ 146 | X( mjtByte, jnt_limited, njnt, 1 ) \ 147 | X( mjtNum, jnt_solref, njnt, mjNREF ) \ 148 | X( mjtNum, jnt_solimp, njnt, mjNIMP ) \ 149 | X( mjtNum, jnt_pos, njnt, 3 ) \ 150 | X( mjtNum, jnt_axis, njnt, 3 ) \ 151 | X( mjtNum, jnt_stiffness, njnt, 1 ) \ 152 | X( mjtNum, jnt_range, njnt, 2 ) \ 153 | X( mjtNum, jnt_margin, njnt, 1 ) \ 154 | X( mjtNum, jnt_user, njnt, nuser_jnt ) \ 155 | X( int, dof_bodyid, nv, 1 ) \ 156 | X( int, dof_jntid, nv, 1 ) \ 157 | X( int, dof_parentid, nv, 1 ) \ 158 | X( int, dof_Madr, nv, 1 ) \ 159 | X( int, dof_simplenum, nv, 1 ) \ 160 | X( mjtNum, dof_solref, nv, mjNREF ) \ 161 | X( mjtNum, dof_solimp, nv, mjNIMP ) \ 162 | X( mjtNum, dof_frictionloss, nv, 1 ) \ 163 | X( mjtNum, dof_armature, nv, 1 ) \ 164 | X( mjtNum, dof_damping, nv, 1 ) \ 165 | X( mjtNum, dof_invweight0, nv, 1 ) \ 166 | X( mjtNum, dof_M0, nv, 1 ) \ 167 | X( int, geom_type, ngeom, 1 ) \ 168 | X( int, geom_contype, ngeom, 1 ) \ 169 | X( int, geom_conaffinity, ngeom, 1 ) \ 170 | X( int, geom_condim, ngeom, 1 ) \ 171 | X( int, geom_bodyid, ngeom, 1 ) \ 172 | X( int, geom_dataid, ngeom, 1 ) \ 173 | X( int, geom_matid, ngeom, 1 ) \ 174 | X( int, geom_group, ngeom, 1 ) \ 175 | X( int, geom_priority, ngeom, 1 ) \ 176 | X( mjtByte, geom_sameframe, ngeom, 1 ) \ 177 | X( mjtNum, geom_solmix, ngeom, 1 ) \ 178 | X( mjtNum, geom_solref, ngeom, mjNREF ) \ 179 | X( mjtNum, geom_solimp, ngeom, mjNIMP ) \ 180 | X( mjtNum, geom_size, ngeom, 3 ) \ 181 | X( mjtNum, geom_rbound, ngeom, 1 ) \ 182 | X( mjtNum, geom_pos, ngeom, 3 ) \ 183 | X( mjtNum, geom_quat, ngeom, 4 ) \ 184 | X( mjtNum, geom_friction, ngeom, 3 ) \ 185 | X( mjtNum, geom_margin, ngeom, 1 ) \ 186 | X( mjtNum, geom_gap, ngeom, 1 ) \ 187 | X( mjtNum, geom_user, ngeom, nuser_geom ) \ 188 | X( float, geom_rgba, ngeom, 4 ) \ 189 | X( int, site_type, nsite, 1 ) \ 190 | X( int, site_bodyid, nsite, 1 ) \ 191 | X( int, site_matid, nsite, 1 ) \ 192 | X( int, site_group, nsite, 1 ) \ 193 | X( mjtByte, site_sameframe, nsite, 1 ) \ 194 | X( mjtNum, site_size, nsite, 3 ) \ 195 | X( mjtNum, site_pos, nsite, 3 ) \ 196 | X( mjtNum, site_quat, nsite, 4 ) \ 197 | X( mjtNum, site_user, nsite, nuser_site ) \ 198 | X( float, site_rgba, nsite, 4 ) \ 199 | X( int, cam_mode, ncam, 1 ) \ 200 | X( int, cam_bodyid, ncam, 1 ) \ 201 | X( int, cam_targetbodyid, ncam, 1 ) \ 202 | X( mjtNum, cam_pos, ncam, 3 ) \ 203 | X( mjtNum, cam_quat, ncam, 4 ) \ 204 | X( mjtNum, cam_poscom0, ncam, 3 ) \ 205 | X( mjtNum, cam_pos0, ncam, 3 ) \ 206 | X( mjtNum, cam_mat0, ncam, 9 ) \ 207 | X( mjtNum, cam_fovy, ncam, 1 ) \ 208 | X( mjtNum, cam_ipd, ncam, 1 ) \ 209 | X( mjtNum, cam_user, ncam, nuser_cam ) \ 210 | X( int, light_mode, nlight, 1 ) \ 211 | X( int, light_bodyid, nlight, 1 ) \ 212 | X( int, light_targetbodyid, nlight, 1 ) \ 213 | X( mjtByte, light_directional, nlight, 1 ) \ 214 | X( mjtByte, light_castshadow, nlight, 1 ) \ 215 | X( mjtByte, light_active, nlight, 1 ) \ 216 | X( mjtNum, light_pos, nlight, 3 ) \ 217 | X( mjtNum, light_dir, nlight, 3 ) \ 218 | X( mjtNum, light_poscom0, nlight, 3 ) \ 219 | X( mjtNum, light_pos0, nlight, 3 ) \ 220 | X( mjtNum, light_dir0, nlight, 3 ) \ 221 | X( float, light_attenuation, nlight, 3 ) \ 222 | X( float, light_cutoff, nlight, 1 ) \ 223 | X( float, light_exponent, nlight, 1 ) \ 224 | X( float, light_ambient, nlight, 3 ) \ 225 | X( float, light_diffuse, nlight, 3 ) \ 226 | X( float, light_specular, nlight, 3 ) \ 227 | X( int, mesh_vertadr, nmesh, 1 ) \ 228 | X( int, mesh_vertnum, nmesh, 1 ) \ 229 | X( int, mesh_texcoordadr, nmesh, 1 ) \ 230 | X( int, mesh_faceadr, nmesh, 1 ) \ 231 | X( int, mesh_facenum, nmesh, 1 ) \ 232 | X( int, mesh_graphadr, nmesh, 1 ) \ 233 | X( float, mesh_vert, nmeshvert, 3 ) \ 234 | X( float, mesh_normal, nmeshvert, 3 ) \ 235 | X( float, mesh_texcoord, nmeshtexvert, 2 ) \ 236 | X( int, mesh_face, nmeshface, 3 ) \ 237 | X( int, mesh_graph, nmeshgraph,1 ) \ 238 | X( int, skin_matid, nskin, 1 ) \ 239 | X( float, skin_rgba, nskin, 4 ) \ 240 | X( float, skin_inflate, nskin, 1 ) \ 241 | X( int, skin_vertadr, nskin, 1 ) \ 242 | X( int, skin_vertnum, nskin, 1 ) \ 243 | X( int, skin_texcoordadr, nskin, 1 ) \ 244 | X( int, skin_faceadr, nskin, 1 ) \ 245 | X( int, skin_facenum, nskin, 1 ) \ 246 | X( int, skin_boneadr, nskin, 1 ) \ 247 | X( int, skin_bonenum, nskin, 1 ) \ 248 | X( float, skin_vert, nskinvert, 3 ) \ 249 | X( float, skin_texcoord, nskintexvert, 2 ) \ 250 | X( int, skin_face, nskinface, 3 ) \ 251 | X( int, skin_bonevertadr, nskinbone, 1 ) \ 252 | X( int, skin_bonevertnum, nskinbone, 1 ) \ 253 | X( float, skin_bonebindpos, nskinbone, 3 ) \ 254 | X( float, skin_bonebindquat, nskinbone, 4 ) \ 255 | X( int, skin_bonebodyid, nskinbone, 1 ) \ 256 | X( int, skin_bonevertid, nskinbonevert, 1 ) \ 257 | X( float, skin_bonevertweight, nskinbonevert, 1 ) \ 258 | X( mjtNum, hfield_size, nhfield, 4 ) \ 259 | X( int, hfield_nrow, nhfield, 1 ) \ 260 | X( int, hfield_ncol, nhfield, 1 ) \ 261 | X( int, hfield_adr, nhfield, 1 ) \ 262 | X( float, hfield_data, nhfielddata, 1 ) \ 263 | X( int, tex_type, ntex, 1 ) \ 264 | X( int, tex_height, ntex, 1 ) \ 265 | X( int, tex_width, ntex, 1 ) \ 266 | X( int, tex_adr, ntex, 1 ) \ 267 | X( mjtByte, tex_rgb, ntexdata, 1 ) \ 268 | X( int, mat_texid, nmat, 1 ) \ 269 | X( mjtByte, mat_texuniform, nmat, 1 ) \ 270 | X( float, mat_texrepeat, nmat, 2 ) \ 271 | X( float, mat_emission, nmat, 1 ) \ 272 | X( float, mat_specular, nmat, 1 ) \ 273 | X( float, mat_shininess, nmat, 1 ) \ 274 | X( float, mat_reflectance, nmat, 1 ) \ 275 | X( float, mat_rgba, nmat, 4 ) \ 276 | X( int, pair_dim, npair, 1 ) \ 277 | X( int, pair_geom1, npair, 1 ) \ 278 | X( int, pair_geom2, npair, 1 ) \ 279 | X( int, pair_signature, npair, 1 ) \ 280 | X( mjtNum, pair_solref, npair, mjNREF ) \ 281 | X( mjtNum, pair_solimp, npair, mjNIMP ) \ 282 | X( mjtNum, pair_margin, npair, 1 ) \ 283 | X( mjtNum, pair_gap, npair, 1 ) \ 284 | X( mjtNum, pair_friction, npair, 5 ) \ 285 | X( int, exclude_signature, nexclude, 1 ) \ 286 | X( int, eq_type, neq, 1 ) \ 287 | X( int, eq_obj1id, neq, 1 ) \ 288 | X( int, eq_obj2id, neq, 1 ) \ 289 | X( mjtByte, eq_active, neq, 1 ) \ 290 | X( mjtNum, eq_solref, neq, mjNREF ) \ 291 | X( mjtNum, eq_solimp, neq, mjNIMP ) \ 292 | X( mjtNum, eq_data, neq, mjNEQDATA ) \ 293 | X( int, tendon_adr, ntendon, 1 ) \ 294 | X( int, tendon_num, ntendon, 1 ) \ 295 | X( int, tendon_matid, ntendon, 1 ) \ 296 | X( int, tendon_group, ntendon, 1 ) \ 297 | X( mjtByte, tendon_limited, ntendon, 1 ) \ 298 | X( mjtNum, tendon_width, ntendon, 1 ) \ 299 | X( mjtNum, tendon_solref_lim, ntendon, mjNREF ) \ 300 | X( mjtNum, tendon_solimp_lim, ntendon, mjNIMP ) \ 301 | X( mjtNum, tendon_solref_fri, ntendon, mjNREF ) \ 302 | X( mjtNum, tendon_solimp_fri, ntendon, mjNIMP ) \ 303 | X( mjtNum, tendon_range, ntendon, 2 ) \ 304 | X( mjtNum, tendon_margin, ntendon, 1 ) \ 305 | X( mjtNum, tendon_stiffness, ntendon, 1 ) \ 306 | X( mjtNum, tendon_damping, ntendon, 1 ) \ 307 | X( mjtNum, tendon_frictionloss, ntendon, 1 ) \ 308 | X( mjtNum, tendon_lengthspring, ntendon, 1 ) \ 309 | X( mjtNum, tendon_length0, ntendon, 1 ) \ 310 | X( mjtNum, tendon_invweight0, ntendon, 1 ) \ 311 | X( mjtNum, tendon_user, ntendon, nuser_tendon) \ 312 | X( float, tendon_rgba, ntendon, 4 ) \ 313 | X( int, wrap_type, nwrap, 1 ) \ 314 | X( int, wrap_objid, nwrap, 1 ) \ 315 | X( mjtNum, wrap_prm, nwrap, 1 ) \ 316 | X( int, actuator_trntype, nu, 1 ) \ 317 | X( int, actuator_dyntype, nu, 1 ) \ 318 | X( int, actuator_gaintype, nu, 1 ) \ 319 | X( int, actuator_biastype, nu, 1 ) \ 320 | X( int, actuator_trnid, nu, 2 ) \ 321 | X( int, actuator_group, nu, 1 ) \ 322 | X( mjtByte, actuator_ctrllimited, nu, 1 ) \ 323 | X( mjtByte, actuator_forcelimited, nu, 1 ) \ 324 | X( mjtNum, actuator_dynprm, nu, mjNDYN ) \ 325 | X( mjtNum, actuator_gainprm, nu, mjNGAIN ) \ 326 | X( mjtNum, actuator_biasprm, nu, mjNBIAS ) \ 327 | X( mjtNum, actuator_ctrlrange, nu, 2 ) \ 328 | X( mjtNum, actuator_forcerange, nu, 2 ) \ 329 | X( mjtNum, actuator_gear, nu, 6 ) \ 330 | X( mjtNum, actuator_cranklength, nu, 1 ) \ 331 | X( mjtNum, actuator_acc0, nu, 1 ) \ 332 | X( mjtNum, actuator_length0, nu, 1 ) \ 333 | X( mjtNum, actuator_lengthrange, nu, 2 ) \ 334 | X( mjtNum, actuator_user, nu, nuser_actuator) \ 335 | X( int, sensor_type, nsensor, 1 ) \ 336 | X( int, sensor_datatype, nsensor, 1 ) \ 337 | X( int, sensor_needstage, nsensor, 1 ) \ 338 | X( int, sensor_objtype, nsensor, 1 ) \ 339 | X( int, sensor_objid, nsensor, 1 ) \ 340 | X( int, sensor_dim, nsensor, 1 ) \ 341 | X( int, sensor_adr, nsensor, 1 ) \ 342 | X( mjtNum, sensor_cutoff, nsensor, 1 ) \ 343 | X( mjtNum, sensor_noise, nsensor, 1 ) \ 344 | X( mjtNum, sensor_user, nsensor, nuser_sensor) \ 345 | X( int, numeric_adr, nnumeric, 1 ) \ 346 | X( int, numeric_size, nnumeric, 1 ) \ 347 | X( mjtNum, numeric_data, nnumericdata, 1 ) \ 348 | X( int, text_adr, ntext, 1 ) \ 349 | X( int, text_size, ntext, 1 ) \ 350 | X( char, text_data, ntextdata, 1 ) \ 351 | X( int, tuple_adr, ntuple, 1 ) \ 352 | X( int, tuple_size, ntuple, 1 ) \ 353 | X( int, tuple_objtype, ntupledata, 1 ) \ 354 | X( int, tuple_objid, ntupledata, 1 ) \ 355 | X( mjtNum, tuple_objprm, ntupledata, 1 ) \ 356 | X( mjtNum, key_time, nkey, 1 ) \ 357 | X( mjtNum, key_qpos, nkey, nq ) \ 358 | X( mjtNum, key_qvel, nkey, nv ) \ 359 | X( mjtNum, key_act, nkey, na ) \ 360 | X( mjtNum, key_mpos, nkey, nmocap3 ) \ 361 | X( mjtNum, key_mquat, nkey, nmocap4 ) \ 362 | X( int, name_bodyadr, nbody, 1 ) \ 363 | X( int, name_jntadr, njnt, 1 ) \ 364 | X( int, name_geomadr, ngeom, 1 ) \ 365 | X( int, name_siteadr, nsite, 1 ) \ 366 | X( int, name_camadr, ncam, 1 ) \ 367 | X( int, name_lightadr, nlight, 1 ) \ 368 | X( int, name_meshadr, nmesh, 1 ) \ 369 | X( int, name_skinadr, nskin, 1 ) \ 370 | X( int, name_hfieldadr, nhfield, 1 ) \ 371 | X( int, name_texadr, ntex, 1 ) \ 372 | X( int, name_matadr, nmat, 1 ) \ 373 | X( int, name_pairadr, npair, 1 ) \ 374 | X( int, name_excludeadr, nexclude, 1 ) \ 375 | X( int, name_eqadr, neq, 1 ) \ 376 | X( int, name_tendonadr, ntendon, 1 ) \ 377 | X( int, name_actuatoradr, nu, 1 ) \ 378 | X( int, name_sensoradr, nsensor, 1 ) \ 379 | X( int, name_numericadr, nnumeric, 1 ) \ 380 | X( int, name_textadr, ntext, 1 ) \ 381 | X( int, name_tupleadr, ntuple, 1 ) \ 382 | X( int, name_keyadr, nkey, 1 ) \ 383 | X( char, names, nnames, 1 ) 384 | 385 | 386 | 387 | //-------------------------------- mjData ----------------------------------------------- 388 | 389 | // pointer fields of mjData 390 | #define MJDATA_POINTERS \ 391 | X( mjtNum, qpos, nq, 1 ) \ 392 | X( mjtNum, qvel, nv, 1 ) \ 393 | X( mjtNum, act, na, 1 ) \ 394 | X( mjtNum, qacc_warmstart, nv, 1 ) \ 395 | X( mjtNum, ctrl, nu, 1 ) \ 396 | X( mjtNum, qfrc_applied, nv, 1 ) \ 397 | X( mjtNum, xfrc_applied, nbody, 6 ) \ 398 | X( mjtNum, qacc, nv, 1 ) \ 399 | X( mjtNum, act_dot, na, 1 ) \ 400 | X( mjtNum, mocap_pos, nmocap, 3 ) \ 401 | X( mjtNum, mocap_quat, nmocap, 4 ) \ 402 | X( mjtNum, userdata, nuserdata, 1 ) \ 403 | X( mjtNum, sensordata, nsensordata,1 ) \ 404 | X( mjtNum, xpos, nbody, 3 ) \ 405 | X( mjtNum, xquat, nbody, 4 ) \ 406 | X( mjtNum, xmat, nbody, 9 ) \ 407 | X( mjtNum, xipos, nbody, 3 ) \ 408 | X( mjtNum, ximat, nbody, 9 ) \ 409 | X( mjtNum, xanchor, njnt, 3 ) \ 410 | X( mjtNum, xaxis, njnt, 3 ) \ 411 | X( mjtNum, geom_xpos, ngeom, 3 ) \ 412 | X( mjtNum, geom_xmat, ngeom, 9 ) \ 413 | X( mjtNum, site_xpos, nsite, 3 ) \ 414 | X( mjtNum, site_xmat, nsite, 9 ) \ 415 | X( mjtNum, cam_xpos, ncam, 3 ) \ 416 | X( mjtNum, cam_xmat, ncam, 9 ) \ 417 | X( mjtNum, light_xpos, nlight, 3 ) \ 418 | X( mjtNum, light_xdir, nlight, 3 ) \ 419 | X( mjtNum, subtree_com, nbody, 3 ) \ 420 | X( mjtNum, cdof, nv, 6 ) \ 421 | X( mjtNum, cinert, nbody, 10 ) \ 422 | X( int, ten_wrapadr, ntendon, 1 ) \ 423 | X( int, ten_wrapnum, ntendon, 1 ) \ 424 | X( int, ten_J_rownnz, ntendon, 1 ) \ 425 | X( int, ten_J_rowadr, ntendon, 1 ) \ 426 | X( int, ten_J_colind, ntendon, nv ) \ 427 | X( mjtNum, ten_length, ntendon, 1 ) \ 428 | X( mjtNum, ten_J, ntendon, nv ) \ 429 | X( int, wrap_obj, nwrap, 2 ) \ 430 | X( mjtNum, wrap_xpos, nwrap, 6 ) \ 431 | X( mjtNum, actuator_length, nu, 1 ) \ 432 | X( mjtNum, actuator_moment, nu, nv ) \ 433 | X( mjtNum, crb, nbody, 10 ) \ 434 | X( mjtNum, qM, nM, 1 ) \ 435 | X( mjtNum, qLD, nM, 1 ) \ 436 | X( mjtNum, qLDiagInv, nv, 1 ) \ 437 | X( mjtNum, qLDiagSqrtInv, nv, 1 ) \ 438 | X( mjContact, contact, nconmax, 1 ) \ 439 | X( int, efc_type, njmax, 1 ) \ 440 | X( int, efc_id, njmax, 1 ) \ 441 | X( int, efc_J_rownnz, njmax, 1 ) \ 442 | X( int, efc_J_rowadr, njmax, 1 ) \ 443 | X( int, efc_J_rowsuper, njmax, 1 ) \ 444 | X( int, efc_J_colind, njmax, nv ) \ 445 | X( int, efc_JT_rownnz, nv, 1 ) \ 446 | X( int, efc_JT_rowadr, nv, 1 ) \ 447 | X( int, efc_JT_rowsuper, nv, 1 ) \ 448 | X( int, efc_JT_colind, nv, njmax ) \ 449 | X( mjtNum, efc_J, njmax, nv ) \ 450 | X( mjtNum, efc_JT, nv, njmax ) \ 451 | X( mjtNum, efc_pos, njmax, 1 ) \ 452 | X( mjtNum, efc_margin, njmax, 1 ) \ 453 | X( mjtNum, efc_frictionloss, njmax, 1 ) \ 454 | X( mjtNum, efc_diagApprox, njmax, 1 ) \ 455 | X( mjtNum, efc_KBIP, njmax, 4 ) \ 456 | X( mjtNum, efc_D, njmax, 1 ) \ 457 | X( mjtNum, efc_R, njmax, 1 ) \ 458 | X( int, efc_AR_rownnz, njmax, 1 ) \ 459 | X( int, efc_AR_rowadr, njmax, 1 ) \ 460 | X( int, efc_AR_colind, njmax, njmax ) \ 461 | X( mjtNum, efc_AR, njmax, njmax ) \ 462 | X( mjtNum, ten_velocity, ntendon, 1 ) \ 463 | X( mjtNum, actuator_velocity, nu, 1 ) \ 464 | X( mjtNum, cvel, nbody, 6 ) \ 465 | X( mjtNum, cdof_dot, nv, 6 ) \ 466 | X( mjtNum, qfrc_bias, nv, 1 ) \ 467 | X( mjtNum, qfrc_passive, nv, 1 ) \ 468 | X( mjtNum, efc_vel, njmax, 1 ) \ 469 | X( mjtNum, efc_aref, njmax, 1 ) \ 470 | X( mjtNum, subtree_linvel, nbody, 3 ) \ 471 | X( mjtNum, subtree_angmom, nbody, 3 ) \ 472 | X( mjtNum, actuator_force, nu, 1 ) \ 473 | X( mjtNum, qfrc_actuator, nv, 1 ) \ 474 | X( mjtNum, qfrc_unc, nv, 1 ) \ 475 | X( mjtNum, qacc_unc, nv, 1 ) \ 476 | X( mjtNum, efc_b, njmax, 1 ) \ 477 | X( mjtNum, efc_force, njmax, 1 ) \ 478 | X( int, efc_state, njmax, 1 ) \ 479 | X( mjtNum, qfrc_constraint, nv, 1 ) \ 480 | X( mjtNum, qfrc_inverse, nv, 1 ) \ 481 | X( mjtNum, cacc, nbody, 6 ) \ 482 | X( mjtNum, cfrc_int, nbody, 6 ) \ 483 | X( mjtNum, cfrc_ext, nbody, 6 ) 484 | 485 | 486 | // scalar fields of mjData 487 | #define MJDATA_SCALAR \ 488 | X( int, nstack ) \ 489 | X( int, nbuffer ) \ 490 | X( int, pstack ) \ 491 | X( int, maxuse_stack ) \ 492 | X( int, maxuse_con ) \ 493 | X( int, maxuse_efc ) \ 494 | X( int, solver_iter ) \ 495 | X( int, solver_nnz ) \ 496 | X( int, ne ) \ 497 | X( int, nf ) \ 498 | X( int, nefc ) \ 499 | X( int, ncon ) \ 500 | X( mjtNum, time ) 501 | 502 | 503 | // vector fields of mjData 504 | #define MJDATA_VECTOR \ 505 | X( mjWarningStat, warning, mjNWARNING, 1 ) \ 506 | X( mjTimerStat, timer, mjNTIMER, 1 ) \ 507 | X( mjSolverStat, solver, mjNSOLVER, 1 ) \ 508 | X( mjtNum, solver_fwdinv, 2, 1 ) \ 509 | X( mjtNum, energy, 2, 1 ) 510 | 511 | #endif // MUJOCO_MJXMACRO_H_ 512 | -------------------------------------------------------------------------------- /mujoco210/include/mujoco.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 DeepMind Technologies Limited 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef MUJOCO_MUJOCO_H_ 16 | #define MUJOCO_MUJOCO_H_ 17 | 18 | // cross-platform import 19 | #if defined(MJ_STATIC) 20 | #define MJAPI 21 | #else 22 | #if defined(_WIN32) 23 | #define MJAPI __declspec(dllimport) 24 | #else 25 | #define MJAPI 26 | #endif 27 | #endif 28 | 29 | 30 | // this is a C-API 31 | #if defined(__cplusplus) 32 | extern "C" 33 | { 34 | #endif 35 | 36 | // header version; should match the library version as returned by mj_version() 37 | #define mjVERSION_HEADER 210 38 | 39 | 40 | // needed to define size_t, fabs and log10 41 | #include "stdlib.h" 42 | #include "math.h" 43 | 44 | 45 | // type definitions 46 | #include "mjmodel.h" 47 | #include "mjdata.h" 48 | #include "mjvisualize.h" 49 | #include "mjrender.h" 50 | #include "mjui.h" 51 | 52 | 53 | // macros 54 | #define mjMARKSTACK int _mark = d->pstack; 55 | #define mjFREESTACK d->pstack = _mark; 56 | #define mjDISABLED(x) (m->opt.disableflags & (x)) 57 | #define mjENABLED(x) (m->opt.enableflags & (x)) 58 | 59 | 60 | // user error and memory handlers 61 | MJAPI extern void (*mju_user_error)(const char*); 62 | MJAPI extern void (*mju_user_warning)(const char*); 63 | MJAPI extern void* (*mju_user_malloc)(size_t); 64 | MJAPI extern void (*mju_user_free)(void*); 65 | 66 | 67 | // callbacks extending computation pipeline 68 | MJAPI extern mjfGeneric mjcb_passive; 69 | MJAPI extern mjfGeneric mjcb_control; 70 | MJAPI extern mjfConFilt mjcb_contactfilter; 71 | MJAPI extern mjfSensor mjcb_sensor; 72 | MJAPI extern mjfTime mjcb_time; 73 | MJAPI extern mjfAct mjcb_act_dyn; 74 | MJAPI extern mjfAct mjcb_act_gain; 75 | MJAPI extern mjfAct mjcb_act_bias; 76 | 77 | 78 | // collision function table 79 | MJAPI extern mjfCollision mjCOLLISIONFUNC[mjNGEOMTYPES][mjNGEOMTYPES]; 80 | 81 | 82 | // string names 83 | MJAPI extern const char* mjDISABLESTRING[mjNDISABLE]; 84 | MJAPI extern const char* mjENABLESTRING[mjNENABLE]; 85 | MJAPI extern const char* mjTIMERSTRING[mjNTIMER]; 86 | MJAPI extern const char* mjLABELSTRING[mjNLABEL]; 87 | MJAPI extern const char* mjFRAMESTRING[mjNFRAME]; 88 | MJAPI extern const char* mjVISSTRING[mjNVISFLAG][3]; 89 | MJAPI extern const char* mjRNDSTRING[mjNRNDFLAG][3]; 90 | 91 | 92 | //---------------------- Activation ----------------------------------------------------- 93 | 94 | // Return 1 (for backward compatibility). 95 | MJAPI int mj_activate(const char* filename); 96 | 97 | // Do nothing (for backward compatibility). 98 | MJAPI void mj_deactivate(void); 99 | 100 | 101 | //---------------------- Virtual file system -------------------------------------------- 102 | 103 | // Initialize VFS to empty (no deallocation). 104 | MJAPI void mj_defaultVFS(mjVFS* vfs); 105 | 106 | // Add file to VFS, return 0: success, 1: full, 2: repeated name, -1: not found on disk. 107 | MJAPI int mj_addFileVFS(mjVFS* vfs, const char* directory, const char* filename); 108 | 109 | // Make empty file in VFS, return 0: success, 1: full, 2: repeated name. 110 | MJAPI int mj_makeEmptyFileVFS(mjVFS* vfs, const char* filename, int filesize); 111 | 112 | // Return file index in VFS, or -1 if not found in VFS. 113 | MJAPI int mj_findFileVFS(const mjVFS* vfs, const char* filename); 114 | 115 | // Delete file from VFS, return 0: success, -1: not found in VFS. 116 | MJAPI int mj_deleteFileVFS(mjVFS* vfs, const char* filename); 117 | 118 | // Delete all files from VFS. 119 | MJAPI void mj_deleteVFS(mjVFS* vfs); 120 | 121 | 122 | //---------------------- Parse and compile ---------------------------------------------- 123 | 124 | // Parse XML file in MJCF or URDF format, compile it, return low-level model. 125 | // If vfs is not NULL, look up files in vfs before reading from disk. 126 | // If error is not NULL, it must have size error_sz. 127 | MJAPI mjModel* mj_loadXML(const char* filename, const mjVFS* vfs, 128 | char* error, int error_sz); 129 | 130 | // Update XML data structures with info from low-level model, save as MJCF. 131 | // If error is not NULL, it must have size error_sz. 132 | MJAPI int mj_saveLastXML(const char* filename, const mjModel* m, 133 | char* error, int error_sz); 134 | 135 | // Free last XML model if loaded. Called internally at each load. 136 | MJAPI void mj_freeLastXML(void); 137 | 138 | // Print internal XML schema as plain text or HTML, with style-padding or  . 139 | MJAPI int mj_printSchema(const char* filename, char* buffer, int buffer_sz, 140 | int flg_html, int flg_pad); 141 | 142 | 143 | //---------------------- Main simulation ------------------------------------------------ 144 | 145 | // Advance simulation, use control callback to obtain external force and control. 146 | MJAPI void mj_step(const mjModel* m, mjData* d); 147 | 148 | // Advance simulation in two steps: before external force and control is set by user. 149 | MJAPI void mj_step1(const mjModel* m, mjData* d); 150 | 151 | // Advance simulation in two steps: after external force and control is set by user. 152 | MJAPI void mj_step2(const mjModel* m, mjData* d); 153 | 154 | // Forward dynamics: same as mj_step but do not integrate in time. 155 | MJAPI void mj_forward(const mjModel* m, mjData* d); 156 | 157 | // Inverse dynamics: qacc must be set before calling. 158 | MJAPI void mj_inverse(const mjModel* m, mjData* d); 159 | 160 | // Forward dynamics with skip; skipstage is mjtStage. 161 | MJAPI void mj_forwardSkip(const mjModel* m, mjData* d, 162 | int skipstage, int skipsensor); 163 | 164 | // Inverse dynamics with skip; skipstage is mjtStage. 165 | MJAPI void mj_inverseSkip(const mjModel* m, mjData* d, 166 | int skipstage, int skipsensor); 167 | 168 | 169 | //---------------------- Initialization ------------------------------------------------- 170 | 171 | // Set default options for length range computation. 172 | MJAPI void mj_defaultLROpt(mjLROpt* opt); 173 | 174 | // Set solver parameters to default values. 175 | MJAPI void mj_defaultSolRefImp(mjtNum* solref, mjtNum* solimp); 176 | 177 | // Set physics options to default values. 178 | MJAPI void mj_defaultOption(mjOption* opt); 179 | 180 | // Set visual options to default values. 181 | MJAPI void mj_defaultVisual(mjVisual* vis); 182 | 183 | // Copy mjModel, allocate new if dest is NULL. 184 | MJAPI mjModel* mj_copyModel(mjModel* dest, const mjModel* src); 185 | 186 | // Save model to binary MJB file or memory buffer; buffer has precedence when given. 187 | MJAPI void mj_saveModel(const mjModel* m, const char* filename, void* buffer, int buffer_sz); 188 | 189 | // Load model from binary MJB file. 190 | // If vfs is not NULL, look up file in vfs before reading from disk. 191 | MJAPI mjModel* mj_loadModel(const char* filename, const mjVFS* vfs); 192 | 193 | // Free memory allocation in model. 194 | MJAPI void mj_deleteModel(mjModel* m); 195 | 196 | // Return size of buffer needed to hold model. 197 | MJAPI int mj_sizeModel(const mjModel* m); 198 | 199 | // Allocate mjData correponding to given model. 200 | MJAPI mjData* mj_makeData(const mjModel* m); 201 | 202 | // Copy mjData. 203 | MJAPI mjData* mj_copyData(mjData* dest, const mjModel* m, const mjData* src); 204 | 205 | // Reset data to defaults. 206 | MJAPI void mj_resetData(const mjModel* m, mjData* d); 207 | 208 | // Reset data to defaults, fill everything else with debug_value. 209 | MJAPI void mj_resetDataDebug(const mjModel* m, mjData* d, unsigned char debug_value); 210 | 211 | // Reset data, set fields from specified keyframe. 212 | MJAPI void mj_resetDataKeyframe(const mjModel* m, mjData* d, int key); 213 | 214 | // Allocate array of specified size on mjData stack. Call mju_error on stack overflow. 215 | MJAPI mjtNum* mj_stackAlloc(mjData* d, int size); 216 | 217 | // Free memory allocation in mjData. 218 | MJAPI void mj_deleteData(mjData* d); 219 | 220 | // Reset all callbacks to NULL pointers (NULL is the default). 221 | MJAPI void mj_resetCallbacks(void); 222 | 223 | // Set constant fields of mjModel, corresponding to qpos0 configuration. 224 | MJAPI void mj_setConst(mjModel* m, mjData* d); 225 | 226 | // Set actuator_lengthrange for specified actuator; return 1 if ok, 0 if error. 227 | MJAPI int mj_setLengthRange(mjModel* m, mjData* d, int index, 228 | const mjLROpt* opt, char* error, int error_sz); 229 | 230 | 231 | //---------------------- Printing ------------------------------------------------------- 232 | 233 | // Print model to text file. 234 | MJAPI void mj_printModel(const mjModel* m, const char* filename); 235 | 236 | // Print data to text file. 237 | MJAPI void mj_printData(const mjModel* m, mjData* d, const char* filename); 238 | 239 | // Print matrix to screen. 240 | MJAPI void mju_printMat(const mjtNum* mat, int nr, int nc); 241 | 242 | // Print sparse matrix to screen. 243 | MJAPI void mju_printMatSparse(const mjtNum* mat, int nr, 244 | const int* rownnz, const int* rowadr, 245 | const int* colind); 246 | 247 | 248 | //---------------------- Components ----------------------------------------------------- 249 | 250 | // Run position-dependent computations. 251 | MJAPI void mj_fwdPosition(const mjModel* m, mjData* d); 252 | 253 | // Run velocity-dependent computations. 254 | MJAPI void mj_fwdVelocity(const mjModel* m, mjData* d); 255 | 256 | // Compute actuator force qfrc_actuation. 257 | MJAPI void mj_fwdActuation(const mjModel* m, mjData* d); 258 | 259 | // Add up all non-constraint forces, compute qacc_unc. 260 | MJAPI void mj_fwdAcceleration(const mjModel* m, mjData* d); 261 | 262 | // Run selected constraint solver. 263 | MJAPI void mj_fwdConstraint(const mjModel* m, mjData* d); 264 | 265 | // Euler integrator, semi-implicit in velocity. 266 | MJAPI void mj_Euler(const mjModel* m, mjData* d); 267 | 268 | // Runge-Kutta explicit order-N integrator. 269 | MJAPI void mj_RungeKutta(const mjModel* m, mjData* d, int N); 270 | 271 | // Run position-dependent computations in inverse dynamics. 272 | MJAPI void mj_invPosition(const mjModel* m, mjData* d); 273 | 274 | // Run velocity-dependent computations in inverse dynamics. 275 | MJAPI void mj_invVelocity(const mjModel* m, mjData* d); 276 | 277 | // Apply the analytical formula for inverse constraint dynamics. 278 | MJAPI void mj_invConstraint(const mjModel* m, mjData* d); 279 | 280 | // Compare forward and inverse dynamics, save results in fwdinv. 281 | MJAPI void mj_compareFwdInv(const mjModel* m, mjData* d); 282 | 283 | 284 | //---------------------- Sub components ------------------------------------------------- 285 | 286 | // Evaluate position-dependent sensors. 287 | MJAPI void mj_sensorPos(const mjModel* m, mjData* d); 288 | 289 | // Evaluate velocity-dependent sensors. 290 | MJAPI void mj_sensorVel(const mjModel* m, mjData* d); 291 | 292 | // Evaluate acceleration and force-dependent sensors. 293 | MJAPI void mj_sensorAcc(const mjModel* m, mjData* d); 294 | 295 | // Evaluate position-dependent energy (potential). 296 | MJAPI void mj_energyPos(const mjModel* m, mjData* d); 297 | 298 | // Evaluate velocity-dependent energy (kinetic). 299 | MJAPI void mj_energyVel(const mjModel* m, mjData* d); 300 | 301 | // Check qpos, reset if any element is too big or nan. 302 | MJAPI void mj_checkPos(const mjModel* m, mjData* d); 303 | 304 | // Check qvel, reset if any element is too big or nan. 305 | MJAPI void mj_checkVel(const mjModel* m, mjData* d); 306 | 307 | // Check qacc, reset if any element is too big or nan. 308 | MJAPI void mj_checkAcc(const mjModel* m, mjData* d); 309 | 310 | // Run forward kinematics. 311 | MJAPI void mj_kinematics(const mjModel* m, mjData* d); 312 | 313 | // Map inertias and motion dofs to global frame centered at CoM. 314 | MJAPI void mj_comPos(const mjModel* m, mjData* d); 315 | 316 | // Compute camera and light positions and orientations. 317 | MJAPI void mj_camlight(const mjModel* m, mjData* d); 318 | 319 | // Compute tendon lengths, velocities and moment arms. 320 | MJAPI void mj_tendon(const mjModel* m, mjData* d); 321 | 322 | // Compute actuator transmission lengths and moments. 323 | MJAPI void mj_transmission(const mjModel* m, mjData* d); 324 | 325 | // Run composite rigid body inertia algorithm (CRB). 326 | MJAPI void mj_crb(const mjModel* m, mjData* d); 327 | 328 | // Compute sparse L'*D*L factorizaton of inertia matrix. 329 | MJAPI void mj_factorM(const mjModel* m, mjData* d); 330 | 331 | // Solve linear system M * x = y using factorization: x = inv(L'*D*L)*y 332 | MJAPI void mj_solveM(const mjModel* m, mjData* d, mjtNum* x, const mjtNum* y, int n); 333 | 334 | // Half of linear solve: x = sqrt(inv(D))*inv(L')*y 335 | MJAPI void mj_solveM2(const mjModel* m, mjData* d, mjtNum* x, const mjtNum* y, int n); 336 | 337 | // Compute cvel, cdof_dot. 338 | MJAPI void mj_comVel(const mjModel* m, mjData* d); 339 | 340 | // Compute qfrc_passive from spring-dampers, viscosity and density. 341 | MJAPI void mj_passive(const mjModel* m, mjData* d); 342 | 343 | // subtree linear velocity and angular momentum 344 | MJAPI void mj_subtreeVel(const mjModel* m, mjData* d); 345 | 346 | // RNE: compute M(qpos)*qacc + C(qpos,qvel); flg_acc=0 removes inertial term. 347 | MJAPI void mj_rne(const mjModel* m, mjData* d, int flg_acc, mjtNum* result); 348 | 349 | // RNE with complete data: compute cacc, cfrc_ext, cfrc_int. 350 | MJAPI void mj_rnePostConstraint(const mjModel* m, mjData* d); 351 | 352 | // Run collision detection. 353 | MJAPI void mj_collision(const mjModel* m, mjData* d); 354 | 355 | // Construct constraints. 356 | MJAPI void mj_makeConstraint(const mjModel* m, mjData* d); 357 | 358 | // Compute inverse constaint inertia efc_AR. 359 | MJAPI void mj_projectConstraint(const mjModel* m, mjData* d); 360 | 361 | // Compute efc_vel, efc_aref. 362 | MJAPI void mj_referenceConstraint(const mjModel* m, mjData* d); 363 | 364 | // Compute efc_state, efc_force, qfrc_constraint, and (optionally) cone Hessians. 365 | // If cost is not NULL, set *cost = s(jar) where jar = Jac*qacc-aref. 366 | MJAPI void mj_constraintUpdate(const mjModel* m, mjData* d, const mjtNum* jar, 367 | mjtNum* cost, int flg_coneHessian); 368 | 369 | 370 | //---------------------- Support -------------------------------------------------------- 371 | 372 | // Add contact to d->contact list; return 0 if success; 1 if buffer full. 373 | MJAPI int mj_addContact(const mjModel* m, mjData* d, const mjContact* con); 374 | 375 | // Determine type of friction cone. 376 | MJAPI int mj_isPyramidal(const mjModel* m); 377 | 378 | // Determine type of constraint Jacobian. 379 | MJAPI int mj_isSparse(const mjModel* m); 380 | 381 | // Determine type of solver (PGS is dual, CG and Newton are primal). 382 | MJAPI int mj_isDual(const mjModel* m); 383 | 384 | // Multiply dense or sparse constraint Jacobian by vector. 385 | MJAPI void mj_mulJacVec(const mjModel* m, mjData* d, 386 | mjtNum* res, const mjtNum* vec); 387 | 388 | // Multiply dense or sparse constraint Jacobian transpose by vector. 389 | MJAPI void mj_mulJacTVec(const mjModel* m, mjData* d, mjtNum* res, const mjtNum* vec); 390 | 391 | // Compute 3/6-by-nv end-effector Jacobian of global point attached to given body. 392 | MJAPI void mj_jac(const mjModel* m, const mjData* d, 393 | mjtNum* jacp, mjtNum* jacr, const mjtNum point[3], int body); 394 | 395 | // Compute body frame end-effector Jacobian. 396 | MJAPI void mj_jacBody(const mjModel* m, const mjData* d, 397 | mjtNum* jacp, mjtNum* jacr, int body); 398 | 399 | // Compute body center-of-mass end-effector Jacobian. 400 | MJAPI void mj_jacBodyCom(const mjModel* m, const mjData* d, 401 | mjtNum* jacp, mjtNum* jacr, int body); 402 | 403 | // Compute geom end-effector Jacobian. 404 | MJAPI void mj_jacGeom(const mjModel* m, const mjData* d, 405 | mjtNum* jacp, mjtNum* jacr, int geom); 406 | 407 | // Compute site end-effector Jacobian. 408 | MJAPI void mj_jacSite(const mjModel* m, const mjData* d, 409 | mjtNum* jacp, mjtNum* jacr, int site); 410 | 411 | // Compute translation end-effector Jacobian of point, and rotation Jacobian of axis. 412 | MJAPI void mj_jacPointAxis(const mjModel* m, mjData* d, 413 | mjtNum* jacPoint, mjtNum* jacAxis, 414 | const mjtNum point[3], const mjtNum axis[3], int body); 415 | 416 | // Get id of object with specified name, return -1 if not found; type is mjtObj. 417 | MJAPI int mj_name2id(const mjModel* m, int type, const char* name); 418 | 419 | // Get name of object with specified id, return 0 if invalid type or id; type is mjtObj. 420 | MJAPI const char* mj_id2name(const mjModel* m, int type, int id); 421 | 422 | // Convert sparse inertia matrix M into full (i.e. dense) matrix. 423 | MJAPI void mj_fullM(const mjModel* m, mjtNum* dst, const mjtNum* M); 424 | 425 | // Multiply vector by inertia matrix. 426 | MJAPI void mj_mulM(const mjModel* m, const mjData* d, mjtNum* res, const mjtNum* vec); 427 | 428 | // Multiply vector by (inertia matrix)^(1/2). 429 | MJAPI void mj_mulM2(const mjModel* m, const mjData* d, mjtNum* res, const mjtNum* vec); 430 | 431 | // Add inertia matrix to destination matrix. 432 | // Destination can be sparse uncompressed, or dense when all int* are NULL 433 | MJAPI void mj_addM(const mjModel* m, mjData* d, mjtNum* dst, 434 | int* rownnz, int* rowadr, int* colind); 435 | 436 | // Apply cartesian force and torque (outside xfrc_applied mechanism). 437 | MJAPI void mj_applyFT(const mjModel* m, mjData* d, 438 | const mjtNum* force, const mjtNum* torque, 439 | const mjtNum* point, int body, mjtNum* qfrc_target); 440 | 441 | // Compute object 6D velocity in object-centered frame, world/local orientation. 442 | MJAPI void mj_objectVelocity(const mjModel* m, const mjData* d, 443 | int objtype, int objid, mjtNum* res, int flg_local); 444 | 445 | // Compute object 6D acceleration in object-centered frame, world/local orientation. 446 | MJAPI void mj_objectAcceleration(const mjModel* m, const mjData* d, 447 | int objtype, int objid, mjtNum* res, int flg_local); 448 | 449 | // Extract 6D force:torque for one contact, in contact frame. 450 | MJAPI void mj_contactForce(const mjModel* m, const mjData* d, int id, mjtNum* result); 451 | 452 | // Compute velocity by finite-differencing two positions. 453 | MJAPI void mj_differentiatePos(const mjModel* m, mjtNum* qvel, mjtNum dt, 454 | const mjtNum* qpos1, const mjtNum* qpos2); 455 | 456 | // Integrate position with given velocity. 457 | MJAPI void mj_integratePos(const mjModel* m, mjtNum* qpos, const mjtNum* qvel, mjtNum dt); 458 | 459 | // Normalize all quaterions in qpos-type vector. 460 | MJAPI void mj_normalizeQuat(const mjModel* m, mjtNum* qpos); 461 | 462 | // Map from body local to global Cartesian coordinates. 463 | MJAPI void mj_local2Global(mjData* d, mjtNum* xpos, mjtNum* xmat, 464 | const mjtNum* pos, const mjtNum* quat, 465 | int body, mjtByte sameframe); 466 | 467 | // Sum all body masses. 468 | MJAPI mjtNum mj_getTotalmass(const mjModel* m); 469 | 470 | // Scale body masses and inertias to achieve specified total mass. 471 | MJAPI void mj_setTotalmass(mjModel* m, mjtNum newmass); 472 | 473 | // Return version number: 1.0.2 is encoded as 102. 474 | MJAPI int mj_version(void); 475 | 476 | 477 | //---------------------- Ray collisions ------------------------------------------------- 478 | 479 | // Intersect ray (pnt+x*vec, x>=0) with visible geoms, except geoms in bodyexclude. 480 | // Return geomid and distance (x) to nearest surface, or -1 if no intersection. 481 | // geomgroup, flg_static are as in mjvOption; geomgroup==NULL skips group exclusion. 482 | MJAPI mjtNum mj_ray(const mjModel* m, const mjData* d, const mjtNum* pnt, const mjtNum* vec, 483 | const mjtByte* geomgroup, mjtByte flg_static, int bodyexclude, 484 | int* geomid); 485 | 486 | // Interect ray with hfield, return nearest distance or -1 if no intersection. 487 | MJAPI mjtNum mj_rayHfield(const mjModel* m, const mjData* d, int geomid, 488 | const mjtNum* pnt, const mjtNum* vec); 489 | 490 | // Interect ray with mesh, return nearest distance or -1 if no intersection. 491 | MJAPI mjtNum mj_rayMesh(const mjModel* m, const mjData* d, int geomid, 492 | const mjtNum* pnt, const mjtNum* vec); 493 | 494 | // Interect ray with pure geom, return nearest distance or -1 if no intersection. 495 | MJAPI mjtNum mju_rayGeom(const mjtNum* pos, const mjtNum* mat, const mjtNum* size, 496 | const mjtNum* pnt, const mjtNum* vec, int geomtype); 497 | 498 | // Interect ray with skin, return nearest vertex id. 499 | MJAPI mjtNum mju_raySkin(int nface, int nvert, const int* face, const float* vert, 500 | const mjtNum* pnt, const mjtNum* vec, int* vertid); 501 | 502 | 503 | //---------------------- Interaction ---------------------------------------------------- 504 | 505 | // Set default camera. 506 | MJAPI void mjv_defaultCamera(mjvCamera* cam); 507 | 508 | // Set default perturbation. 509 | MJAPI void mjv_defaultPerturb(mjvPerturb* pert); 510 | 511 | // Transform pose from room to model space. 512 | MJAPI void mjv_room2model(mjtNum* modelpos, mjtNum* modelquat, const mjtNum* roompos, 513 | const mjtNum* roomquat, const mjvScene* scn); 514 | 515 | // Transform pose from model to room space. 516 | MJAPI void mjv_model2room(mjtNum* roompos, mjtNum* roomquat, const mjtNum* modelpos, 517 | const mjtNum* modelquat, const mjvScene* scn); 518 | 519 | // Get camera info in model space; average left and right OpenGL cameras. 520 | MJAPI void mjv_cameraInModel(mjtNum* headpos, mjtNum* forward, mjtNum* up, 521 | const mjvScene* scn); 522 | 523 | // Get camera info in room space; average left and right OpenGL cameras. 524 | MJAPI void mjv_cameraInRoom(mjtNum* headpos, mjtNum* forward, mjtNum* up, 525 | const mjvScene* scn); 526 | 527 | // Get frustum height at unit distance from camera; average left and right OpenGL cameras. 528 | MJAPI mjtNum mjv_frustumHeight(const mjvScene* scn); 529 | 530 | // Rotate 3D vec in horizontal plane by angle between (0,1) and (forward_x,forward_y). 531 | MJAPI void mjv_alignToCamera(mjtNum* res, const mjtNum* vec, const mjtNum* forward); 532 | 533 | // Move camera with mouse; action is mjtMouse. 534 | MJAPI void mjv_moveCamera(const mjModel* m, int action, mjtNum reldx, mjtNum reldy, 535 | const mjvScene* scn, mjvCamera* cam); 536 | 537 | // Move perturb object with mouse; action is mjtMouse. 538 | MJAPI void mjv_movePerturb(const mjModel* m, const mjData* d, int action, mjtNum reldx, 539 | mjtNum reldy, const mjvScene* scn, mjvPerturb* pert); 540 | 541 | // Move model with mouse; action is mjtMouse. 542 | MJAPI void mjv_moveModel(const mjModel* m, int action, mjtNum reldx, mjtNum reldy, 543 | const mjtNum* roomup, mjvScene* scn); 544 | 545 | // Copy perturb pos,quat from selected body; set scale for perturbation. 546 | MJAPI void mjv_initPerturb(const mjModel* m, const mjData* d, 547 | const mjvScene* scn, mjvPerturb* pert); 548 | 549 | // Set perturb pos,quat in d->mocap when selected body is mocap, and in d->qpos otherwise. 550 | // Write d->qpos only if flg_paused and subtree root for selected body has free joint. 551 | MJAPI void mjv_applyPerturbPose(const mjModel* m, mjData* d, const mjvPerturb* pert, 552 | int flg_paused); 553 | 554 | // Set perturb force,torque in d->xfrc_applied, if selected body is dynamic. 555 | MJAPI void mjv_applyPerturbForce(const mjModel* m, mjData* d, const mjvPerturb* pert); 556 | 557 | // Return the average of two OpenGL cameras. 558 | MJAPI mjvGLCamera mjv_averageCamera(const mjvGLCamera* cam1, const mjvGLCamera* cam2); 559 | 560 | // Select geom or skin with mouse, return bodyid; -1: none selected. 561 | MJAPI int mjv_select(const mjModel* m, const mjData* d, const mjvOption* vopt, 562 | mjtNum aspectratio, mjtNum relx, mjtNum rely, 563 | const mjvScene* scn, mjtNum* selpnt, int* geomid, int* skinid); 564 | 565 | 566 | //---------------------- Visualization -------------------------------------------------- 567 | 568 | // Set default visualization options. 569 | MJAPI void mjv_defaultOption(mjvOption* opt); 570 | 571 | // Set default figure. 572 | MJAPI void mjv_defaultFigure(mjvFigure* fig); 573 | 574 | // Initialize given geom fields when not NULL, set the rest to their default values. 575 | MJAPI void mjv_initGeom(mjvGeom* geom, int type, const mjtNum* size, 576 | const mjtNum* pos, const mjtNum* mat, const float* rgba); 577 | 578 | // Set (type, size, pos, mat) for connector-type geom between given points. 579 | // Assume that mjv_initGeom was already called to set all other properties. 580 | MJAPI void mjv_makeConnector(mjvGeom* geom, int type, mjtNum width, 581 | mjtNum a0, mjtNum a1, mjtNum a2, 582 | mjtNum b0, mjtNum b1, mjtNum b2); 583 | 584 | // Set default abstract scene. 585 | MJAPI void mjv_defaultScene(mjvScene* scn); 586 | 587 | // Allocate resources in abstract scene. 588 | MJAPI void mjv_makeScene(const mjModel* m, mjvScene* scn, int maxgeom); 589 | 590 | // Free abstract scene. 591 | MJAPI void mjv_freeScene(mjvScene* scn); 592 | 593 | // Update entire scene given model state. 594 | MJAPI void mjv_updateScene(const mjModel* m, mjData* d, const mjvOption* opt, 595 | const mjvPerturb* pert, mjvCamera* cam, int catmask, mjvScene* scn); 596 | 597 | // Add geoms from selected categories. 598 | MJAPI void mjv_addGeoms(const mjModel* m, mjData* d, const mjvOption* opt, 599 | const mjvPerturb* pert, int catmask, mjvScene* scn); 600 | 601 | // Make list of lights. 602 | MJAPI void mjv_makeLights(const mjModel* m, mjData* d, mjvScene* scn); 603 | 604 | // Update camera. 605 | MJAPI void mjv_updateCamera(const mjModel* m, mjData* d, mjvCamera* cam, mjvScene* scn); 606 | 607 | // Update skins. 608 | MJAPI void mjv_updateSkin(const mjModel* m, mjData* d, mjvScene* scn); 609 | 610 | 611 | //---------------------- OpenGL rendering ----------------------------------------------- 612 | 613 | // Set default mjrContext. 614 | MJAPI void mjr_defaultContext(mjrContext* con); 615 | 616 | // Allocate resources in custom OpenGL context; fontscale is mjtFontScale. 617 | MJAPI void mjr_makeContext(const mjModel* m, mjrContext* con, int fontscale); 618 | 619 | // Change font of existing context. 620 | MJAPI void mjr_changeFont(int fontscale, mjrContext* con); 621 | 622 | // Add Aux buffer with given index to context; free previous Aux buffer. 623 | MJAPI void mjr_addAux(int index, int width, int height, int samples, mjrContext* con); 624 | 625 | // Free resources in custom OpenGL context, set to default. 626 | MJAPI void mjr_freeContext(mjrContext* con); 627 | 628 | // Upload texture to GPU, overwriting previous upload if any. 629 | MJAPI void mjr_uploadTexture(const mjModel* m, const mjrContext* con, int texid); 630 | 631 | // Upload mesh to GPU, overwriting previous upload if any. 632 | MJAPI void mjr_uploadMesh(const mjModel* m, const mjrContext* con, int meshid); 633 | 634 | // Upload height field to GPU, overwriting previous upload if any. 635 | MJAPI void mjr_uploadHField(const mjModel* m, const mjrContext* con, int hfieldid); 636 | 637 | // Make con->currentBuffer current again. 638 | MJAPI void mjr_restoreBuffer(const mjrContext* con); 639 | 640 | // Set OpenGL framebuffer for rendering: mjFB_WINDOW or mjFB_OFFSCREEN. 641 | // If only one buffer is available, set that buffer and ignore framebuffer argument. 642 | MJAPI void mjr_setBuffer(int framebuffer, mjrContext* con); 643 | 644 | // Read pixels from current OpenGL framebuffer to client buffer. 645 | // Viewport is in OpenGL framebuffer; client buffer starts at (0,0). 646 | MJAPI void mjr_readPixels(unsigned char* rgb, float* depth, 647 | mjrRect viewport, const mjrContext* con); 648 | 649 | // Draw pixels from client buffer to current OpenGL framebuffer. 650 | // Viewport is in OpenGL framebuffer; client buffer starts at (0,0). 651 | MJAPI void mjr_drawPixels(const unsigned char* rgb, const float* depth, 652 | mjrRect viewport, const mjrContext* con); 653 | 654 | // Blit from src viewpoint in current framebuffer to dst viewport in other framebuffer. 655 | // If src, dst have different size and flg_depth==0, color is interpolated with GL_LINEAR. 656 | MJAPI void mjr_blitBuffer(mjrRect src, mjrRect dst, 657 | int flg_color, int flg_depth, const mjrContext* con); 658 | 659 | // Set Aux buffer for custom OpenGL rendering (call restoreBuffer when done). 660 | MJAPI void mjr_setAux(int index, const mjrContext* con); 661 | 662 | // Blit from Aux buffer to con->currentBuffer. 663 | MJAPI void mjr_blitAux(int index, mjrRect src, int left, int bottom, 664 | const mjrContext* con); 665 | 666 | // Draw text at (x,y) in relative coordinates; font is mjtFont. 667 | MJAPI void mjr_text(int font, const char* txt, const mjrContext* con, 668 | float x, float y, float r, float g, float b); 669 | 670 | // Draw text overlay; font is mjtFont; gridpos is mjtGridPos. 671 | MJAPI void mjr_overlay(int font, int gridpos, mjrRect viewport, 672 | const char* overlay, const char* overlay2, const mjrContext* con); 673 | 674 | // Get maximum viewport for active buffer. 675 | MJAPI mjrRect mjr_maxViewport(const mjrContext* con); 676 | 677 | // Draw rectangle. 678 | MJAPI void mjr_rectangle(mjrRect viewport, float r, float g, float b, float a); 679 | 680 | // Draw rectangle with centered text. 681 | MJAPI void mjr_label(mjrRect viewport, int font, const char* txt, 682 | float r, float g, float b, float a, float rt, float gt, float bt, 683 | const mjrContext* con); 684 | 685 | // Draw 2D figure. 686 | MJAPI void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con); 687 | 688 | // Render 3D scene. 689 | MJAPI void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con); 690 | 691 | // Call glFinish. 692 | MJAPI void mjr_finish(void); 693 | 694 | // Call glGetError and return result. 695 | MJAPI int mjr_getError(void); 696 | 697 | // Find first rectangle containing mouse, -1: not found. 698 | MJAPI int mjr_findRect(int x, int y, int nrect, const mjrRect* rect); 699 | 700 | 701 | //---------------------- UI framework --------------------------------------------------- 702 | 703 | // Get builtin UI theme spacing (ind: 0-1). 704 | MJAPI mjuiThemeSpacing mjui_themeSpacing(int ind); 705 | 706 | // Get builtin UI theme color (ind: 0-3). 707 | MJAPI mjuiThemeColor mjui_themeColor(int ind); 708 | 709 | // Add definitions to UI. 710 | MJAPI void mjui_add(mjUI* ui, const mjuiDef* def); 711 | 712 | // Add definitions to UI section. 713 | MJAPI void mjui_addToSection(mjUI* ui, int sect, const mjuiDef* def); 714 | 715 | // Compute UI sizes. 716 | MJAPI void mjui_resize(mjUI* ui, const mjrContext* con); 717 | 718 | // Update specific section/item; -1: update all. 719 | MJAPI void mjui_update(int section, int item, const mjUI* ui, 720 | const mjuiState* state, const mjrContext* con); 721 | 722 | // Handle UI event, return pointer to changed item, NULL if no change. 723 | MJAPI mjuiItem* mjui_event(mjUI* ui, mjuiState* state, const mjrContext* con); 724 | 725 | // Copy UI image to current buffer. 726 | MJAPI void mjui_render(mjUI* ui, const mjuiState* state, const mjrContext* con); 727 | 728 | 729 | //---------------------- Error and memory ----------------------------------------------- 730 | 731 | // Main error function; does not return to caller. 732 | MJAPI void mju_error(const char* msg); 733 | 734 | // Error function with int argument; msg is a printf format string. 735 | MJAPI void mju_error_i(const char* msg, int i); 736 | 737 | // Error function with string argument. 738 | MJAPI void mju_error_s(const char* msg, const char* text); 739 | 740 | // Main warning function; returns to caller. 741 | MJAPI void mju_warning(const char* msg); 742 | 743 | // Warning function with int argument. 744 | MJAPI void mju_warning_i(const char* msg, int i); 745 | 746 | // Warning function with string argument. 747 | MJAPI void mju_warning_s(const char* msg, const char* text); 748 | 749 | // Clear user error and memory handlers. 750 | MJAPI void mju_clearHandlers(void); 751 | 752 | // Allocate memory; byte-align on 8; pad size to multiple of 8. 753 | MJAPI void* mju_malloc(size_t size); 754 | 755 | // Free memory, using free() by default. 756 | MJAPI void mju_free(void* ptr); 757 | 758 | // High-level warning function: count warnings in mjData, print only the first. 759 | MJAPI void mj_warning(mjData* d, int warning, int info); 760 | 761 | // Write [datetime, type: message] to MUJOCO_LOG.TXT. 762 | MJAPI void mju_writeLog(const char* type, const char* msg); 763 | 764 | 765 | //---------------------- Standard math -------------------------------------------------- 766 | 767 | #define mjMAX(a,b) (((a) > (b)) ? (a) : (b)) 768 | #define mjMIN(a,b) (((a) < (b)) ? (a) : (b)) 769 | 770 | #ifdef mjUSEDOUBLE 771 | #define mju_sqrt sqrt 772 | #define mju_exp exp 773 | #define mju_sin sin 774 | #define mju_cos cos 775 | #define mju_tan tan 776 | #define mju_asin asin 777 | #define mju_acos acos 778 | #define mju_atan2 atan2 779 | #define mju_tanh tanh 780 | #define mju_pow pow 781 | #define mju_abs fabs 782 | #define mju_log log 783 | #define mju_log10 log10 784 | #define mju_floor floor 785 | #define mju_ceil ceil 786 | 787 | #else 788 | #define mju_sqrt sqrtf 789 | #define mju_exp expf 790 | #define mju_sin sinf 791 | #define mju_cos cosf 792 | #define mju_tan tanf 793 | #define mju_asin asinf 794 | #define mju_acos acosf 795 | #define mju_atan2 atan2f 796 | #define mju_tanh tanhf 797 | #define mju_pow powf 798 | #define mju_abs fabsf 799 | #define mju_log logf 800 | #define mju_log10 log10f 801 | #define mju_floor floorf 802 | #define mju_ceil ceilf 803 | #endif 804 | 805 | 806 | //------------------------------ Vector math -------------------------------------------- 807 | 808 | // Set res = 0. 809 | MJAPI void mju_zero3(mjtNum res[3]); 810 | 811 | // Set res = vec. 812 | MJAPI void mju_copy3(mjtNum res[3], const mjtNum data[3]); 813 | 814 | // Set res = vec*scl. 815 | MJAPI void mju_scl3(mjtNum res[3], const mjtNum vec[3], mjtNum scl); 816 | 817 | // Set res = vec1 + vec2. 818 | MJAPI void mju_add3(mjtNum res[3], const mjtNum vec1[3], const mjtNum vec2[3]); 819 | 820 | // Set res = vec1 - vec2. 821 | MJAPI void mju_sub3(mjtNum res[3], const mjtNum vec1[3], const mjtNum vec2[3]); 822 | 823 | // Set res = res + vec. 824 | MJAPI void mju_addTo3(mjtNum res[3], const mjtNum vec[3]); 825 | 826 | // Set res = res - vec. 827 | MJAPI void mju_subFrom3(mjtNum res[3], const mjtNum vec[3]); 828 | 829 | // Set res = res + vec*scl. 830 | MJAPI void mju_addToScl3(mjtNum res[3], const mjtNum vec[3], mjtNum scl); 831 | 832 | // Set res = vec1 + vec2*scl. 833 | MJAPI void mju_addScl3(mjtNum res[3], const mjtNum vec1[3], const mjtNum vec2[3], mjtNum scl); 834 | 835 | // Normalize vector, return length before normalization. 836 | MJAPI mjtNum mju_normalize3(mjtNum res[3]); 837 | 838 | // Return vector length (without normalizing the vector). 839 | MJAPI mjtNum mju_norm3(const mjtNum vec[3]); 840 | 841 | // Return dot-product of vec1 and vec2. 842 | MJAPI mjtNum mju_dot3(const mjtNum vec1[3], const mjtNum vec2[3]); 843 | 844 | // Return Cartesian distance between 3D vectors pos1 and pos2. 845 | MJAPI mjtNum mju_dist3(const mjtNum pos1[3], const mjtNum pos2[3]); 846 | 847 | // Multiply vector by 3D rotation matrix: res = mat * vec. 848 | MJAPI void mju_rotVecMat(mjtNum res[3], const mjtNum vec[3], const mjtNum mat[9]); 849 | 850 | // Multiply vector by transposed 3D rotation matrix: res = mat' * vec. 851 | MJAPI void mju_rotVecMatT(mjtNum res[3], const mjtNum vec[3], const mjtNum mat[9]); 852 | 853 | // Compute cross-product: res = cross(a, b). 854 | MJAPI void mju_cross(mjtNum res[3], const mjtNum a[3], const mjtNum b[3]); 855 | 856 | // Set res = 0. 857 | MJAPI void mju_zero4(mjtNum res[4]); 858 | 859 | // Set res = (1,0,0,0). 860 | MJAPI void mju_unit4(mjtNum res[4]); 861 | 862 | // Set res = vec. 863 | MJAPI void mju_copy4(mjtNum res[4], const mjtNum data[4]); 864 | 865 | // Normalize vector, return length before normalization. 866 | MJAPI mjtNum mju_normalize4(mjtNum res[4]); 867 | 868 | // Set res = 0. 869 | MJAPI void mju_zero(mjtNum* res, int n); 870 | 871 | // Set res = vec. 872 | MJAPI void mju_copy(mjtNum* res, const mjtNum* data, int n); 873 | 874 | // Return sum(vec). 875 | MJAPI mjtNum mju_sum(const mjtNum* vec, int n); 876 | 877 | // Return L1 norm: sum(abs(vec)). 878 | MJAPI mjtNum mju_L1(const mjtNum* vec, int n); 879 | 880 | // Set res = vec*scl. 881 | MJAPI void mju_scl(mjtNum* res, const mjtNum* vec, mjtNum scl, int n); 882 | 883 | // Set res = vec1 + vec2. 884 | MJAPI void mju_add(mjtNum* res, const mjtNum* vec1, const mjtNum* vec2, int n); 885 | 886 | // Set res = vec1 - vec2. 887 | MJAPI void mju_sub(mjtNum* res, const mjtNum* vec1, const mjtNum* vec2, int n); 888 | 889 | // Set res = res + vec. 890 | MJAPI void mju_addTo(mjtNum* res, const mjtNum* vec, int n); 891 | 892 | // Set res = res - vec. 893 | MJAPI void mju_subFrom(mjtNum* res, const mjtNum* vec, int n); 894 | 895 | // Set res = res + vec*scl. 896 | MJAPI void mju_addToScl(mjtNum* res, const mjtNum* vec, mjtNum scl, int n); 897 | 898 | // Set res = vec1 + vec2*scl. 899 | MJAPI void mju_addScl(mjtNum* res, const mjtNum* vec1, const mjtNum* vec2, mjtNum scl, int n); 900 | 901 | // Normalize vector, return length before normalization. 902 | MJAPI mjtNum mju_normalize(mjtNum* res, int n); 903 | 904 | // Return vector length (without normalizing vector). 905 | MJAPI mjtNum mju_norm(const mjtNum* res, int n); 906 | 907 | // Return dot-product of vec1 and vec2. 908 | MJAPI mjtNum mju_dot(const mjtNum* vec1, const mjtNum* vec2, const int n); 909 | 910 | // Multiply matrix and vector: res = mat * vec. 911 | MJAPI void mju_mulMatVec(mjtNum* res, const mjtNum* mat, const mjtNum* vec, 912 | int nr, int nc); 913 | 914 | // Multiply transposed matrix and vector: res = mat' * vec. 915 | MJAPI void mju_mulMatTVec(mjtNum* res, const mjtNum* mat, const mjtNum* vec, 916 | int nr, int nc); 917 | 918 | // Transpose matrix: res = mat'. 919 | MJAPI void mju_transpose(mjtNum* res, const mjtNum* mat, int nr, int nc); 920 | 921 | // Multiply matrices: res = mat1 * mat2. 922 | MJAPI void mju_mulMatMat(mjtNum* res, const mjtNum* mat1, const mjtNum* mat2, 923 | int r1, int c1, int c2); 924 | 925 | // Multiply matrices, second argument transposed: res = mat1 * mat2'. 926 | MJAPI void mju_mulMatMatT(mjtNum* res, const mjtNum* mat1, const mjtNum* mat2, 927 | int r1, int c1, int r2); 928 | 929 | // Multiply matrices, first argument transposed: res = mat1' * mat2. 930 | MJAPI void mju_mulMatTMat(mjtNum* res, const mjtNum* mat1, const mjtNum* mat2, 931 | int r1, int c1, int c2); 932 | 933 | // Set res = mat' * diag * mat if diag is not NULL, and res = mat' * mat otherwise. 934 | MJAPI void mju_sqrMatTD(mjtNum* res, const mjtNum* mat, const mjtNum* diag, int nr, int nc); 935 | 936 | // Coordinate transform of 6D motion or force vector in rotation:translation format. 937 | // rotnew2old is 3-by-3, NULL means no rotation; flg_force specifies force or motion type. 938 | MJAPI void mju_transformSpatial(mjtNum res[6], const mjtNum vec[6], int flg_force, 939 | const mjtNum newpos[3], const mjtNum oldpos[3], 940 | const mjtNum rotnew2old[9]); 941 | 942 | 943 | //---------------------- Quaternions ---------------------------------------------------- 944 | 945 | // Rotate vector by quaternion. 946 | MJAPI void mju_rotVecQuat(mjtNum res[3], const mjtNum vec[3], const mjtNum quat[4]); 947 | 948 | // Conjugate quaternion, corresponding to opposite rotation. 949 | MJAPI void mju_negQuat(mjtNum res[4], const mjtNum quat[4]); 950 | 951 | // Muiltiply quaternions. 952 | MJAPI void mju_mulQuat(mjtNum res[4], const mjtNum quat1[4], const mjtNum quat2[4]); 953 | 954 | // Muiltiply quaternion and axis. 955 | MJAPI void mju_mulQuatAxis(mjtNum res[4], const mjtNum quat[4], const mjtNum axis[3]); 956 | 957 | // Convert axisAngle to quaternion. 958 | MJAPI void mju_axisAngle2Quat(mjtNum res[4], const mjtNum axis[3], mjtNum angle); 959 | 960 | // Convert quaternion (corresponding to orientation difference) to 3D velocity. 961 | MJAPI void mju_quat2Vel(mjtNum res[3], const mjtNum quat[4], mjtNum dt); 962 | 963 | // Subtract quaternions, express as 3D velocity: qb*quat(res) = qa. 964 | MJAPI void mju_subQuat(mjtNum res[3], const mjtNum qa[4], const mjtNum qb[4]); 965 | 966 | // Convert quaternion to 3D rotation matrix. 967 | MJAPI void mju_quat2Mat(mjtNum res[9], const mjtNum quat[4]); 968 | 969 | // Convert 3D rotation matrix to quaterion. 970 | MJAPI void mju_mat2Quat(mjtNum quat[4], const mjtNum mat[9]); 971 | 972 | // Compute time-derivative of quaternion, given 3D rotational velocity. 973 | MJAPI void mju_derivQuat(mjtNum res[4], const mjtNum quat[4], const mjtNum vel[3]); 974 | 975 | // Integrate quaterion given 3D angular velocity. 976 | MJAPI void mju_quatIntegrate(mjtNum quat[4], const mjtNum vel[3], mjtNum scale); 977 | 978 | // Construct quaternion performing rotation from z-axis to given vector. 979 | MJAPI void mju_quatZ2Vec(mjtNum quat[4], const mjtNum vec[3]); 980 | 981 | 982 | //---------------------- Poses ---------------------------------------------------------- 983 | 984 | // Multiply two poses. 985 | MJAPI void mju_mulPose(mjtNum posres[3], mjtNum quatres[4], 986 | const mjtNum pos1[3], const mjtNum quat1[4], 987 | const mjtNum pos2[3], const mjtNum quat2[4]); 988 | 989 | // Conjugate pose, corresponding to the opposite spatial transformation. 990 | MJAPI void mju_negPose(mjtNum posres[3], mjtNum quatres[4], 991 | const mjtNum pos[3], const mjtNum quat[4]); 992 | 993 | // Transform vector by pose. 994 | MJAPI void mju_trnVecPose(mjtNum res[3], const mjtNum pos[3], const mjtNum quat[4], 995 | const mjtNum vec[3]); 996 | 997 | 998 | //---------------------- Decompositions -------------------------------------------------- 999 | 1000 | // Cholesky decomposition: mat = L*L'; return rank. 1001 | MJAPI int mju_cholFactor(mjtNum* mat, int n, mjtNum mindiag); 1002 | 1003 | // Solve mat * res = vec, where mat is Cholesky-factorized 1004 | MJAPI void mju_cholSolve(mjtNum* res, const mjtNum* mat, const mjtNum* vec, int n); 1005 | 1006 | // Cholesky rank-one update: L*L' +/- x*x'; return rank. 1007 | MJAPI int mju_cholUpdate(mjtNum* mat, mjtNum* x, int n, int flg_plus); 1008 | 1009 | // Eigenvalue decomposition of symmetric 3x3 matrix. 1010 | MJAPI int mju_eig3(mjtNum* eigval, mjtNum* eigvec, mjtNum* quat, const mjtNum* mat); 1011 | 1012 | 1013 | //---------------------- Miscellaneous -------------------------------------------------- 1014 | 1015 | // Muscle active force, prm = (range[2], force, scale, lmin, lmax, vmax, fpmax, fvmax). 1016 | MJAPI mjtNum mju_muscleGain(mjtNum len, mjtNum vel, const mjtNum lengthrange[2], 1017 | mjtNum acc0, const mjtNum prm[9]); 1018 | 1019 | // Muscle passive force, prm = (range[2], force, scale, lmin, lmax, vmax, fpmax, fvmax). 1020 | MJAPI mjtNum mju_muscleBias(mjtNum len, const mjtNum lengthrange[2], 1021 | mjtNum acc0, const mjtNum prm[9]); 1022 | 1023 | // Muscle activation dynamics, prm = (tau_act, tau_deact). 1024 | MJAPI mjtNum mju_muscleDynamics(mjtNum ctrl, mjtNum act, const mjtNum prm[2]); 1025 | 1026 | // Convert contact force to pyramid representation. 1027 | MJAPI void mju_encodePyramid(mjtNum* pyramid, const mjtNum* force, 1028 | const mjtNum* mu, int dim); 1029 | 1030 | // Convert pyramid representation to contact force. 1031 | MJAPI void mju_decodePyramid(mjtNum* force, const mjtNum* pyramid, 1032 | const mjtNum* mu, int dim); 1033 | 1034 | // Integrate spring-damper analytically, return pos(dt). 1035 | MJAPI mjtNum mju_springDamper(mjtNum pos0, mjtNum vel0, mjtNum Kp, mjtNum Kv, mjtNum dt); 1036 | 1037 | // Return min(a,b) with single evaluation of a and b. 1038 | MJAPI mjtNum mju_min(mjtNum a, mjtNum b); 1039 | 1040 | // Return max(a,b) with single evaluation of a and b. 1041 | MJAPI mjtNum mju_max(mjtNum a, mjtNum b); 1042 | 1043 | // Return sign of x: +1, -1 or 0. 1044 | MJAPI mjtNum mju_sign(mjtNum x); 1045 | 1046 | // Round x to nearest integer. 1047 | MJAPI int mju_round(mjtNum x); 1048 | 1049 | // Convert type id (mjtObj) to type name. 1050 | MJAPI const char* mju_type2Str(int type); 1051 | 1052 | // Convert type name to type id (mjtObj). 1053 | MJAPI int mju_str2Type(const char* str); 1054 | 1055 | // Construct a warning message given the warning type and info. 1056 | MJAPI const char* mju_warningText(int warning, int info); 1057 | 1058 | // Return 1 if nan or abs(x)>mjMAXVAL, 0 otherwise. Used by check functions. 1059 | MJAPI int mju_isBad(mjtNum x); 1060 | 1061 | // Return 1 if all elements are 0. 1062 | MJAPI int mju_isZero(mjtNum* vec, int n); 1063 | 1064 | // Standard normal random number generator (optional second number). 1065 | MJAPI mjtNum mju_standardNormal(mjtNum* num2); 1066 | 1067 | // Convert from float to mjtNum. 1068 | MJAPI void mju_f2n(mjtNum* res, const float* vec, int n); 1069 | 1070 | // Convert from mjtNum to float. 1071 | MJAPI void mju_n2f(float* res, const mjtNum* vec, int n); 1072 | 1073 | // Convert from double to mjtNum. 1074 | MJAPI void mju_d2n(mjtNum* res, const double* vec, int n); 1075 | 1076 | // Convert from mjtNum to double. 1077 | MJAPI void mju_n2d(double* res, const mjtNum* vec, int n); 1078 | 1079 | // Insertion sort, resulting list is in increasing order. 1080 | MJAPI void mju_insertionSort(mjtNum* list, int n); 1081 | 1082 | // Integer insertion sort, resulting list is in increasing order. 1083 | MJAPI void mju_insertionSortInt(int* list, int n); 1084 | 1085 | // Generate Halton sequence. 1086 | MJAPI mjtNum mju_Halton(int index, int base); 1087 | 1088 | // Call strncpy, then set dst[n-1] = 0. 1089 | MJAPI char* mju_strncpy(char *dst, const char *src, int n); 1090 | 1091 | // Sigmoid function over 0<=x<=1 constructed from half-quadratics. 1092 | MJAPI mjtNum mju_sigmoid(mjtNum x); 1093 | 1094 | 1095 | #if defined(__cplusplus) 1096 | } 1097 | #endif 1098 | 1099 | #endif // MUJOCO_MUJOCO_H_ 1100 | -------------------------------------------------------------------------------- /mujoco210/include/uitools.c: -------------------------------------------------------------------------------- 1 | // Copyright 2021 DeepMind Technologies Limited 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "uitools.h" 16 | #include "stdio.h" 17 | #include "string.h" 18 | 19 | 20 | //-------------------------------- Internal GLFW callbacks ------------------------------ 21 | 22 | // update state 23 | static void uiUpdateState(GLFWwindow* wnd) 24 | { 25 | // extract data from user pointer 26 | uiUserPointer* ptr = (uiUserPointer*)glfwGetWindowUserPointer(wnd); 27 | mjuiState* state = ptr->state; 28 | 29 | // mouse buttons 30 | state->left = (glfwGetMouseButton(wnd, GLFW_MOUSE_BUTTON_LEFT)==GLFW_PRESS); 31 | state->right = (glfwGetMouseButton(wnd, GLFW_MOUSE_BUTTON_RIGHT)==GLFW_PRESS); 32 | state->middle = (glfwGetMouseButton(wnd, GLFW_MOUSE_BUTTON_MIDDLE)==GLFW_PRESS); 33 | 34 | // keyboard modifiers 35 | state->control = (glfwGetKey(wnd, GLFW_KEY_LEFT_CONTROL)==GLFW_PRESS || 36 | glfwGetKey(wnd, GLFW_KEY_RIGHT_CONTROL)==GLFW_PRESS); 37 | state->shift = (glfwGetKey(wnd, GLFW_KEY_LEFT_SHIFT)==GLFW_PRESS || 38 | glfwGetKey(wnd, GLFW_KEY_RIGHT_SHIFT)==GLFW_PRESS); 39 | state->alt = (glfwGetKey(wnd, GLFW_KEY_LEFT_ALT)==GLFW_PRESS || 40 | glfwGetKey(wnd, GLFW_KEY_RIGHT_ALT)==GLFW_PRESS); 41 | 42 | // swap left and right if Alt 43 | if( state->alt ) 44 | { 45 | int tmp = state->left; 46 | state->left = state->right; 47 | state->right = tmp; 48 | } 49 | 50 | // get mouse position, scale by buffer-to-window ratio 51 | double x, y; 52 | glfwGetCursorPos(wnd, &x, &y); 53 | x *= ptr->buffer2window; 54 | y *= ptr->buffer2window; 55 | 56 | // invert y to match OpenGL convention 57 | y = state->rect[0].height - y; 58 | 59 | // save 60 | state->dx = x - state->x; 61 | state->dy = y - state->y; 62 | state->x = x; 63 | state->y = y; 64 | 65 | // find mouse rectangle 66 | state->mouserect = mjr_findRect(mju_round(x), mju_round(y), 67 | state->nrect-1, state->rect+1) + 1; 68 | } 69 | 70 | 71 | 72 | // keyboard 73 | static void uiKeyboard(GLFWwindow* wnd, int key, int scancode, int act, int mods) 74 | { 75 | // release: nothing to do 76 | if( act==GLFW_RELEASE ) 77 | return; 78 | 79 | // extract data from user pointer 80 | uiUserPointer* ptr = (uiUserPointer*)glfwGetWindowUserPointer(wnd); 81 | mjuiState* state = ptr->state; 82 | 83 | // update state 84 | uiUpdateState(wnd); 85 | 86 | // set key info 87 | state->type = mjEVENT_KEY; 88 | state->key = key; 89 | state->keytime = glfwGetTime(); 90 | 91 | // application-specific processing 92 | ptr->uiEvent(state); 93 | } 94 | 95 | 96 | 97 | // mouse button 98 | static void uiMouseButton(GLFWwindow* wnd, int button, int act, int mods) 99 | { 100 | // extract data from user pointer 101 | uiUserPointer* ptr = (uiUserPointer*)glfwGetWindowUserPointer(wnd); 102 | mjuiState* state = ptr->state; 103 | 104 | // update state 105 | uiUpdateState(wnd); 106 | 107 | // translate button 108 | if( button==GLFW_MOUSE_BUTTON_LEFT ) 109 | button = mjBUTTON_LEFT; 110 | else if( button==GLFW_MOUSE_BUTTON_RIGHT ) 111 | button = mjBUTTON_RIGHT; 112 | else 113 | button = mjBUTTON_MIDDLE; 114 | 115 | // swap left and right if Alt 116 | if( glfwGetKey(wnd, GLFW_KEY_LEFT_ALT)==GLFW_PRESS || 117 | glfwGetKey(wnd, GLFW_KEY_RIGHT_ALT)==GLFW_PRESS ) 118 | { 119 | if( button==mjBUTTON_LEFT ) 120 | button = mjBUTTON_RIGHT; 121 | else if( button==mjBUTTON_RIGHT ) 122 | button = mjBUTTON_LEFT; 123 | } 124 | 125 | // press 126 | if( act==GLFW_PRESS ) 127 | { 128 | // detect doubleclick: 250 ms 129 | if( button==state->button && glfwGetTime()-state->buttontime<0.25 ) 130 | state->doubleclick = 1; 131 | else 132 | state->doubleclick = 0; 133 | 134 | // set info 135 | state->type = mjEVENT_PRESS; 136 | state->button = button; 137 | state->buttontime = glfwGetTime(); 138 | 139 | // start dragging 140 | if( state->mouserect ) 141 | { 142 | state->dragbutton = state->button; 143 | state->dragrect = state->mouserect; 144 | } 145 | } 146 | 147 | // release 148 | else 149 | state->type = mjEVENT_RELEASE; 150 | 151 | // application-specific processing 152 | ptr->uiEvent(state); 153 | 154 | // stop dragging after application processing 155 | if( state->type==mjEVENT_RELEASE ) 156 | { 157 | state->dragrect = 0; 158 | state->dragbutton = 0; 159 | } 160 | } 161 | 162 | 163 | 164 | // mouse move 165 | static void uiMouseMove(GLFWwindow* wnd, double xpos, double ypos) 166 | { 167 | // extract data from user pointer 168 | uiUserPointer* ptr = (uiUserPointer*)glfwGetWindowUserPointer(wnd); 169 | mjuiState* state = ptr->state; 170 | 171 | // no buttons down: nothing to do 172 | if( !state->left && !state->right && !state->middle ) 173 | return; 174 | 175 | // update state 176 | uiUpdateState(wnd); 177 | 178 | // set move info 179 | state->type = mjEVENT_MOVE; 180 | 181 | // application-specific processing 182 | ptr->uiEvent(state); 183 | } 184 | 185 | 186 | 187 | // scroll 188 | static void uiScroll(GLFWwindow* wnd, double xoffset, double yoffset) 189 | { 190 | // extract data from user pointer 191 | uiUserPointer* ptr = (uiUserPointer*)glfwGetWindowUserPointer(wnd); 192 | mjuiState* state = ptr->state; 193 | 194 | // update state 195 | uiUpdateState(wnd); 196 | 197 | // set scroll info, scale by buffer-to-window ratio 198 | state->type = mjEVENT_SCROLL; 199 | state->sx = xoffset * ptr->buffer2window; 200 | state->sy = yoffset * ptr->buffer2window; 201 | 202 | // application-specific processing 203 | ptr->uiEvent(state); 204 | } 205 | 206 | 207 | 208 | // resize 209 | static void uiResize(GLFWwindow* wnd, int width, int height) 210 | { 211 | // extract data from user pointer 212 | uiUserPointer* ptr = (uiUserPointer*)glfwGetWindowUserPointer(wnd); 213 | mjuiState* state = ptr->state; 214 | 215 | // set layout 216 | ptr->uiLayout(state); 217 | 218 | // update state 219 | uiUpdateState(wnd); 220 | 221 | // set resize info 222 | state->type = mjEVENT_RESIZE; 223 | 224 | // stop dragging 225 | state->dragbutton = 0; 226 | state->dragrect = 0; 227 | 228 | // application-specific processing (unless called with 0,0 from uiModify) 229 | if( width && height ) 230 | ptr->uiEvent(state); 231 | } 232 | 233 | 234 | 235 | //----------------------------------- Public API ---------------------------------------- 236 | 237 | // Compute suitable font scale. 238 | int uiFontScale(GLFWwindow* wnd) 239 | { 240 | // compute framebuffer-to-window ratio 241 | int width_win, width_buf, height; 242 | glfwGetWindowSize(wnd, &width_win, &height); 243 | glfwGetFramebufferSize(wnd, &width_buf, &height); 244 | double b2w = (double)width_buf / (double)width_win; 245 | 246 | // compute PPI 247 | int width_MM, height_MM; 248 | glfwGetMonitorPhysicalSize(glfwGetPrimaryMonitor(), &width_MM, &height_MM); 249 | int width_vmode = glfwGetVideoMode(glfwGetPrimaryMonitor())->width; 250 | double PPI = 25.4 * b2w * (double)width_vmode / (double)width_MM; 251 | 252 | // estimate font scaling, guard against unrealistic PPI 253 | int fs; 254 | if( width_buf>width_win ) 255 | fs = mju_round(b2w * 100); 256 | else if( PPI>50 && PPI<350 ) 257 | fs = mju_round(PPI); 258 | else 259 | fs = 150; 260 | fs = mju_round(fs * 0.02) * 50; 261 | fs = mjMIN(300, mjMAX(100, fs)); 262 | 263 | return fs; 264 | } 265 | 266 | 267 | 268 | // Set internal and user-supplied UI callbacks in GLFW window. 269 | void uiSetCallback(GLFWwindow* wnd, mjuiState* state, 270 | uiEventFn uiEvent, uiLayoutFn uiLayout) 271 | { 272 | // make container with user-supplied objects and set window pointer 273 | uiUserPointer* ptr = (uiUserPointer*) mju_malloc(sizeof(uiUserPointer)); 274 | ptr->state = state; 275 | ptr->uiEvent = uiEvent; 276 | ptr->uiLayout = uiLayout; 277 | glfwSetWindowUserPointer(wnd, ptr); 278 | 279 | // compute framebuffer-to-window pixel ratio 280 | int width_win, width_buf, height; 281 | glfwGetWindowSize(wnd, &width_win, &height); 282 | glfwGetFramebufferSize(wnd, &width_buf, &height); 283 | ptr->buffer2window = (double)width_buf / (double)width_win; 284 | 285 | // set internal callbacks 286 | glfwSetKeyCallback(wnd, uiKeyboard); 287 | glfwSetCursorPosCallback(wnd, uiMouseMove); 288 | glfwSetMouseButtonCallback(wnd, uiMouseButton); 289 | glfwSetScrollCallback(wnd, uiScroll); 290 | glfwSetWindowSizeCallback(wnd, uiResize); 291 | } 292 | 293 | 294 | 295 | // Clear UI callbacks in GLFW window. 296 | void uiClearCallback(GLFWwindow* wnd) 297 | { 298 | // clear container 299 | if( glfwGetWindowUserPointer(wnd) ) 300 | { 301 | mju_free(glfwGetWindowUserPointer(wnd)); 302 | glfwSetWindowUserPointer(wnd, NULL); 303 | } 304 | 305 | // clear internal callbacks 306 | glfwSetKeyCallback(wnd, NULL); 307 | glfwSetCursorPosCallback(wnd, NULL); 308 | glfwSetMouseButtonCallback(wnd, NULL); 309 | glfwSetScrollCallback(wnd, NULL); 310 | glfwSetWindowSizeCallback(wnd, NULL); 311 | } 312 | 313 | 314 | 315 | // Modify UI structure. 316 | void uiModify(GLFWwindow* wnd, mjUI* ui, mjuiState* state, mjrContext* con) 317 | { 318 | mjui_resize(ui, con); 319 | mjr_addAux(ui->auxid, ui->width, ui->maxheight, ui->spacing.samples, con); 320 | uiResize(wnd, 0, 0); 321 | mjui_update(-1, -1, ui, state, con); 322 | } 323 | -------------------------------------------------------------------------------- /mujoco210/include/uitools.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 DeepMind Technologies Limited 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef MUJOCO_UITOOLS_H_ 16 | #define MUJOCO_UITOOLS_H_ 17 | 18 | 19 | #include "mujoco.h" 20 | #include "glfw3.h" 21 | 22 | 23 | // this is a C-API 24 | #if defined(__cplusplus) 25 | extern "C" 26 | { 27 | #endif 28 | 29 | 30 | // User-supplied callback function types. 31 | typedef void (*uiEventFn)(mjuiState* state); 32 | typedef void (*uiLayoutFn)(mjuiState* state); 33 | 34 | // Container for GLFW window pointer. 35 | struct _uiUserPointer 36 | { 37 | mjuiState* state; 38 | uiEventFn uiEvent; 39 | uiLayoutFn uiLayout; 40 | double buffer2window; 41 | }; 42 | typedef struct _uiUserPointer uiUserPointer; 43 | 44 | // Set internal and user-supplied UI callbacks in GLFW window. 45 | void uiSetCallback(GLFWwindow* wnd, mjuiState* state, 46 | uiEventFn uiEvent, uiLayoutFn uiLayout); 47 | 48 | // Clear UI callbacks in GLFW window. 49 | void uiClearCallback(GLFWwindow* wnd); 50 | 51 | // Compute suitable font scale. 52 | int uiFontScale(GLFWwindow* wnd); 53 | 54 | // Modify UI structure. 55 | void uiModify(GLFWwindow* wnd, mjUI* ui, mjuiState* state, mjrContext* con); 56 | 57 | 58 | #if defined(__cplusplus) 59 | } 60 | #endif 61 | 62 | #endif // MUJOCO_UITOOLS_H_ 63 | -------------------------------------------------------------------------------- /mujoco_ros/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.3) 2 | project(mujoco_ros) 3 | 4 | add_compile_options(-Ofast -std=c++11) 5 | 6 | find_package(catkin REQUIRED COMPONENTS 7 | roscpp 8 | std_msgs 9 | mujoco_ros_msgs 10 | eigen_conversions 11 | ) 12 | 13 | find_package(tocabi_lib COMPONENTS) 14 | IF(tocabi_lib_FOUND) 15 | message(" -- shm mode enabled" ) 16 | ADD_DEFINITIONS(-DCOMPILE_SHAREDMEMORY) 17 | ENDIF() 18 | 19 | set(MUJOCO_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../mujoco210) 20 | 21 | message("MuJoCo path: " ${MUJOCO_PATH}) 22 | 23 | catkin_package( 24 | DEPENDS mujoco_ros_msgs 25 | ) 26 | 27 | 28 | include_directories( 29 | include 30 | ${MUJOCO_PATH}/include 31 | ${catkin_INCLUDE_DIRS} 32 | ${EIGEN3_INCLUDE_DIRS} 33 | ) 34 | 35 | link_directories( 36 | ${MUJOCO_PATH}/bin 37 | ) 38 | 39 | IF(tocabi_lib_FOUND) 40 | include_directories( 41 | ${tocabi_lib_INCLUDE_DIRS} 42 | ) 43 | ENDIF() 44 | 45 | file(GLOB LIB_MUJOCO ${MUJOCO_PATH}/bin/libmujoco210.so) 46 | 47 | file(GLOB UI_SRC "${MUJOCO_PATH}/include/uitools.c") 48 | 49 | add_library(mujoco_ros_lib 50 | ${UI_SRC} 51 | src/mjros.cpp 52 | ) 53 | 54 | add_executable(mujoco_ros src/main.cpp) 55 | 56 | target_link_libraries(mujoco_ros 57 | mujoco_ros_lib 58 | 59 | ${catkin_LIBRARIES} 60 | ${LIB_MUJOCO} 61 | GL 62 | #GLU 63 | #glut 64 | 65 | ${MUJOCO_PATH}/bin/libglew.so 66 | ${MUJOCO_PATH}/bin/libglfw.so.3 67 | ) 68 | 69 | add_dependencies(mujoco_ros_lib ${catkin_EXPORTED_TARGETS}) 70 | add_dependencies(mujoco_ros ${catkin_EXPORTED_TARGETS}) 71 | 72 | -------------------------------------------------------------------------------- /mujoco_ros/include/mjros.h: -------------------------------------------------------------------------------- 1 | #ifndef _MJROS_H 2 | #define _MJROS_H 3 | 4 | //Mujoco include 5 | #include "mjxmacro.h" 6 | #include "uitools.h" 7 | #include "stdio.h" 8 | #include "string.h" 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | //Ros include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | 32 | #ifdef COMPILE_SHAREDMEMORY 33 | #include "shm_msgs.h" 34 | SHMmsgs *mj_shm_; 35 | int shm_msg_id; 36 | 37 | #define USE_SHM true 38 | #else 39 | #define USE_SHM false 40 | #endif 41 | 42 | //-------------------------------- global ----------------------------------------------- 43 | //-----mujoco var----- 44 | // constants 45 | const int maxgeom = 5000; // preallocated geom array in mjvScene 46 | const double syncmisalign = 0.1; // maximum time mis-alignment before re-sync 47 | const double refreshfactor = 0.7; // fraction of refresh available for simulation 48 | 49 | // model and data 50 | mjModel *m = NULL; 51 | mjData *d = NULL; 52 | char filename[1000] = ""; 53 | 54 | // abstract visualization 55 | mjvScene scn; 56 | mjvCamera cam; 57 | mjvOption vopt; 58 | mjvPerturb pert; 59 | mjvFigure figconstraint; 60 | mjvFigure figcost; 61 | mjvFigure figtimer; 62 | mjvFigure figsize; 63 | mjvFigure figsensor; 64 | 65 | // OpenGL rendering and UI 66 | GLFWvidmode vmode; 67 | int windowpos[2]; 68 | int windowsize[2]; 69 | mjrContext con; 70 | GLFWwindow *window = NULL; 71 | mjuiState uistate; 72 | mjUI ui0, ui1; 73 | 74 | int key_ui = 0; 75 | 76 | int com_latency = 0; 77 | 78 | // UI settings not contained in MuJoCo structures 79 | struct setting_ 80 | { 81 | // file 82 | int exitrequest = 0; 83 | 84 | // option 85 | int spacing = 0; 86 | int color = 0; 87 | int font = 0; 88 | int ui0 = 1; 89 | int ui1 = 0; 90 | int help = 0; 91 | int info = 1; 92 | int profiler = 0; 93 | int sensor = 0; 94 | int fullscreen = 0; 95 | int vsync = 1; 96 | int busywait = 1; 97 | int realtime = 0; 98 | int debug = 0; 99 | int testbtn2 = 1; 100 | int timecheck = 0; 101 | int controlui = 0; 102 | int link_info = 0; 103 | 104 | // simulation 105 | int run = 0; 106 | int key = 0; 107 | char key_s[40] = "0"; 108 | int loadrequest = 0; 109 | 110 | // watch 111 | char field[mjMAXUITEXT] = "qpos"; 112 | int index = 0; 113 | 114 | // physics: need sync 115 | int disable[mjNDISABLE]; 116 | int enable[mjNENABLE]; 117 | 118 | // rendering: need sync 119 | int camera = 0; 120 | }; 121 | 122 | setting_ settings; 123 | 124 | // section ids 125 | enum 126 | { 127 | // left ui 128 | SECT_FILE = 0, 129 | SECT_OPTION, 130 | SECT_SIMULATION, 131 | SECT_PHYSICS, 132 | SECT_RENDERING, 133 | SECT_GROUP, 134 | NSECT0, 135 | 136 | // right ui 137 | SECT_WATCH = 0, 138 | SECT_JOINT, 139 | SECT_CONTROL, 140 | NSECT1 141 | }; 142 | 143 | // file section of UI 144 | const mjuiDef defFile[] = 145 | { 146 | {mjITEM_SECTION, "File", 1, NULL, "AF"}, 147 | {mjITEM_BUTTON, "Save xml", 2, NULL, ""}, 148 | {mjITEM_BUTTON, "Save mjb", 2, NULL, ""}, 149 | {mjITEM_BUTTON, "Print model", 2, NULL, "CM"}, 150 | {mjITEM_BUTTON, "Print data", 2, NULL, "CD"}, 151 | {mjITEM_BUTTON, "Quit", 1, NULL, "CQ"}, 152 | {mjITEM_END}}; 153 | 154 | // option section of UI 155 | const mjuiDef defOption[] = 156 | { 157 | {mjITEM_SECTION, "Option", 1, NULL, "AO"}, 158 | {mjITEM_SELECT, "Spacing", 1, &settings.spacing, "Tight\nWide"}, 159 | {mjITEM_SELECT, "Color", 1, &settings.color, "Default\nOrange\nWhite\nBlack"}, 160 | {mjITEM_SELECT, "Font", 1, &settings.font, "50 %\n100 %\n150 %\n200 %\n250 %\n300 %"}, 161 | {mjITEM_CHECKINT, "Left UI (Tab)", 1, &settings.ui0, " #258"}, 162 | {mjITEM_CHECKINT, "Right UI", 1, &settings.ui1, "S#258"}, 163 | {mjITEM_CHECKINT, "Help", 2, &settings.help, " #290"}, 164 | {mjITEM_CHECKINT, "Info", 2, &settings.info, " #291"}, 165 | {mjITEM_CHECKINT, "Profiler", 2, &settings.profiler, " #292"}, 166 | {mjITEM_CHECKINT, "Sensor", 2, &settings.sensor, " #293"}, 167 | #ifdef __APPLE__ 168 | {mjITEM_CHECKINT, "Fullscreen", 0, &settings.fullscreen, " #294"}, 169 | #else 170 | {mjITEM_CHECKINT, "Fullscreen", 1, &settings.fullscreen, " #294"}, 171 | #endif 172 | {mjITEM_CHECKINT, "Vertical Sync", 1, &settings.vsync, " #295"}, 173 | {mjITEM_CHECKINT, "Real Time", 1, &settings.busywait, " #296"}, 174 | {mjITEM_CHECKINT, "Debug", 1, &settings.debug, " #297"}, 175 | {mjITEM_CHECKINT, "Time Check", 1, &settings.timecheck, " #298"}, 176 | {mjITEM_CHECKINT, "Control by UI", 1, &settings.controlui, ""}, 177 | {mjITEM_CHECKINT, "Link info", 1, &settings.link_info, ""}, 178 | {mjITEM_END}}; 179 | 180 | // simulation section of UI 181 | mjuiDef defSimulation[] = 182 | { 183 | {mjITEM_SECTION, "Simulation", 1, NULL, "AS"}, 184 | {mjITEM_RADIO, "", 2, &settings.run, "Pause\nRun"}, 185 | {mjITEM_BUTTON, "Reset", 2, NULL, "C#259"}, 186 | {mjITEM_BUTTON, "Reload", 2, NULL, "CL"}, 187 | {mjITEM_BUTTON, "Align", 2, NULL, "CA"}, 188 | {mjITEM_BUTTON, "Copy pose", 2, NULL, "CC"}, 189 | //{mjITEM_SLIDERINT, "Key", 3, &settings.key, "0 0"}, 190 | {mjITEM_BUTTON, "Key + ", 2, NULL, " #266"}, 191 | {mjITEM_BUTTON, "Key - ", 2, NULL, " #267"}, 192 | {mjITEM_STATIC, "Key", 2, NULL, " 0"}, 193 | {mjITEM_BUTTON, "Latency + ", 2, NULL, ""}, 194 | {mjITEM_BUTTON, "Latency - ", 2, NULL, ""}, 195 | {mjITEM_STATIC, "Latency", 2, NULL, " 0"}, 196 | {mjITEM_BUTTON, "Reset to key", 3, NULL, " #259"}, 197 | {mjITEM_BUTTON, "Set key", 3}, 198 | {mjITEM_END}}; 199 | 200 | // watch section of UI 201 | const mjuiDef defWatch[] = 202 | { 203 | {mjITEM_SECTION, "Watch", 0, NULL, "AW"}, 204 | {mjITEM_EDITTXT, "Field", 2, settings.field, "qpos"}, 205 | {mjITEM_EDITINT, "Index", 2, &settings.index, "1"}, 206 | {mjITEM_STATIC, "Value", 2, NULL, " "}, 207 | {mjITEM_END}}; 208 | 209 | // help strings 210 | const char help_content[] = 211 | "Alt mouse button\n" 212 | "UI right hold\n" 213 | "UI title double-click\n" 214 | "Space\n" 215 | "Esc\n" 216 | "Right arrow\n" 217 | "Left arrow\n" 218 | "Down arrow\n" 219 | "Up arrow\n" 220 | "Page Up\n" 221 | "Double-click\n" 222 | "Right double-click\n" 223 | "Ctrl Right double-click\n" 224 | "Scroll, middle drag\n" 225 | "Left drag\n" 226 | "[Shift] right drag\n" 227 | "Ctrl [Shift] drag\n" 228 | "Ctrl [Shift] right drag"; 229 | 230 | const char help_title[] = 231 | "Swap left-right\n" 232 | "Show UI shortcuts\n" 233 | "Expand/collapse all \n" 234 | "Pause\n" 235 | "Free camera\n" 236 | "Step forward\n" 237 | "Step back\n" 238 | "Step forward 100\n" 239 | "Step back 100\n" 240 | "Select parent\n" 241 | "Select\n" 242 | "Center\n" 243 | "Track camera\n" 244 | "Zoom\n" 245 | "View rotate\n" 246 | "View translate\n" 247 | "Object rotate\n" 248 | "Object translate"; 249 | 250 | // info strings 251 | char info_title[1000]; 252 | char info_content[1000]; 253 | 254 | void profilerinit(void); 255 | void profilerupdate(void); 256 | void profilershow(mjrRect rect); 257 | void sensorinit(void); 258 | void sensorupdate(void); 259 | void sensorshow(mjrRect rect); 260 | void infotext(char *title, char *content, double interval); 261 | void printfield(char *str, void *ptr); 262 | void watch(void); 263 | void makephysics(int oldstate); 264 | void makerendering(int oldstate); 265 | void makegroup(int oldstate); 266 | void makejoint(int oldstate); 267 | void makecontrol(int oldstate); 268 | void makesections(void); 269 | void alignscale(void); 270 | void copykey(void); 271 | mjtNum timer(void); 272 | void cleartimers(void); 273 | void updatesettings(void); 274 | void drop(GLFWwindow *window, int count, const char **paths); 275 | void loadmodel(void); 276 | int uiPredicate(int category, void *userdata); 277 | void uiLayout(mjuiState *state); 278 | void uiEvent(mjuiState *state); 279 | void prepare(void); 280 | void render(GLFWwindow *window); 281 | void simulate(void); 282 | void init(); 283 | void rosPollEvents(); 284 | 285 | std::mutex mtx; 286 | 287 | //---------------ROS Var----------------------- 288 | ros::Publisher joint_state_pub; 289 | ros::Publisher sensor_state_pub; 290 | ros::Subscriber joint_set; 291 | ros::Subscriber joint_init; 292 | ros::Subscriber sim_command_sub; 293 | ros::Publisher sim_command_pub; 294 | ros::Publisher sim_status_pub; 295 | 296 | // apply external force 297 | ros::Subscriber force_apply_sub; 298 | // std_msgs::Float32MultiArray ext_force_msg_; 299 | mujoco_ros_msgs::applyforce ext_force_msg_; 300 | bool ext_force_applied_ = false; 301 | std::vector applied_ext_force_; 302 | unsigned int force_appiedd_link_idx_; 303 | mjvGeom* arrow; 304 | void arrowshow(mjvGeom* arrow); 305 | void makeArrow(mjvGeom* arrow); 306 | void force_apply_callback(const mujoco_ros_msgs::applyforce &msg); 307 | 308 | //mujoco_ros_msgs::JointState joint_state_msg_; 309 | //mujoco_ros_msgs::JointSet joint_set_msg_; 310 | mujoco_ros_msgs::SensorState sensor_state_msg_; 311 | mujoco_ros_msgs::SimStatus sim_status_msg_; 312 | sensor_msgs::JointState joint_state_msg_; 313 | //sensor_msgs::JointState joint_set_msg_; 314 | mujoco_ros_msgs::JointSet joint_set_msg_; 315 | std_msgs::Float32 sim_time; 316 | ros::Publisher sim_time_pub; 317 | 318 | std::vector command; 319 | std::vector command2; 320 | 321 | int loadmodel_request = 0; 322 | 323 | bool ros_time_sync_reset; 324 | 325 | //reset start time 326 | bool ros_sim_started = true; 327 | bool controller_reset_check = true; 328 | bool controller_init_check = true; 329 | bool reset_request = false; 330 | 331 | bool pause_check = true; 332 | 333 | bool pub_total_mode = false; 334 | 335 | bool use_shm = false; 336 | 337 | //bool for custom applied force 338 | bool custom_ft_applied = false; 339 | 340 | ros::Duration sim_time_ros; 341 | ros::Time sim_time_run; 342 | 343 | ros::Duration sim_time_now_ros; 344 | 345 | ros::Duration ros_sim_runtime; 346 | ros::Time sync_time_test; 347 | 348 | std::string ctrlstat = "Missing"; 349 | 350 | std::vector ctrl_command_temp_; 351 | 352 | std::deque> ctrl_cmd_que_; 353 | 354 | mjtNum *ctrl_command; 355 | mjtNum *ctrl_command2; 356 | 357 | bool cmd_rcv = false; 358 | 359 | // user state for pub 360 | 361 | float com_time; 362 | float dif_time; 363 | 364 | double t_bf = 0; 365 | 366 | double sim_cons_time = 0; 367 | //void c_pause(); 368 | //void c_slowmotion(); 369 | void c_reset(); 370 | 371 | //---------------------callback functions -------------------------------- 372 | 373 | void jointset_callback(const mujoco_ros_msgs::JointSetConstPtr &msg); 374 | void sim_command_callback(const std_msgs::StringConstPtr &msg); 375 | void state_publisher_init(); 376 | void state_publisher(); 377 | void mujoco_ros_connector_init(); 378 | void mycontroller(const mjModel *m, mjData *d); 379 | 380 | #endif -------------------------------------------------------------------------------- /mujoco_ros/package.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | mujoco_ros 4 | 0.0.0 5 | The dyros_red_mujoco package based on mujoco2.0 6 | 7 | 8 | 9 | 10 | saga 11 | 12 | 13 | 14 | 15 | 16 | TODO 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | catkin 52 | roscpp 53 | std_msgs 54 | mujoco_ros_msgs 55 | roscpp 56 | std_msgs 57 | mujoco_ros_msgs 58 | roscpp 59 | std_msgs 60 | mujoco_ros_msgs 61 | tocabi_lib 62 | tocabi_lib 63 | tocabi_lib 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /mujoco_ros/src/main.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright © 2018, Roboti LLC 2 | 3 | This file is licensed under the MuJoCo Resource License (the "License"). 4 | You may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | https://www.roboti.us/resourcelicense.txt 8 | */ 9 | 10 | #include "mjros.h" 11 | 12 | // drop file callback 13 | void drop(GLFWwindow *window, int count, const char **paths) 14 | { 15 | // make sure list is non-empty 16 | if (count > 0) 17 | { 18 | mju_strncpy(filename, paths[0], 1000); 19 | settings.loadrequest = 1; 20 | ROS_INFO("DROP REQUEST"); 21 | } 22 | } 23 | 24 | // load mjb or xml model 25 | void loadmodel(void) 26 | { 27 | // clear request 28 | settings.loadrequest = 0; 29 | 30 | // make sure filename is not empty 31 | if (!filename[0]) 32 | return; 33 | 34 | // load and compile 35 | char error[500] = ""; 36 | mjModel *mnew = 0; 37 | if (strlen(filename) > 4 && !strcmp(filename + strlen(filename) - 4, ".mjb")) 38 | { 39 | mnew = mj_loadModel(filename, NULL); 40 | if (!mnew) 41 | strcpy(error, "could not load binary model"); 42 | } 43 | else 44 | { 45 | mnew = mj_loadXML(filename, NULL, error, 500); 46 | } 47 | if (!mnew) 48 | { 49 | printf("%s\n", error); 50 | return; 51 | } 52 | 53 | // compiler warning: print and pause 54 | if (error[0]) 55 | { 56 | // mj_forward() below will print the warning message 57 | printf("Model compiled, but simulation warning (paused):\n %s\n\n", 58 | error); 59 | settings.run = 0; 60 | } 61 | 62 | // delete old model, assign new 63 | mj_deleteData(d); 64 | mj_deleteModel(m); 65 | m = mnew; 66 | d = mj_makeData(m); 67 | 68 | int i = settings.key; 69 | d->time = m->key_time[i]; 70 | mju_copy(d->qpos, m->key_qpos + i * m->nq, m->nq); 71 | mju_copy(d->qvel, m->key_qvel + i * m->nv, m->nv); 72 | mju_copy(d->act, m->key_act + i * m->na, m->na); 73 | 74 | if (m->actuator_biastype[0]) 75 | { 76 | mju_copy(d->ctrl, m->key_qpos + 7 + i * m->nq, m->nu); 77 | } 78 | 79 | mj_forward(m, d); 80 | 81 | ros_sim_started = true; 82 | ctrl_command = mj_stackAlloc(d, (int)m->nu); 83 | ctrl_command2 = mj_stackAlloc(d, (int)(m->nbody * 6)); 84 | 85 | // re-create scene and context 86 | mjv_makeScene(m, &scn, maxgeom); 87 | mjr_makeContext(m, &con, 50 * (settings.font + 1)); 88 | 89 | // clear perturbation state 90 | pert.active = 0; 91 | pert.select = 0; 92 | pert.skinselect = -1; 93 | 94 | // align and scale view, update scene 95 | alignscale(); 96 | mjv_updateScene(m, d, &vopt, &pert, &cam, mjCAT_ALL, &scn); 97 | 98 | // set window title to model name 99 | if (window && m->names) 100 | { 101 | char title[200] = "Simulate : "; 102 | strcat(title, m->names); 103 | strcat(title, ros::this_node::getNamespace().c_str()); 104 | glfwSetWindowTitle(window, title); 105 | } 106 | 107 | // rebuild UI sections 108 | makesections(); 109 | 110 | // full ui update 111 | uiModify(window, &ui0, &uistate, &con); 112 | uiModify(window, &ui1, &uistate, &con); 113 | 114 | updatesettings(); 115 | mujoco_ros_connector_init(); 116 | std::cout << " MODEL LOADED " << std::endl; 117 | } 118 | // run event loop 119 | int main(int argc, char **argv) 120 | { 121 | // :: ROS CUSTUM :: initialize ros 122 | ros::init(argc, argv, "mujoco_ros"); 123 | ros::NodeHandle nh("~"); 124 | std::string key_file; 125 | nh.param("license", key_file, "mjkey.txt"); 126 | 127 | nh.param("use_shm", use_shm, false); 128 | sim_command_sub = nh.subscribe("/mujoco_ros_interface/sim_command_con2sim", 100, sim_command_callback); 129 | sim_command_pub = nh.advertise("/mujoco_ros_interface/sim_command_sim2con", 1); 130 | force_apply_sub = nh.subscribe("/mujoco_ros_interface/applied_ext_force", 10, &force_apply_callback); 131 | 132 | if (!use_shm) 133 | { 134 | nh.param("pub_mode", pub_total_mode, false); 135 | std::cout<<"Name Space: " << ros::this_node::getNamespace() << std::endl; 136 | 137 | //register publisher & subscriber 138 | char prefix[200] = "/mujoco_ros_interface"; 139 | char joint_set_name[200]; 140 | char sim_status_name[200]; 141 | char joint_state_name[200]; 142 | char sim_time_name[200]; 143 | char sensor_state_name[200]; 144 | 145 | strcpy(joint_set_name, prefix); 146 | strcpy(sim_status_name, prefix); 147 | strcpy(joint_state_name, prefix); 148 | strcpy(sim_time_name, prefix); 149 | strcpy(sensor_state_name, prefix); 150 | if (ros::this_node::getNamespace() != "/") 151 | { 152 | strcat(joint_set_name, ros::this_node::getNamespace().c_str()); 153 | strcat(sim_status_name, ros::this_node::getNamespace().c_str()); 154 | strcat(joint_state_name, ros::this_node::getNamespace().c_str()); 155 | strcat(sim_time_name, ros::this_node::getNamespace().c_str()); 156 | strcat(sensor_state_name, ros::this_node::getNamespace().c_str()); 157 | } 158 | strcat(joint_set_name, "/joint_set"); 159 | strcat(sim_status_name, "/sim_status"); 160 | strcat(joint_state_name, "/joint_states"); 161 | strcat(sim_time_name, "/sim_time"); 162 | strcat(sensor_state_name, "/sensor_states"); 163 | 164 | joint_set = nh.subscribe(joint_set_name, 1, jointset_callback, ros::TransportHints().tcpNoDelay(true)); 165 | 166 | if (pub_total_mode) 167 | sim_status_pub = nh.advertise(sim_status_name, 1); 168 | else 169 | { 170 | joint_state_pub = nh.advertise(joint_state_name, 1); 171 | sim_time_pub = nh.advertise(sim_time_name, 1); 172 | sensor_state_pub = nh.advertise(sensor_state_name, 1); 173 | } 174 | } 175 | else 176 | { 177 | #ifdef COMPILE_SHAREDMEMORY 178 | init_shm(shm_msg_key, shm_msg_id, &mj_shm_); 179 | #endif 180 | } 181 | 182 | //ROS_INFO("ROS initialize complete"); 183 | sim_time_ros = ros::Duration(0); 184 | sim_time_run = ros::Time::now(); 185 | sim_time_now_ros = ros::Duration(0); 186 | 187 | // initialize everything 188 | init(); 189 | 190 | std::string model_file; 191 | // request loadmodel if file given (otherwise drag-and-drop) 192 | if (nh.getParam("model_file", model_file)) 193 | { 194 | mju_strncpy(filename, model_file.c_str(), 1000); 195 | settings.loadrequest = 2; 196 | ROS_INFO("model is at %s", model_file.c_str()); 197 | } 198 | 199 | // start simulation thread 200 | std::thread simthread(simulate); 201 | 202 | // event loop 203 | while ((!glfwWindowShouldClose(window) && !settings.exitrequest) && ros::ok()) 204 | { 205 | // start exclusive access (block simulation thread) 206 | mtx.lock(); 207 | // load model (not on first pass, to show "loading" label) 208 | if (settings.loadrequest == 1) 209 | { 210 | ROS_INFO("Load Request"); 211 | loadmodel(); 212 | } 213 | else if (settings.loadrequest > 1) 214 | settings.loadrequest = 1; 215 | 216 | // handle events (calls all callbacks) 217 | glfwPollEvents(); 218 | 219 | // prepare to render 220 | prepare(); 221 | 222 | // ros events 223 | rosPollEvents(); 224 | 225 | // end exclusive access (allow simulation thread to run) 226 | mtx.unlock(); 227 | 228 | // render while simulation is running 229 | render(window); 230 | } 231 | 232 | // stop simulation thread 233 | settings.exitrequest = 1; 234 | simthread.join(); 235 | 236 | // delete everything we allocated 237 | uiClearCallback(window); 238 | mj_deleteData(d); 239 | mj_deleteModel(m); 240 | mjv_freeScene(&scn); 241 | mjr_freeContext(&con); 242 | 243 | // deactive MuJoCo 244 | // mj_deactivate(); 245 | 246 | std_msgs::String pmsg; 247 | pmsg.data = std::string("terminate"); 248 | sim_command_pub.publish(pmsg); 249 | 250 | #ifdef COMPILE_SHAREDMEMORY 251 | deleteSharedMemory(shm_msg_id, mj_shm_); 252 | #endif 253 | // terminate GLFW (crashes with Linux NVidia drivers) 254 | #if defined(__APPLE__) || defined(_WIN32) 255 | glfwTerminate(); 256 | #endif 257 | 258 | return 0; 259 | } 260 | -------------------------------------------------------------------------------- /mujoco_ros_msgs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.3) 2 | project(mujoco_ros_msgs) 3 | 4 | find_package(catkin REQUIRED COMPONENTS 5 | message_generation 6 | geometry_msgs 7 | sensor_msgs 8 | std_msgs 9 | ) 10 | 11 | 12 | add_message_files( 13 | FILES 14 | applyforce.msg 15 | JointInit.msg 16 | JointSet.msg 17 | JointState.msg 18 | SensorState.msg 19 | SensorBase.msg 20 | SimstatusM2C.msg 21 | SimStatus.msg 22 | ) 23 | 24 | 25 | generate_messages( 26 | DEPENDENCIES std_msgs geometry_msgs 27 | ) 28 | 29 | catkin_package( 30 | CATKIN_DEPENDS message_runtime std_msgs 31 | geometry_msgs 32 | sensor_msgs 33 | ) 34 | 35 | include_directories( 36 | ${catkin_INCLUDE_DIRS} 37 | ) 38 | -------------------------------------------------------------------------------- /mujoco_ros_msgs/msg/JointInit.msg: -------------------------------------------------------------------------------- 1 | Header header 2 | 3 | string[] name 4 | -------------------------------------------------------------------------------- /mujoco_ros_msgs/msg/JointSet.msg: -------------------------------------------------------------------------------- 1 | Header header 2 | float64 time 3 | 4 | 5 | int32 MODE 6 | float64[] position 7 | float64[] torque 8 | 9 | # MODE 0 = POSITION 10 | # MODE 1 = TORQUE 11 | -------------------------------------------------------------------------------- /mujoco_ros_msgs/msg/JointState.msg: -------------------------------------------------------------------------------- 1 | 2 | Header header 3 | float64 time 4 | 5 | string[] name 6 | float64[] position 7 | float64[] velocity 8 | float64[] torque 9 | -------------------------------------------------------------------------------- /mujoco_ros_msgs/msg/SensorBase.msg: -------------------------------------------------------------------------------- 1 | string name 2 | 3 | float64[] data 4 | -------------------------------------------------------------------------------- /mujoco_ros_msgs/msg/SensorState.msg: -------------------------------------------------------------------------------- 1 | Header header 2 | 3 | 4 | SensorBase[] sensor 5 | -------------------------------------------------------------------------------- /mujoco_ros_msgs/msg/SimStatus.msg: -------------------------------------------------------------------------------- 1 | 2 | Header header 3 | float64 time 4 | 5 | string[] name 6 | float64[] position 7 | float64[] velocity 8 | float64[] effort 9 | 10 | SensorBase[] sensor -------------------------------------------------------------------------------- /mujoco_ros_msgs/msg/SimstatusM2C.msg: -------------------------------------------------------------------------------- 1 | #MUJOCO -> CONTROLLER SIM STATUS COMMANDER 2 | 3 | 4 | Header header 5 | float64 time 6 | 7 | bool sim_paused 8 | bool sim_reset 9 | 10 | 11 | -------------------------------------------------------------------------------- /mujoco_ros_msgs/msg/applyforce.msg: -------------------------------------------------------------------------------- 1 | Header header 2 | uint32 link_idx 3 | geometry_msgs/Wrench wrench -------------------------------------------------------------------------------- /mujoco_ros_msgs/package.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | mujoco_ros_msgs 4 | 0.0.0 5 | The mujoco_ros_msgs package 6 | 7 | Junhee_Ahn 8 | 9 | BSD 10 | 11 | Junhee_Ahn 12 | 13 | catkin 14 | geometry_msgs 15 | sensor_msgs 16 | std_msgs 17 | message_generation 18 | geometry_msgs 19 | sensor_msgs 20 | std_msgs 21 | message_runtime 22 | 23 | 24 | 25 | 26 | --------------------------------------------------------------------------------