-
Notifications
You must be signed in to change notification settings - Fork 2
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 #12
Draft
frehe
wants to merge
43
commits into
main
Choose a base branch
from
Tobi_Dance
base: main
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 8 commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
68bf537
Starting template for integrating vector of target positions
marcinpaluch1994 6a6d218
to fix tensorflow JIT compile case insentivity problem, renamed cart …
tobidelbruck d1d9203
docstring for update_parameters
tobidelbruck cc2b58c
controller_mpc.py now copies all modified controller, cost and optimi…
tobidelbruck 06c7981
rename config_cost_function.yml to config_cost_functions.yml for cons…
tobidelbruck 068a0ac
finally the dynamically modifiable control cost parameters are workin…
tobidelbruck 64148a3
now spin and balance both work! and so does changing the policy and …
tobidelbruck fef38b0
got basic shimmy movement to work now. added helper vars to access co…
tobidelbruck d2e9942
added cartonly trajectory and fixed bug that erased the target positi…
tobidelbruck 03fa3af
passing current state to cartpole_trajectory_generator.py so it can e…
tobidelbruck ab0f34e
added MPPI papers to docstring
tobidelbruck 7ad7be1
added MPPI papers to docstring
tobidelbruck 86c8d68
Rename num_rollouts -> batch_size in config templates
frehe 3ade5d0
add comment
tobidelbruck 56d3e51
local changes, all minor except for trajectory cost that is in flux
tobidelbruck 9dad3a7
Merge remote-tracking branch 'origin/Tobi_Dance' into Tobi_Dance
tobidelbruck 67ba599
renamed s to state for clariy in many of the classes.
1f324f4
added dancer that reads CSV file to specify sequence of 'steps' (beha…
0b543a0
fixed import of CompileTF to point to SI_Toolkit
tobidelbruck 8fe2a96
Merge remote-tracking branch 'origin/main' into Tobi_Dance
tobidelbruck c0ee620
merged from Tobi_Dance and added some loggers
tobidelbruck ee9ca38
moved get_logger to own file in SI_Toolkit
tobidelbruck ecf2cc8
Merge remote-tracking branch 'origin/Tobi_Dance' into Tobi_Dance
tobidelbruck 69b886c
added search path for running from physical-cartpole.
tobidelbruck 4ce131e
update path to config_cost_functions.yml
tobidelbruck 32c0a50
move get_logger.py to Control_Toolkit so that it can be used by physi…
tobidelbruck 45f1d56
Merge remote-tracking branch 'origin/Tobi_Dance' into Tobi_Dance
tobidelbruck f0ec1d1
cartpole_dancer.py starts to work. Music starts and stops, some steps…
tobidelbruck 5d13e63
improved control slightly by adding back more cost terms to provide s…
tobidelbruck e2162fd
added some docstrings, but they are not very informative
tobidelbruck 518a00f
added prediction and target trajectory to logging to allow model mism…
tobidelbruck 9190c2a
add computation of pole natural frequency to p_globals.py.
tobidelbruck 6b8a676
added 'cartwheel' step to cartpole_trajectory_generator.py.
tobidelbruck 039d385
added warning for cart calibration.
tobidelbruck ed2c118
fixed some logic and reduced some loggers to debug level
tobidelbruck a16b454
fixed shimmy math.
tobidelbruck 000ff67
Merge remote-tracking branch 'origin/Tobi_Dance' into Tobi_Dance
tobidelbruck ea33a00
improved console reporting of current objective and logging output so…
tobidelbruck 6e8ef51
improved logging output to make debug logger light gray, include file…
tobidelbruck e894dfc
fixed get_logger.py that now uses a single logger name to only add th…
tobidelbruck 3489a44
reduced chatter in logging
tobidelbruck a1a36db
major changes to cartpole_dancer_cost and cartpole_trajectory_generat…
tobidelbruck 807c46d
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# stub for genrating desired future trajectory of cartpole | ||
import numpy | ||
import numpy as np | ||
from torch import TensorType | ||
|
||
from Control_Toolkit.Controllers import template_controller | ||
from Control_Toolkit.others.globals_and_utils import get_logger | ||
from SI_Toolkit.computation_library import ComputationLibrary | ||
from CartPole import state_utilities | ||
|
||
period=1 | ||
|
||
log=get_logger(__name__) | ||
|
||
class cartpole_trajectory_generator: | ||
""" Generates target state trajectory for the cartpole """ | ||
def __init__(self, lib:ComputationLibrary, controller:template_controller=None): | ||
""" Construct the trajectory generator. | ||
|
||
:param lib: the computation library, e.g. tensorflow | ||
:param horizon: the MPC horizon in timesteps | ||
""" | ||
self.lib = lib | ||
self.controller:template_controller=controller | ||
|
||
def step(self, time: float, horizon: int, dt:float) -> TensorType: | ||
""" Computes the desired future state trajectory at this time. | ||
|
||
:param time: the scalar time in seconds | ||
:param horizon: the number of horizon steps | ||
:param dt: the timestep in seconds | ||
|
||
:returns: the target state trajectory of cartpole. | ||
It should be a Tensor with NaN as at least first entries for don't care states, and otherwise the desired state values. | ||
|
||
""" | ||
|
||
traj=np.zeros((state_utilities.NUM_STATES, horizon)) # must be numpy here because tensor is immutable | ||
traj[:]=self.lib.nan # set all states undetermined | ||
|
||
cost_function=self.controller.cost_function_wrapper.cost_function # use cost_function to access attributes (fields) set in config_cost_functions.yml | ||
controller=self.controller # use controller to access attributes set in config_optimizers | ||
|
||
policy=cost_function.policy | ||
if policy is None: | ||
raise RuntimeError(f'set policy in config_cost_functions.yml') | ||
|
||
if policy == 'spin': # spin pole CW or CCW depending on target_equilibrium up or down | ||
traj[state_utilities.POSITION_IDX] = controller.target_position | ||
# traj[state_utilities.ANGLE_COS_IDX, :] = controller.target_equilibrium | ||
# traj[state_utilities.ANGLE_SIN_IDX, :] = 0 | ||
# traj[state_utilities.ANGLE_IDX, :] = self.lib.pi * controller.target_equilibrium | ||
traj[state_utilities.ANGLED_IDX, :] = 1000*controller.target_equilibrium # 1000 rad/s is arbitrary, not sure if this is best target | ||
# traj[state_utilities.POSITIOND_IDX, :] = 0 | ||
elif policy == 'balance': # balance upright or down at desired cart position | ||
traj[state_utilities.POSITION_IDX] = controller.target_position | ||
target_angle=self.lib.pi * (1-controller.target_equilibrium)/2 # either 0 for up and pi for down | ||
traj[state_utilities.ANGLE_COS_IDX, :] = np.cos(target_angle) | ||
traj[state_utilities.ANGLE_SIN_IDX, :] = np.sin(target_angle) | ||
traj[state_utilities.ANGLE_IDX, :] = target_angle | ||
traj[state_utilities.ANGLED_IDX, :] = 0 | ||
traj[state_utilities.POSITIOND_IDX, :] = 0 | ||
elif policy == 'shimmy': # cart follows a desired cart position shimmy while keeping pole up or down | ||
shimmy_period=cost_function.shimmy_period # seconds | ||
shimmy_amp=cost_function.shimmy_amp # meters | ||
endtime=time+horizon*dt | ||
times=np.linspace(time,endtime,num=horizon) | ||
shimmy=shimmy_amp*np.sin((2*np.pi/shimmy_period)*times) | ||
shimmyd=np.gradient(shimmy,dt) | ||
traj[state_utilities.POSITION_IDX] = controller.target_position+shimmy | ||
target_angle=self.lib.pi * (1-controller.target_equilibrium)/2 # either 0 for up and pi for down | ||
traj[state_utilities.ANGLE_COS_IDX, :] = np.cos(target_angle) | ||
traj[state_utilities.ANGLE_SIN_IDX, :] = np.sin(target_angle) | ||
traj[state_utilities.ANGLE_IDX, :] = target_angle | ||
# traj[state_utilities.ANGLED_IDX, :] = 0 | ||
traj[state_utilities.POSITIOND_IDX, :] = shimmyd | ||
else: | ||
log.error(f'cost policy "{policy}" is unknown') | ||
|
||
# traj=self.lib.to_variable(traj, self.lib.float32) | ||
|
||
return traj |
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.
Technically, we always work with a static reference to the computation library. That means we don't create instances of it, but always call the methods on the class itself. Therefore, the type of this attribute is
type
. This is really only for documentation. The code will work no matter what we put here.Btw, the subscript type notation
"type[ComputationLibrary]"
in quotes is necessary for python<=3.8. In later versions one can usetype[ComputationLibrary]
, but we maintain backward compatibility for now