Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
itmo-sai-code
rostok
Commits
8406521f
Commit
8406521f
authored
1 year ago
by
MikhailChaikovskii
Browse files
Options
Download
Email Patches
Plain Diff
default behavior for events
parent
ec87404c
master
article3-accurate-mass-geometric
article3-exception
article3-mcts-tree-random
article3-parallel_core
article3-shaker-and-show-results
article3-tune_hyperparameters
article_3
article_3_K
article_3_add_optimizer_holy_3
article_3_k2_hull
article_3_k_parallel
article_force_Kirill
article_learning
article_trajectories
builder_update
feature/golem_casessss
feature/paralel_script_for_run
feature/tendon_controller1
fix-readme-badges
fix/length_fix
fix_examples_grasping
prototype/tendon_ext_force
test_designs
test_run
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
rostok/criterion/simulation_flags.py
+19
-18
rostok/criterion/simulation_flags.py
rostok/simulation_chrono/basic_simulation.py
+29
-17
rostok/simulation_chrono/basic_simulation.py
with
48 additions
and
35 deletions
+48
-35
rostok/criterion/simulation_flags.py
View file @
8406521f
...
...
@@ -74,15 +74,14 @@ class EventContactTimeOut(SimulationSingleEvent):
"""
if
self
.
contact
:
return
EventCommands
.
CONTINUE
else
:
self
.
contact
=
env_data
.
get_amount_contacts
()[
0
]
>
0
if
self
.
contact
:
return
EventCommands
.
CONTINUE
else
:
if
current_time
>
self
.
reference_time
:
self
.
state
=
True
self
.
step_n
=
step_n
return
EventCommands
.
STOP
self
.
contact
=
env_data
.
get_amount_contacts
()[
0
]
>
0
if
self
.
contact
and
current_time
>
self
.
reference_time
:
self
.
state
=
True
self
.
step_n
=
step_n
return
EventCommands
.
STOP
return
EventCommands
.
CONTINUE
class
EventFlyingApart
(
SimulationSingleEvent
):
...
...
@@ -112,6 +111,8 @@ class EventFlyingApart(SimulationSingleEvent):
self
.
step_n
=
step_n
return
EventCommands
.
STOP
return
EventCommands
.
CONTINUE
class
EventSlipOut
(
SimulationSingleEvent
):
"""The event that stops simulation if the body slips out from the grasp after the contact.
...
...
@@ -140,16 +141,14 @@ class EventSlipOut(SimulationSingleEvent):
if
contact
:
self
.
time_last_contact
=
current_time
return
EventCommands
.
CONTINUE
else
:
if
self
.
time_last_contact
is
None
:
return
EventCommands
.
CONTINUE
else
:
if
current_time
-
self
.
time_last_contact
>
self
.
reference_time
:
if
(
not
self
.
time_last_contact
is
None
)
:
if
current_time
-
self
.
time_last_contact
>
self
.
reference_time
:
self
.
step_n
=
step_n
self
.
state
=
True
return
EventCommands
.
STOP
else
:
return
EventCommands
.
CONTINUE
return
EventCommands
.
CONTINUE
class
EventGrasp
(
SimulationSingleEvent
):
...
...
@@ -187,14 +186,14 @@ class EventGrasp(SimulationSingleEvent):
Returns:
EventCommands: return a command for simulation
"""
if
not
self
.
state
and
current_time
>
self
.
grasp_limit_time
:
return
EventCommands
.
STOP
if
self
.
state
:
if
current_time
>
self
.
force_test_time
+
self
.
grasp_time
:
return
EventCommands
.
STOP
else
:
return
EventCommands
.
CONTINUE
elif
current_time
>
self
.
grasp_limit_time
:
return
EventCommands
.
STOP
if
not
self
.
contact
:
self
.
contact
=
env_data
.
get_amount_contacts
()[
0
]
>
0
...
...
@@ -213,3 +212,5 @@ class EventGrasp(SimulationSingleEvent):
print
(
'Grasp event!'
,
current_time
)
return
EventCommands
.
ACTIVATE
return
EventCommands
.
CONTINUE
This diff is collapsed.
Click to expand it.
rostok/simulation_chrono/basic_simulation.py
View file @
8406521f
...
...
@@ -13,6 +13,8 @@ from rostok.virtual_experiment.robot_new import BuiltGraphChrono, RobotChrono
from
rostok.virtual_experiment.sensors
import
DataStorage
,
Sensor
from
rostok.criterion.simulation_flags
import
SimulationSingleEvent
,
EventCommands
import
time
class
SystemPreviewChrono
:
"""A simulation of the motionless environment and design"""
...
...
@@ -107,7 +109,7 @@ class SimulationResult:
key_storage
=
storage
[
key
]
for
key_2
in
key_storage
:
value
=
key_storage
[
key_2
]
new_value
=
value
[:
step_n
+
2
:]
new_value
=
value
[:
step_n
+
2
:]
key_storage
[
key_2
]
=
new_value
if
self
.
environment_final_ds
:
...
...
@@ -116,7 +118,7 @@ class SimulationResult:
key_storage
=
storage
[
key
]
for
key_2
in
key_storage
:
value
=
key_storage
[
key_2
]
new_value
=
value
[:
step_n
+
2
:]
new_value
=
value
[:
step_n
+
2
:]
key_storage
[
key_2
]
=
new_value
def
reduce_nan
(
self
):
...
...
@@ -281,7 +283,7 @@ class RobotSimulationChrono():
number_of_steps
:
int
,
step_length
:
float
,
frame_update
:
int
,
event_container
:
List
[
SimulationSingleEvent
]
=
None
,
event_container
:
List
[
SimulationSingleEvent
]
=
None
,
visualize
=
False
,
):
"""Execute a simulation.
...
...
@@ -309,7 +311,8 @@ class RobotSimulationChrono():
for
i
in
range
(
number_of_steps
):
current_time
=
self
.
chrono_system
.
GetChTime
()
self
.
simulate_step
(
step_length
,
current_time
,
i
)
self
.
result
.
time_vector
.
append
(
self
.
chrono_system
.
GetChTime
())
# TODO: timevector can be constructed from number_of_steps and time_step
self
.
result
.
time_vector
.
append
(
self
.
chrono_system
.
GetChTime
(
))
# TODO: timevector can be constructed from number_of_steps and time_step
if
vis
:
vis
.
Run
()
if
i
%
frame_update
==
0
:
...
...
@@ -318,7 +321,8 @@ class RobotSimulationChrono():
vis
.
EndScene
()
if
event_container
:
for
event
in
event_container
:
event_command
=
event
.
event_check
(
current_time
,
self
.
robot
.
sensor
,
self
.
data_storage
.
sensor
)
event_command
=
event
.
event_check
(
current_time
,
self
.
robot
.
sensor
,
self
.
data_storage
.
sensor
)
if
event_command
==
EventCommands
.
STOP
:
stop_flag
=
True
break
...
...
@@ -336,15 +340,31 @@ class RobotSimulationChrono():
self
.
result
.
reduce_nan
()
return
self
.
result
class
RobotSimulationWithForceTest
(
RobotSimulationChrono
):
def
__init__
(
self
,
delay
=
False
,
object_list
:
List
[
Tuple
[
ChronoEasyShapeObject
,
bool
]]
=
[]):
def
__init__
(
self
,
delay
=
False
,
object_list
:
List
[
Tuple
[
ChronoEasyShapeObject
,
bool
]]
=
[]):
super
().
__init__
(
object_list
)
self
.
delay_flag
=
delay
def
activate
(
self
,
code
:
int
,
current_time
,
step_n
):
def
activate
(
self
,
code
:
int
,
current_time
,
step_n
):
if
code
==
0
:
self
.
force_torque_container
.
controller_list
[
0
].
start_time
=
current_time
def
handle_events
(
self
,
event_container
,
current_time
,
step_n
):
if
event_container
==
None
:
return
False
for
event
in
event_container
:
event_command
=
event
.
event_check
(
current_time
,
step_n
,
self
.
robot
.
sensor
,
self
.
data_storage
.
sensor
)
if
event_command
==
EventCommands
.
STOP
:
return
True
elif
event_command
==
EventCommands
.
ACTIVATE
:
self
.
activate
(
event
.
activation_code
,
current_time
,
step_n
)
return
False
def
simulate
(
self
,
number_of_steps
:
int
,
...
...
@@ -385,19 +405,11 @@ class RobotSimulationWithForceTest(RobotSimulationChrono):
vis
.
BeginScene
(
True
,
True
,
chrono
.
ChColor
(
0.1
,
0.1
,
0.1
))
vis
.
Render
()
vis
.
EndScene
()
stop_flag
=
self
.
handle_events
(
event_container
,
current_time
,
i
)
if
event_container
:
for
event
in
event_container
:
event_command
=
event
.
event_check
(
current_time
,
i
,
self
.
robot
.
sensor
,
self
.
data_storage
.
sensor
)
if
event_command
==
EventCommands
.
STOP
:
stop_flag
=
True
break
elif
event_command
==
EventCommands
.
ACTIVATE
:
self
.
activate
(
event
.
activation_code
,
current_time
,
i
)
if
stop_flag
:
break
# just to slow down the simulation
if
self
.
delay_flag
:
time
.
sleep
(
0.0001
)
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help