Comments (6)
Hi @Junang-Wang
Although we have hooked up PyElastica with RL and model based controllers we haven't haven't tried controlling PyElastica rods with keyboard. Depending on the properties of the rod (soft rods) you can achieve real time simulations. Then you can design the interface with a keyboard controller to achieve your goal.
from pyelastica.
HI @Junang-Wang,
Here's a code snippet to help you with controlling the rod with your keyboard. I modified the AxialStretchingCase example to control the stretching force using the keyboard:
# ea.integrate(timestepper, stretch_sim, final_time, total_steps)
# modify the loop in ea.integrate to work with keyboard press
from elastica.timestepper import extend_stepper_interface
from tqdm import tqdm
import keyboard
do_step, stages_and_updates = extend_stepper_interface(timestepper, stretch_sim)
dt = np.float64(float(final_time) / total_steps)
time = 0
for i in tqdm(range(total_steps)):
time = do_step(timestepper, stages_and_updates, stretch_sim, time, dt)
if keyboard.is_pressed('a'):
print("a is pressed")
end_force[:] += dt*np.array([1.0,0.0,0.0]) #increase force when a is pressed (scaled by dt)
else:
temp = end_force.copy() - dt*np.array([1.0,0.0,0.0]) #decrease force when a is not pressed (scaled by dt)
if temp[0] > 0:
end_force[:] = temp #if greater than zero then use temp force
else:
end_force[:] = np.array([0.0,0.0,0.0]) #if less than zero then use zero force
controlled_stretching.mp4
from pyelastica.
Hi @Junang-Wang,
These might be helpful for the you: Elastica-RL-control, gym-softrobot.
It might also be helpful to look at the definition of integrate
in the __init__.py
file in elastica/timestepper to understand the code snippet I provided since it is just a modified version of that.
from pyelastica.
Hi @Ali-7800 @armantekinalp, thank you so much for your reply. Ali, your code snippet is very heuristic for me. Do you guys know where I can find the tutorial or document of PyElastica RL and model based controllers modules? I didn't find the information of control/Robotic modules, for example extend_stepper_interface in Ali's code, in the PyElastica doc page https://docs.cosseratrods.org/en/latest/index.html.
from pyelastica.
@Ali-7800 Thank you so much for you help.
from pyelastica.
I am closing this issue seems it is resolved
from pyelastica.
Related Issues (20)
- Reproducing snake diffraction results from your Nat Comm Paper HOT 7
- Failure for Helix under Gravity Case HOT 2
- Can PyElastica support GPU acceleration? HOT 3
- Do PyElastica support to simulate a rod containing two segments? HOT 3
- Question about base length HOT 8
- Replicating side-winding results from your Nat-comm snake paper HOT 29
- Small scale rod simulation HOT 11
- Updating muscle forces mid-simulation - how does it work? HOT 1
- Small-scale simulation problem 2 HOT 1
- OneEndFixedBC didn't work for applying a external torque HOT 4
- Adding force and torque at same time HOT 5
- How to using PyElastica data to visualize in 3D models? HOT 1
- `FileNotFoundError` `python continuum_snake.py` HOT 1
- Bug and fix in 2_Slithering_Snake.ipynb HOT 1
- Task 1: Utilizing Python to clean and convert data from Elastica into a format recognizable by Blender. HOT 1
- Avoid having randomized unittest HOT 17
- [GSOC project 3] Binding PyElastica with Elastica++ HOT 1
- GSoC interest in Optimizing backend kernels in PyElastica HOT 1
- Examples not running due to modules not being found HOT 18
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 pyelastica.