-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Using config fully now instead of constants
except for the initial stepper delay.. need to calculate that then calibrate from it.
- Loading branch information
Showing
4 changed files
with
201 additions
and
103 deletions.
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import os.path | ||
import time, datetime | ||
import yaml | ||
|
||
CONFIG_FILENAME="stepper.yaml" | ||
|
||
def save(config): | ||
# update history | ||
if 'calculated_ms' in config['delays']: | ||
latest=None | ||
if len(config['history']) > 0: | ||
latest=config['history'][0] | ||
|
||
# assume structure of history is valid | ||
|
||
# create new history if any delays have changed OR we don't have any history | ||
create_history=False | ||
if latest is not None: | ||
for key in config['delays'].keys(): | ||
h_value=latest[key] | ||
d_value=config['delays'][key] | ||
if h_value != d_value: | ||
create_history=True | ||
break | ||
else: | ||
create_history=True | ||
|
||
if create_history: | ||
new_history={} | ||
new_history['timestamp']=datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S') | ||
for key in config['delays'].keys(): | ||
new_history[key]=config['delays'][key] | ||
config['history'].insert(0, new_history) | ||
|
||
with open(CONFIG_FILENAME, 'w') as outfile: | ||
yaml.dump(config, outfile, default_flow_style=False) | ||
|
||
def load(): | ||
config={} | ||
if os.path.exists(CONFIG_FILENAME): | ||
with open(CONFIG_FILENAME, 'r') as infile: | ||
config=yaml.load(infile, Loader=yaml.FullLoader) | ||
|
||
# initialize requrired child objects and arrays | ||
objects = ['pins','delays'] | ||
arrays = ['history'] | ||
|
||
for obj in objects: | ||
if obj not in config: | ||
config[obj]={} | ||
for arr in arrays: | ||
if arr not in config: | ||
config[arr]=[] | ||
|
||
return config |
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,46 @@ | ||
{ | ||
"debug": false, | ||
"gp_out": { | ||
"v5": 18, | ||
"led": 25, | ||
"stepper":[28,27,26,22], | ||
"startup_gp_on":["v5","led"] | ||
}, | ||
"gp_in": { | ||
"forward": -1, | ||
"reverse": -1, | ||
"stop": -1, | ||
"slower": -1, | ||
"faster": -1, | ||
"lock": -1, | ||
"unkock": -1 | ||
}, | ||
"controls": { | ||
"hold_unlock_s": 5, | ||
"hold_lock_s": 5, | ||
"faster_increment": 0.1, | ||
"slower_increment": 0.1, | ||
"reverse_speed_multiplier": 4 | ||
}, | ||
"tracker": { | ||
"radius": 200, | ||
"pitch": 0.7874, | ||
"gear_ratio": "10:43", | ||
"stepper": { | ||
"sequence": [ | ||
[1,0,0,0], | ||
[1,1,0,0], | ||
[0,1,0,0], | ||
[0,1,1,0], | ||
[0,0,1,0], | ||
[0,0,1,1], | ||
[0,0,0,1], | ||
[1,0,0,1] | ||
] | ||
} | ||
}, | ||
"calibration": { | ||
"accuracy": 0.001, | ||
"calibrated_gp_off": ["led"] | ||
} | ||
} |
Oops, something went wrong.