gazzolalab / elastica-rl-control Goto Github PK
View Code? Open in Web Editor NEWCode for the cases presented in the paper "Elastica: A compliant mechanics environment for soft robotic control"
License: MIT License
Code for the cases presented in the paper "Elastica: A compliant mechanics environment for soft robotic control"
License: MIT License
Hi PyElastica, thank you in advance for the time that you spent for the issues. I’m a Python beginner, so probabily I'm missing something. I download PyElastica with pip install pyelastica
and this repository with git clone. Then, I type in my terminal:
~/Elastica-RL-control/Case2$ python3 set_environment.py
and I obtain this error message:
File "set_environment.py", line 15, in <module>
from MuscleTorquesWithBspline.BsplineMuscleTorques import (
File "/home/daniele/elastica_ws/Elastica-RL-control/Case2/MuscleTorquesWithBspline/BsplineMuscleTorques/__init__.py", line 3, in <module>
from MuscleTorquesWithBspline.BsplineMuscleTorques.muscle_torques_with_bspline import (
ModuleNotFoundError: No module named 'MuscleTorquesWithBspline.BsplineMuscleTorques.muscle_torques_with_bspline'
Honestly, I don’t understand why import doesn’t work, so probably I’m missing something about building this project. Could you help me?
Thank you in advance
Hello PyElastica,
I wanted to know how can I generate time-series data from the RL model for different cases and write them to a text file. By data I mean the control input is given, the position of the tip of the robot, and time. I will be using this data to run a system identification algorithm which is part of my research.
Any advice would be of great help.
Thank you.
Hi all,
I was excited to explore this repo for my research. I was trying to run the case 1 with this command.
python3 logging_bio_args.py --algo_name TRPO --total_timesteps 1E6 --SEED 0 --timesteps_per_batch 2048
However, I was getting this error in the set_environment.py file.
********** Iteration 0 ************
Optimizing Policy...
sampling
The option to set damping coefficient (nu) for the rod during rod initialisation is now deprecated. Instead, for adding damping to rods, please derive your simulation class from the add-on Damping mixin class. For reference see the class elastica.dissipation.AnalyticalLinearDamper(), and for usage check examples/axial_stretching.py The option to set damping coefficient (nu) during rod construction will be removed in the future (v0.3.1).
Target position: 0.48091483107752364 0.7711978957802575 -0.4329243253563396
Traceback (most recent call last):
File "logging_bio_args.py", line 182, in <module>
model.learn(total_timesteps=int(args.total_timesteps))
File "/home/aneesh/Elastica-RL-control/venv/lib/python3.7/site-packages/stable_baselines/trpo_mpi/trpo_mpi.py", line 333, in learn
seg = seg_gen.__next__()
File "/home/aneesh/Elastica-RL-control/venv/lib/python3.7/site-packages/stable_baselines/common/runners.py", line 89, in traj_segment_generator
observation = env.reset()
File "/home/aneesh/Elastica-RL-control/venv/lib/python3.7/site-packages/stable_baselines/bench/monitor.py", line 80, in reset
return self.env.reset(**kwargs)
File "/home/aneesh/Elastica-RL-control/Case1/set_environment.py", line 426, in reset
class WallBoundaryForSphere(FreeRod):
NameError: name 'FreeRod' is not defined
Kindly help me out with this error.
I run policy_training_script.py and
File "C:\Users\LEESHOHYUN\anaconda3\envs\tensorflow\lib\multiprocessing\process.py", line 105, in start
File "C:\Users\LEESHOHYUN\anaconda3\envs\tensorflow\lib\multiprocessing\process.py", line 105, in start
self._popen = self._Popen(self)
File "C:\Users\LEESHOHYUN\anaconda3\envs\tensorflow\lib\multiprocessing\context.py", line 322, in _Popen
self._popen = self._Popen(self)
self._popen = self._Popen(self)
File "C:\Users\LEESHOHYUN\anaconda3\envs\tensorflow\lib\multiprocessing\context.py", line 322, in _Popen
File "C:\Users\LEESHOHYUN\anaconda3\envs\tensorflow\lib\multiprocessing\context.py", line 322, in _Popen
return Popen(process_obj)
File "C:\Users\LEESHOHYUN\anaconda3\envs\tensorflow\lib\multiprocessing\popen_spawn_win32.py", line 33, in init
return Popen(process_obj)
return Popen(process_obj)
File "C:\Users\LEESHOHYUN\anaconda3\envs\tensorflow\lib\multiprocessing\popen_spawn_win32.py", line 33, in init
File "C:\Users\LEESHOHYUN\anaconda3\envs\tensorflow\lib\multiprocessing\popen_spawn_win32.py", line 33, in init
prep_data = spawn.get_preparation_data(process_obj._name)
File "C:\Users\LEESHOHYUN\anaconda3\envs\tensorflow\lib\multiprocessing\spawn.py", line 146, in get_preparation_data
prep_data = spawn.get_preparation_data(process_obj._name)
File "C:\Users\LEESHOHYUN\anaconda3\envs\tensorflow\lib\multiprocessing\spawn.py", line 146, in get_preparation_data
prep_data = spawn.get_preparation_data(process_obj._name)
File "C:\Users\LEESHOHYUN\anaconda3\envs\tensorflow\lib\multiprocessing\spawn.py", line 146, in get_preparation_data
_check_not_importing_main()
File "C:\Users\LEESHOHYUN\anaconda3\envs\tensorflow\lib\multiprocessing\spawn.py", line 139, in _check_not_importing_main
_check_not_importing_main()
File "C:\Users\LEESHOHYUN\anaconda3\envs\tensorflow\lib\multiprocessing\spawn.py", line 139, in _check_not_importing_main
_check_not_importing_main()
File "C:\Users\LEESHOHYUN\anaconda3\envs\tensorflow\lib\multiprocessing\spawn.py", line 139, in _check_not_importing_main
is not going to be frozen to produce an executable.''')
RuntimeError:
An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.
This probably means that you are not using fork to start your
child processes and you have forgotten to use the proper idiom
in the main module:
if __name__ == '__main__':
freeze_support()
...
The "freeze_support()" line can be omitted if the program
is not going to be frozen to produce an executable.RuntimeError:
An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.
error happened.
where should I put if name=='main' ??
I am trying to build a custom gymnasium environment for my own RL project using PyElastica.
I've been digging into the muscle_torques_with_bspline.py
for Case 1 to try and understand the nuts and bolts of how muscle torques are changing mid-simulation.
In an attempt to compare it with a PyElastica example were forces/torques applied to rods aren't changing throughout the simulation, I looked at axial_stretching.py
which brought me to the EndPointForces class.
I am still not clear how muscle_torques_with_bspline.py
allows for an RL agent to change the torques within a rod while the simulation is running. Could this be explained?
I'm happy to provide additional details to clarify my question if that's useful.
Thanks in advance!
...
python3 logging_bio_args.py --total_timesteps=10000000.0 --SEED=4 --timesteps_per_batch=4000 --algo=TRPO
python3 logging_bio_args.py --total_timesteps=10000000.0 --SEED=4 --timesteps_per_batch=8000 --algo=TRPO
python3 logging_bio_args.py --total_timesteps=10000000.0 --SEED=4 --timesteps_per_batch=16000 --algo=TRPO
python3 logging_bio_args.py --total_timesteps=10000000.0 --SEED=4 --timesteps_per_batch=32000 --algo=TRPO
python3 logging_bio_args.py --total_timesteps=10000000.0 --SEED=4 --timesteps_per_batch=64000 --algo=TRPO
python3 logging_bio_args.py --total_timesteps=10000000.0 --SEED=4 --timesteps_per_batch=128000 --algo=TRPO
may I ask how can I running policy_training_script??
Hello PyElastica,
I really appreciate you guys for taking the time to resolve our queries. After taking the steps you mentioned in my issue titled " Generating Data From Trained Model ", I wanted to use MuscleTorqueWithVaryingBSpline and generate some data, and to do that I am using the code in the uploaded file.
Practice1.txt
But I run into the following error :
Traceback (most recent call last): File "Practice1.py", line 199, in <module> integrate(timestepper, ElasticaSim, final_time, total_steps) File "C:\Users\reach\anaconda3\envs\MyEnv\lib\site-packages\elastica\_elastica_numba\_timestepper\__init__.py", line 79, in integrate time = do_step(StatefulStepper, stages_and_updates, System, time, dt) File "C:\Users\reach\anaconda3\envs\MyEnv\lib\site-packages\elastica\timestepper\symplectic_steppers.py", line 83, in do_step SystemCollection.synchronize(time) File "C:\Users\reach\anaconda3\envs\MyEnv\lib\site-packages\elastica\wrappers\base_system.py", line 158, in synchronize feature(self, time) File "C:\Users\reach\anaconda3\envs\MyEnv\lib\site-packages\elastica\wrappers\forcing.py", line 84, in __call__ ext_force_torque.apply_torques(self._systems[sys_id], time, *args, **kwargs) File "C:\Users\reach\Desktop\Thesis\Elastica-RL-control-main\Case1\MuscleTorquesWithBspline\BsplineMuscleTorques\muscle_torques_with_bspline_numba.py", line 145, in apply_torques self.max_rate_of_change_of_activation, ValueError: unable to broadcast argument 1 to output array File "C:\Users\reach\anaconda3\envs\MyEnv\lib\site-packages\numba\np\npyimpl.py", line 228,
Any advice into this will be of great help
Thank you.
In Case 1, the __doc__
string states that
This script is to train or run a policy for the arm following randomly moving target. Case 1 in CoRL 2020 paper.
I'm assuming CoRL is "Conference on Robot Learning".
Looking at the references for the Naughton et al., RA-L, 2021 paper, I don't see any CoRL 2020 papers.
I also checked the wonderful supplementary materials website as well as tried searching through this archive of CoRL 2020 papers but to no avail.
Thanks in advance for pointing me in the right direction!
Hello PyElastica,
I am having trouble with the tip of the robot as it always points in the positive z-direction and barely moves down by a cm or two in the downward z-direction. Although I am applying forces in the normal, binormal, and twist directions. I did run the file a sufficiently large number of times but every time the tip never moved more than 2 cm. I am wondering what could I be possibly doing wrong ?
I have attached my code for reference.
MyElastica.txt
I've been able to successfully run all Cases in this repo within a virtual environment. In it, I am using pyelastica==0.1.0.post5
However, if I keep all things the same but changed to pyelastica==0.2.2.post2
, I get the following error when I run Case1/logging_bio_args.py
Traceback (most recent call last):
File "/home/saul/anaconda3/envs/rlcontrol-2/lib/python3.7/site-packages/elastica/wrappers/constraints.py", line 188, in __call__
*positions, *directors, *self._args, _system=rod, **self._kwargs
TypeError: __init__() got an unexpected keyword argument '_system'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/saul/Elastica-RL-control/Case1/logging_bio_args.py", line 182, in <module>
model.learn(total_timesteps=int(args.total_timesteps))
File "/home/saul/anaconda3/envs/rlcontrol-2/lib/python3.7/site-packages/stable_baselines/trpo_mpi/trpo_mpi.py", line 333, in learn
seg = seg_gen.__next__()
File "/home/saul/anaconda3/envs/rlcontrol-2/lib/python3.7/site-packages/stable_baselines/common/runners.py", line 89, in traj_segment_generator
observation = env.reset()
File "/home/saul/anaconda3/envs/rlcontrol-2/lib/python3.7/site-packages/stable_baselines/bench/monitor.py", line 80, in reset
return self.env.reset(**kwargs)
File "/home/saul/Elastica-RL-control/Case1/set_environment.py", line 610, in reset
self.simulator.finalize()
File "/home/saul/anaconda3/envs/rlcontrol-2/lib/python3.7/site-packages/elastica/wrappers/base_system.py", line 147, in finalize
finalize()
File "/home/saul/anaconda3/envs/rlcontrol-2/lib/python3.7/site-packages/elastica/wrappers/constraints.py", line 63, in _finalize_constraints
for constraint in self._constraints
File "/home/saul/anaconda3/envs/rlcontrol-2/lib/python3.7/site-packages/elastica/wrappers/constraints.py", line 63, in <listcomp>
for constraint in self._constraints
File "/home/saul/anaconda3/envs/rlcontrol-2/lib/python3.7/site-packages/elastica/wrappers/constraints.py", line 193, in __call__
"Unable to construct boundary condition class. Note that:\n"
TypeError: Unable to construct boundary condition class. Note that:
1. Any rod properties needed should be placed first
in the boundary_condition __init__ like so (pos_one, pos_two, <other_args>)
2. Number of requested position and directors such as (1, 2) should match
the __init__ method. eg MyBC.__init__(pos_one, director_one, director_two)
should have the `using` call as .using(MyBC, positions=(1,), directors=(1,-1))
Attempting to find the cause of this error, I believe this the error resulted from the adoption of Mixin and Composition to the code design, which happened after the publication of the Elastica-RL codebase.
Is there an easy way to adapt this code from Case 1 the WallBoundaryForSphere class to be compatible with pyelastica==0.3.1.post1
?
class WallBoundaryForSphere(FreeRod):
"""
This class generates a bounded space that sphere can move inside. If sphere
hits one of the boundaries (walls) of this space, it is reflected in opposite direction
with the same velocity magnitude.
"""
def __init__(self, boundaries):
self.x_boundary_low = boundaries[0]
self.x_boundary_high = boundaries[1]
self.y_boundary_low = boundaries[2]
self.y_boundary_high = boundaries[3]
self.z_boundary_low = boundaries[4]
self.z_boundary_high = boundaries[5]
def constrain_values(self, sphere, time):
pos_x = sphere.position_collection[0]
pos_y = sphere.position_collection[1]
pos_z = sphere.position_collection[2]
radius = sphere.radius
vx = sphere.velocity_collection[0]
vy = sphere.velocity_collection[1]
vz = sphere.velocity_collection[2]
if (pos_x - radius) < self.x_boundary_low:
sphere.velocity_collection[:] = np.array([-vx, vy, vz])
if (pos_x + radius) > self.x_boundary_high:
sphere.velocity_collection[:] = np.array([-vx, vy, vz])
if (pos_y - radius) < self.y_boundary_low:
sphere.velocity_collection[:] = np.array([vx, -vy, vz])
if (pos_y + radius) > self.y_boundary_high:
sphere.velocity_collection[:] = np.array([vx, -vy, vz])
if (pos_z - radius) < self.z_boundary_low:
sphere.velocity_collection[:] = np.array([vx, vy, -vz])
if (pos_z + radius) > self.z_boundary_high:
sphere.velocity_collection[:] = np.array([vx, vy, -vz])
def constrain_rates(self, sphere, time):
pass
I am working on an RL project and am trying to recreate Case 1 as a benchmark for my custom system. Specifically, I am trying to recreate the target sphere moving in a bounded box so beautifully illustrated here.
For that system, I am using pyelastica==0.3.1.post1
. When trying to recreate the target sphere moving in a bounded box, it seems that the error is being thrown when instantiating the WallBoundaryForSphere class.
I'm happy to provide any additional information or context, thanks in advance!
Hi all,
I wanted to know how we can run the postprocessing scripts. Where do we get the 2 required positional arguments: 'rods_history' and 'sphere_history' from? (for case2)
Hi all,
I'm building a custom RL env to do some learning tasks with soft filaments in PyElastica. I'm running into trouble applying new actions and I was looking over the Case 1 code for some guidance on how I might do that. One of the points that I am confused about is how you apply a new action when you call the step
method of the env. The reset
method finalizes the simulator and my understanding is that after finalization no new forces can be added. Is the point that no new forces can be added but we can change the magnitude of the forces/torques already there? In other words, how is the step
method applying a new force without resetting the environment?
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.