-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft: Tobi Dance Branch #48
Draft
frehe
wants to merge
116
commits into
master
Choose a base branch
from
Tobi_Dance
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
116 commits
Select commit
Hold shift + click to select a range
cc12775
Starting template for integrating vector of target positions
marcinpaluch1994 c383c1c
added parameter descriptions
tobidelbruck 50d71a5
REF TO Control_Toolkit
marcinpaluch1994 8fe670f
added parameter descriptions
tobidelbruck 824ae35
Merge remote-tracking branch 'origin/Tobi_Dance' into Tobi_Dance
tobidelbruck 89e2528
set hanging mode True to see whole state of pole.
tobidelbruck 2dad5ae
fixed README header and add link to global compile file
tobidelbruck 63590e1
more notes added
tobidelbruck d441109
document what JIT means
tobidelbruck a326093
added some docstrings
tobidelbruck cc33e60
added in utility to reload config if it has been modified on disk sin…
tobidelbruck 3cb32d2
fixed logging function to be colored cyan for info and to generate py…
tobidelbruck 4954af2
to fix tensorflow JIT compile case insentivity problem, renamed cart …
tobidelbruck 7a754f3
generate pycharm link in log output.
tobidelbruck 4d36e70
improved load_or_reload_config_if_modified to return dict of changed …
tobidelbruck 747628c
added dict_differ library
tobidelbruck ff46345
resize window smaller so we can see IDE.
tobidelbruck b3326f3
fix typing
tobidelbruck 38c45b0
added section for cartpole_trajectory_cost.py
tobidelbruck c08c2fa
rename config_cost_function.yml to config_cost_functions.yml for cons…
tobidelbruck 1767461
finally the dynamically modifiable control cost parameters are workin…
tobidelbruck a94082c
now spin and balance both work! and so does changing the policy and …
tobidelbruck 39fcecd
got basic shimmy movement to work now. added helper vars to access co…
tobidelbruck 61537d7
added cartonly trajectory and fixed bug that erased the target positi…
tobidelbruck bf83557
added check for incorrect float as int in config file if existing att…
tobidelbruck 2ffa4ed
passing current state to cartpole_trajectory_generator.py so it can e…
tobidelbruck 8336079
added MPPI papers to docstring
tobidelbruck f5c733e
added MPPI papers to docstring
tobidelbruck 1fdbe41
Rename tensorflow compilation flags
frehe 9958310
Update control toolkit
frehe 6352890
Finish renaming of num_rollouts -> batch_size
frehe 9ff1277
fix setting of correct type of variable, fix comments and docstrings
tobidelbruck 4e6e17d
add pypref to store cartpole GUI preferences
tobidelbruck 544e4c3
add preferences for CSV file
tobidelbruck 9965f9b
local changes, all minor except for trajectory cost that is in flux
tobidelbruck 2c59279
Merge remote-tracking branch 'origin/Tobi_Dance' into Tobi_Dance
tobidelbruck 0972952
renamed s to state for clariy in many of the classes.
5ef8c49
added dancer that reads CSV file to specify sequence of 'steps' (beha…
f7d016f
added the fist demo dance sequence file
284cfa3
got shimmy linear ramp from one freq/amp to another one working
4f8c691
added beep to signal change of step.
3cb2509
got cart bounce working for MPPI rollouts and added modeling of absor…
95ecbf6
add docstring for set_status_text method
00277fd
added comments about edge_bounce
bed7eee
docstrings
e02eb42
doctrings
06ef6ce
added policy number to dance step policy so that we can branch on it …
75bee6b
finally got spinning to work robustly by crafting a spin cost functio…
tobidelbruck ae2fbea
added vlc music player, start on start of dance, stop not implemented…
tobidelbruck 3dd3fe4
added signal to CartPoleMainWindow that emits signal when simulation …
tobidelbruck acf3231
fixed logic of starting dance. changed tensorflow to fix version 2.10…
12a6e66
added config values for track edge barrier and track barrier length
4e64f1e
changed dance to absolute song time to make it easier to synchronize.
tobidelbruck 4d2b903
moved the cartpole_dancer.py song and csv to config_cost_functions.yml.
tobidelbruck 86fd933
moved the cartpole_dancer.py song and csv to config_cost_functions.yml.
tobidelbruck 784ef6e
Merge remote-tracking branch 'origin/master' into Tobi_Dance
tobidelbruck f7974ff
merged from master, commented out dynamic song rate changes since it …
tobidelbruck 72b244b
Merge remote-tracking branch 'origin/main' into Tobi_Dance
tobidelbruck fa170c1
only add signal if GUI exists
tobidelbruck 34d778b
fixed logging at start of GPU. Fixed print_help().
tobidelbruck d3e38b6
typos, comments, and Merge remote-tracking branch 'origin/main' into …
tobidelbruck 6b6d66e
move preferences to own file in others prefs.py
tobidelbruck 427e618
Merge branch 'master' into Tobi_Dance
tobidelbruck f972fb3
merged from Tobi_Dance and added some loggers
tobidelbruck e66ac87
moved get_logger to own file in SI_Toolkit
tobidelbruck 3bfe82a
moved get_logger to own file in SI_Toolkit
tobidelbruck fee814c
added search path for running from physical-cartpole.
tobidelbruck fb49139
update path to config_cost_functions.yml
tobidelbruck 13ea6dc
move get_logger.py to Control_Toolkit so that it can be used by physi…
tobidelbruck 9616633
cartpole_dancer.py starts to work. Music starts and stops, some steps…
tobidelbruck 06f1947
improved control slightly by adding back more cost terms to provide s…
tobidelbruck 872ec3c
added some docstrings, but they are not very informative
tobidelbruck 0770b98
added primitive ability to record the predictor_ODE_tf.py predictions…
tobidelbruck 6b1f3f0
added prediction and target trajectory to logging to allow model mism…
tobidelbruck ead9c79
updated config_cost_functions.yml to match physical-cartpole better, …
tobidelbruck 42aebb8
added NaturalPeriod to cartpole constants, it is .73 seconds using th…
tobidelbruck ae7035b
add computation of pole natural frequency to p_globals.py.
tobidelbruck 4e7d284
fixed spin cost to count only terminal state of pole at end of horizo…
tobidelbruck 48d665b
cleanup comments
tobidelbruck 10809ba
updated dance, dance to satisfaction finally starting to work.New spi…
tobidelbruck bebba78
Merge remote-tracking branch 'origin/Tobi_Dance' into Tobi_Dance
tobidelbruck d517d7d
changed shimmy target trajectory to keep pole pointed at correct angl…
tobidelbruck d42307f
corrected formula for natural frequency based on error pointed out by…
tobidelbruck 5abab34
fixed cartpole_trajectory_generator.py for shimmy to make pole angle …
tobidelbruck 41ad200
fixed angle target for shimmy to be correct, shimmy works well in sim…
tobidelbruck b9bbb40
added 'cartwheel' step to cartpole_trajectory_generator.py.
tobidelbruck 195f669
modified cartwheel step to be a state machine with transitions betwee…
tobidelbruck 23e03b7
fixed logic for multiple cartwheels, seems to work fine now in simula…
tobidelbruck 1562d7a
small changes to weights to make balancing work better
tobidelbruck bab5a18
Merge remote-tracking branch 'origin/Tobi_Dance' into Tobi_Dance
tobidelbruck 4e8eac0
added comments to headers of some config files, not done yet.
tobidelbruck 6744441
Merge remote-tracking branch 'origin/Tobi_Dance' into Tobi_Dance
tobidelbruck 0fe4481
working demo of dancer, fixed inits of vars, updated costs to work be…
tobidelbruck 921968c
fixed some logic and reduced some loggers to debug level
tobidelbruck 02aded4
Merge remote-tracking branch 'origin/Tobi_Dance' into Tobi_Dance
tobidelbruck 60fd44e
added explanatory comments to config files
dab0b32
added more explanatory comments to config files
b6b071f
Merge remote-tracking branch 'origin/Tobi_Dance' into Tobi_Dance
tobidelbruck 5118bf2
fixed logic for shimmy start time, will test in simulation
tobidelbruck 92417f2
fixed shimmy math.
tobidelbruck 1b5be4f
working dancer
tobidelbruck 6b33317
improved console reporting of current objective and logging output so…
tobidelbruck 0e8a9f5
improved logging output to make debug logger light gray, include file…
tobidelbruck ee2fe88
improved cartonly and integrated to start of satification dance
tobidelbruck 318f641
reverted sookie sookie with corrupted binary
tobidelbruck 3666578
fixed get_logger.py that now uses a single logger name to only add th…
tobidelbruck 5424c72
fixed logic to test for changed cartpole cycles and casting to python…
tobidelbruck c2cf1d9
added to and fro cartwheel step
tobidelbruck b85dfdf
improved console output.
tobidelbruck 9da6d58
slightly changed pole length based on careful measurement
tobidelbruck fa8c24f
reduced chatter in logging
tobidelbruck 455f52b
updated config_cost_functions.yml from physical-cartpole
tobidelbruck dfef006
major changes to cartpole_dancer_cost and cartpole_trajectory_generat…
tobidelbruck 2a37817
latest physical-cartpole dancer, works with RPGD
tobidelbruck ae92487
added jtag connection photo.
tobidelbruck 36ad4c5
initial commit of Shreyan's code for energy-based controller for cart…
tobidelbruck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -10,9 +10,12 @@ | |||||
import csv | ||||||
# Import module to interact with OS | ||||||
import os | ||||||
import sys | ||||||
import traceback | ||||||
# Import module to get a current time and date used to name the files containing the history of simulations | ||||||
from datetime import datetime | ||||||
from typing import Optional | ||||||
|
||||||
# To detect the latest csv file | ||||||
|
||||||
import numpy as np | ||||||
|
@@ -22,9 +25,9 @@ | |||||
from Control_Toolkit.others.globals_and_utils import ( | ||||||
get_available_controller_names, get_available_optimizer_names, get_controller_name, get_optimizer_name, import_controller_by_name) | ||||||
from others.globals_and_utils import MockSpace, create_rng, load_config | ||||||
from others.p_globals import (P_GLOBALS, J_fric, L, m_cart, M_fric, TrackHalfLength, | ||||||
controlBias, controlDisturbance, export_globals, | ||||||
g, k, m_pole, u_max, v_max) | ||||||
from others.p_globals import (J_fric, L, m_cart, M_fric, TrackHalfLength, | ||||||
controlBias, controlDisturbance, g, k, m_pole, u_max, v_max, cart_bounce_factor, NaturalPeriod, | ||||||
export_globals) | ||||||
# Interpolate function to create smooth random track | ||||||
from scipy.interpolate import BPoly, interp1d | ||||||
# Run range() automatically adding progress bar in terminal | ||||||
|
@@ -40,6 +43,9 @@ | |||||
from CartPole.state_utilities import (ANGLE_COS_IDX, ANGLE_IDX, ANGLE_SIN_IDX, | ||||||
ANGLED_IDX, POSITION_IDX, POSITIOND_IDX) | ||||||
|
||||||
from Control_Toolkit.others.get_logger import get_logger | ||||||
log = get_logger(__name__) | ||||||
|
||||||
# region Imported modules | ||||||
|
||||||
try: | ||||||
|
@@ -143,7 +149,7 @@ def __init__(self, initial_state=s0, path_to_experiment_recordings=None): | |||||
# region Variables controlling operation of the program - should not be modified directly | ||||||
self.save_flag = False # Signalizes that the current time step should be saved | ||||||
self.csv_filepath = None # Where to save the experiment history. | ||||||
self.controller = None # Placeholder for the currently used controller function | ||||||
self.controller:template_controller = Optional[None] # Placeholder for the currently used controller function | ||||||
self.controller_name = '' # Placeholder for the currently used controller name | ||||||
self.optimizer_name = '' # Placeholder for the currently used optimizer name | ||||||
self.controller_idx = None # Placeholder for the currently used controller index | ||||||
|
@@ -199,7 +205,7 @@ def __init__(self, initial_state=s0, path_to_experiment_recordings=None): | |||||
self.slider_max = 1.0 | ||||||
self.slider_value = 0.0 | ||||||
|
||||||
self.show_hanging_pole = False | ||||||
self.show_hanging_pole = True | ||||||
|
||||||
self.physical_to_graphics = None | ||||||
self.graphics_to_physical = None | ||||||
|
@@ -446,6 +452,7 @@ def cartpole_integration(self): | |||||
|
||||||
def edge_bounce(self): | ||||||
# Elastic collision at edges | ||||||
# TODO should be semielastic | ||||||
self.s[ANGLE_IDX], self.s[ANGLED_IDX], self.s[POSITION_IDX], self.s[POSITIOND_IDX] = edge_bounce_numba( | ||||||
self.s[ANGLE_IDX], | ||||||
np.cos(self.s[ANGLE_IDX]), | ||||||
|
@@ -460,6 +467,10 @@ def edge_bounce(self): | |||||
# This function should be called for the first time to calculate 0th time step | ||||||
# Otherwise it goes out of sync with saving | ||||||
def Update_Q(self): | ||||||
""" Determine the dimensionless [-1,1] value of the motor power Q | ||||||
This function should be called for the first time to calculate 0th time step | ||||||
Otherwise it goes out of sync with saving, | ||||||
""" | ||||||
# Calculate time steps from last update | ||||||
# The counter should be initialized at max-1 to start with a control input update | ||||||
self.dt_controller_steps_counter += 1 | ||||||
|
@@ -471,7 +482,7 @@ def Update_Q(self): | |||||
# in this case slider corresponds already to the power of the motor | ||||||
self.Q = self.slider_value | ||||||
else: # in this case slider gives a target position, lqr regulator | ||||||
self.Q = self.controller.step(self.s_with_noise_and_latency, self.time, {"target_position": self.target_position, "target_equilibrium": self.target_equilibrium}) | ||||||
self.Q = self.controller.step(self.s_with_noise_and_latency, self.time, updated_attributes= {"target_position": self.target_position, "target_equilibrium": self.target_equilibrium}) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Good catch. Technically, we should also pass the time as keyword-arg, because it is also optional. |
||||||
|
||||||
self.dt_controller_steps_counter = 0 | ||||||
|
||||||
|
@@ -488,6 +499,11 @@ def update_parameters(self): | |||||
|
||||||
# This method saves the dictionary keeping the history of simulation to a .csv file | ||||||
def save_history_csv(self, csv_name=None, mode='init', length_of_experiment='unknown'): | ||||||
""" Saves history of cartpole state and control | ||||||
:param csv_name: the filename base, .csv is appended if it is not there. self.path_to_experiment_recordings is prepended for path | ||||||
:param mode: the mode for saving, default is 'init' which makes the timestamped folder etc TODO what are these modes??????? | ||||||
:param length_of_experiment: the duration of this experiment in seconds, written to header of CSV | ||||||
""" | ||||||
|
||||||
if mode == 'init': | ||||||
|
||||||
|
@@ -550,8 +566,9 @@ def save_history_csv(self, csv_name=None, mode='init', length_of_experiment='unk | |||||
|
||||||
writer.writerow(['#']) | ||||||
writer.writerow(['# Parameters:']) | ||||||
for k in P_GLOBALS.__dict__: | ||||||
writer.writerow(['# ' + k + ': ' + str(getattr(P_GLOBALS, k))]) | ||||||
c = load_config("config.yml") | ||||||
for k,v in c.items(): | ||||||
writer.writerow(['# ' + k + ': ' + str(v)]) | ||||||
writer.writerow(['#']) | ||||||
|
||||||
writer.writerow(['# Data:']) | ||||||
|
@@ -900,8 +917,9 @@ def set_controller(self, controller_name=None, controller_idx=None): | |||||
) | ||||||
|
||||||
else: | ||||||
log.debug(f'configuring controller "{self.controller}"') | ||||||
self.controller.configure() | ||||||
|
||||||
|
||||||
# Set the maximal allowed value of the slider - relevant only for GUI | ||||||
if self.controller_name == 'manual-stabilization': | ||||||
|
@@ -932,8 +950,10 @@ def set_cartpole_state_at_t0(self, reset_mode=1, s=None, target_position=None, r | |||||
pass | ||||||
|
||||||
# reset global variables | ||||||
global k, m_cart, m_pole, g, J_fric, M_fric, L, v_max, u_max, controlDisturbance, controlBias, TrackHalfLength | ||||||
k[...], m_cart[...], m_pole[...], g[...], J_fric[...], M_fric[...], L[...], v_max[...], u_max[...], controlDisturbance[...], controlBias[...], TrackHalfLength[...] = export_globals() | ||||||
global k, m_cart, m_pole, g, J_fric, M_fric, L, v_max, u_max, controlDisturbance, controlBias, TrackHalfLength, cart_bounce_factor, NaturalPeriod | ||||||
# TODO why is ellipis object used here? https://stackoverflow.com/questions/772124/what-does-the-ellipsis-object-do | ||||||
# these outputs of export_globals are numpy scalar arrays, i.e. each constant is a np.array with a single element | ||||||
k[...], m_cart[...], m_pole[...], g[...], J_fric[...], M_fric[...], L[...], v_max[...], u_max[...], controlDisturbance[...], controlBias[...], TrackHalfLength[...], cart_bounce_factor[...], NaturalPeriod[...] = export_globals() | ||||||
|
||||||
self.time = 0.0 | ||||||
if reset_mode == 0: # Don't change it | ||||||
|
@@ -1297,3 +1317,17 @@ def animationManage(i): | |||||
return anim | ||||||
|
||||||
# endregion | ||||||
|
||||||
|
||||||
def is_physical_cartpole_running_and_control_enabled(): | ||||||
""" super hack to determine if we are running physical cartpole and control is turned on""" | ||||||
if 'DriverFunctions' in sys.modules: # if this module exists in sys.modules, we can deduce that physical-cartpole is running | ||||||
try: | ||||||
physical_cartpole_instance = sys.modules[ | ||||||
'DriverFunctions'].PhysicalCartPoleDriver.PhysicalCartPoleDriver.PhysicalCartPoleDriverInstance | ||||||
if getattr(physical_cartpole_instance, 'controlEnabled') == True: | ||||||
log.debug(f'physical cartpole present and control enabled') | ||||||
return True | ||||||
except Exception as e: | ||||||
log.warning(f'Could not determine if control is enabled: {e}') | ||||||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.