Comments (3)
Sorry, it was an error on my part, I managed to figure this out.
Still curious to know why there is flexvert_xpos
when you can get the flex vertex xpos from xpos
through flex_vertbodyid
.
from mujoco.
Sorry, it was an error on my part, I managed to figure this out.
Still curious to know why there is
flexvert_xpos
when you can get the flex vertex xpos fromxpos
throughflex_vertbodyid
.
Hey! Would you mind sharing how you solved this?
from mujoco.
@dblanm
It appears that my assumption is correct: the flex_vertbodyid
maps a flex vertex to a mujoco body.
Here is a demonstration code:
Getting the flex id from name:
int getFlexId(std::string flexName) {
return mj_name2id(m, mjOBJ_FLEX, flexName.c_str());
}
Getting and setting all positions of the flex vertices:
std::vector<std::tuple<float, float, float>> getFlexPositions(std::string flexName) {
std::vector<std::tuple<float, float, float>> positions;
int flexId = getFlexId(flexName);
int firstVertadr = m->flex_vertadr[flexId];
int numVertices = m->flex_vertnum[flexId];
for(int i=0; i < numVertices; i++) {
int bodyId = m->flex_vertbodyid[firstVertadr + i];
float x = d->xpos[(bodyId * 3) + 0];
float y = d->xpos[(bodyId * 3) + 1];
float z = d->xpos[(bodyId * 3) + 2];
/* // or the same with:
x = d->flexvert_xpos[firstVertadr + i * 3 + 0];
y = d->flexvert_xpos[firstVertadr + i * 3 + 1];
z = d->flexvert_xpos[firstVertadr + i * 3 + 2];
*/
positions.push_back(std::make_tuple(x, y, z));
}
return positions;
}
void setFlexPositions(std::string flexName, std::vector<std::tuple<float, float, float>> positions) {
int flexId = getFlexId(flexName);
int firstVertadr = m->flex_vertadr[flexId];
int numVertices = m->flex_vertnum[flexId];
for(int i=0; i < numVertices; i++) {
int bodyId = m->flex_vertbodyid[firstVertadr + i];
const int jointIndex = m->body_jntadr[bodyId];
const int qposIndex = m->jnt_qposadr[jointIndex];
float x = std::get<0>(positions[i]);
float y = std::get<1>(positions[i]);
float z = std::get<2>(positions[i]);
d->qpos[qposIndex + 0] = x;
d->qpos[qposIndex + 1] = y;
d->qpos[qposIndex + 2] = z;
}
}
Getting and setting the flex vertex velocities:
std::vector<std::tuple<float, float, float>> getFlexVelocities(std::string flexName) {
std::vector<std::tuple<float, float, float>> velocities;
int flexId = getFlexId(flexName);
int firstVertadr = m->flex_vertadr[flexId];
int numVertices = m->flex_vertnum[flexId];
for(int i=0; i < numVertices; i++) {
int bodyId = m->flex_vertbodyid[firstVertadr + i];
const int jointIndex = m->body_jntadr[bodyId];
const int start = m->jnt_dofadr[jointIndex];
double linearX = d->qvel[start + 0];
double linearY = d->qvel[start + 1];
double linearZ = d->qvel[start + 2];
velocities.push_back(std::make_tuple(linearX, linearY, linearZ));
}
return velocities;
}
void setFlexVelocities(std::string flexName, std::vector<std::tuple<float, float, float>> velocities) {
int flexId = getFlexId(flexName);
int firstVertadr = m->flex_vertadr[flexId];
int numVertices = m->flex_vertnum[flexId];
for(int i=0; i < numVertices; i++) {
int bodyId = m->flex_vertbodyid[firstVertadr + i];
const int jointIndex = m->body_jntadr[bodyId];
const int start = m->jnt_dofadr[jointIndex];
float x = std::get<0>(velocities[i]);
float y = std::get<1>(velocities[i]);
float z = std::get<2>(velocities[i]);
d->qvel[start + 0] = x;
d->qvel[start + 1] = y;
d->qvel[start + 2] = z;
}
}
from mujoco.
Related Issues (20)
- Actuator force visualization HOT 5
- mj_forward modifies jacobian when called after mj_step HOT 3
- Bouncing in MJX HOT 1
- I have a question about the friction force experiment. HOT 2
- mjx.put_data() and mjx.put_model() takes lot of time to resolve HOT 2
- Improved MuJoCo Simulation Scaling HOT 1
- Camera rendering in MuJoCo - How to take a picture from a simulated camera and still keeping the GUI active
- MJX Documentation API Update HOT 1
- how to get flexible body position and velocity
- Possible to use different fluid force configuration among different links? HOT 2
- Problem using xpos to obtain the location of the xml file loaded model
- Manipulating Individual Joint Stiffness of a Elastic Cable HOT 1
- Issue with Camera Visibility of Dynamically Merged XML Models in MuJoCo HOT 1
- Issue with STL placements in new Model
- Support for Rendering in MJX for Simulated Camera Reinforcement Learning HOT 5
- `.skn` file not working with replicated bodies (dmcontrol rodent model) HOT 1
- Domain randomization for MJX HOT 7
- Resource not found (ValueError), but only on consecutive runs. HOT 12
- Equation for the Scalar Length l_i in the Actuator Transmission for Hinge Joints HOT 2
- Estimate qvel from sequence of rotations HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mujoco.