Replies: 1 comment
-
You need to use a physics plugin to apply user specified forces (or torques). Then you can add the physics plugin with the File / New / New Physics Plugin... menu item. After having added the plugin you must compile it using Webots editor. Then you must associate the plugin with your simulation world. This can be done by editing the WorldInfo.physics field in the Scene Tree. Then you must modify the plugin code such as to add the force. Here is an example: #include <ode/ode.h>
#include <plugins/physics.h>
dBodyID body = NULL;
void webots_physics_init() {
// find the body on which you want to apply a force
body = dWebotsGetBodyFromDEF("MY_ROBOT");
...
}
void webots_physics_step() {
...
dVector3 f;
f[0] = ...
f[1] = ...
f[2] = ...
...
// at every time step, add a force to the body
dBodyAddForce(body, f[0], f[1], f[2]);
...
}
```
There is more info on the plugin functions in the [Reference Manual](https://www.cyberbotics.com/doc/reference/physics-plugin). Additional information about the ODE functions can be found [here](http://ode.org/wiki/index.php?title=Manual). You may also want to study this example distributed with Webots: `WEBOTS_HOME/projects/samples/demos/worlds/salamander.wbt`.
In this example, the physics plugin adds user computed forces to the robot body in order to simulate Archimedes and hydrodynamic drag forces. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I need to apply programmatically a force to an object in Webots. How to proceed?
Beta Was this translation helpful? Give feedback.
All reactions