Comments (1)
Hello there!
In case you are not aware or for anyone else that might read this, on the official Webots documentation you can find all available methods for all nodes and their usage for multiple languages including python. Here you can find official guides and tutorials.
Moreover, the official Webots discord is great place for asking questions relating to Webots, usually answered by the developers of Webots. Also, you can find more third-party tutorials advertised in the discord server.
Nevertheless, i will do my best to answer your question. To set or get positions of nodes in the Webots simulation, you generally have to do it through a supervisor Robot node
.
When a controller runs on a supervisor node it has access to additional methods. For your specific example you could possibly do it as follows:
- Create a Robot node and set it to supervisor through its atrributes on the tree view.
- Set the DEF of any node that you want to manipulate to your liking. You can set the DEF by left-clicking on a node in the tree view and a DEF field will appear to fill.
- Create a script and attach it to this node you want to manipulate.
- Use the
getFromDef()
method to get the reference to the node. - From that node extract the
translation
field or whatever field you are interested in manipulating, using the `getField("translation") method. - Use set methods to set the new value. For the
translation
field you need to use thesetSFVec3f()
.
I am including an example supervisor controller and a world file demonstrating the solution. I hope it helps! :)
supervisor controller:
"""Supervisor that repeatedly randomizes the translation of an object"""
from controller import Supervisor
from random import uniform
# create the Supervisor instance.
supervisor = Supervisor()
# get the time step of the current world.
timestep = int(supervisor.getBasicTimeStep())
boxNode = supervisor.getFromDef("BOX") # Get box node from its DEF
originalPosition = boxNode.getPosition()
print("Original position:", originalPosition)
boxTranslationField = boxNode.getField("translation") # Get a handle of the translation field
# Main loop:
# - perform simulation steps until Webots is stopping the controller
countLimit = 50
count = 50
while supervisor.step(timestep) != -1:
if count >= countLimit:
newPos = originalPosition
newPos[0] = uniform(0.0, 0.3) # x coordinate
newPos[2] = uniform(0.0, 0.3) # z coordinate
# Here we set the translation field.
# Depending on the field type, other set methods need to be used
boxTranslationField.setSFVec3f(newPos)
print("New random position:", newPos)
count = 0
count += 1
.wbt file:
#VRML_SIM R2020b utf8
WorldInfo {
coordinateSystem "NUE"
}
Viewpoint {
orientation -0.6931032800836722 0.6931032800836722 0.1980295085953349 0.75
position 0.6047745756810856 0.8076768137559899 0.9196826490423601
}
TexturedBackground {
}
TexturedBackgroundLight {
}
RectangleArena {
}
DEF BOX CardboardBox {
translation 0 0.06 0
size 0.1 0.1 0.1
}
Robot {
controller "my_controller"
supervisor TRUE
}
from deepbots.
Related Issues (20)
- Create documentation site
- Modify Docker
- get_timestep deprecation warning in supervisor_emitter_receiver
- Is it possible to run several simulations in parallel? HOT 1
- RobotEmitterReceiver class should inherit from Webots Robot class
- doubt about the implement of the emitter-receiver scheme HOT 9
- Usage of snake_case
- A bug of robot never moving HOT 1
- CSV handle_emitter data types
- Error in gym setup command: 'extras_require' HOT 5
- Migrating to gymnasium
- Unable to install deepbots HOT 2
- Gym Environment and using stable baselines HOT 2
- Request for Assistance with Sim2Real Transformation Using Emitter Receiver in DeepBots HOT 4
- There seems to be a bug in the step function of the robot_supervisor.py HOT 1
- Extend deepbots to support stable-baselines and implement gym-style default enviroments HOT 3
- Extend deepbots to support Evolutionary Algorithms HOT 14
- Question: how to get kinect camera information HOT 7
- [Tracker] Extension to Evolutionary Algorithms
- How to use ray to train in deepbots environment. HOT 3
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 deepbots.