Giter VIP home page Giter VIP logo

Comments (6)

armantekinalp avatar armantekinalp commented on August 30, 2024 1

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.

Ali-7800 avatar Ali-7800 commented on August 30, 2024 1

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.

Ali-7800 avatar Ali-7800 commented on August 30, 2024 1

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.

Junang-Wang avatar Junang-Wang commented on August 30, 2024

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.

Junang-Wang avatar Junang-Wang commented on August 30, 2024

@Ali-7800 Thank you so much for you help.

from pyelastica.

armantekinalp avatar armantekinalp commented on August 30, 2024

I am closing this issue seems it is resolved

from pyelastica.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.