Last active
July 3, 2019 15:57
-
-
Save shikarunochi/2d81dded14a068fddd9578a9f64f5080 to your computer and use it in GitHub Desktop.
motionScript maker for PLEN:bit ( Microsoft MakeCode)
This file contains hidden or 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
import sys | |
import os | |
import json | |
args = sys.argv | |
fileName = args[1] | |
motionFile = open(fileName, 'r') | |
motionJson = json.load(motionFile) | |
scriptFileName = os.path.splitext(fileName)[0] + ".motionScript" | |
scriptFile = open(scriptFileName, 'w') | |
frames = motionJson["frames"] | |
for frame in frames: | |
device_list = ["left_shoulder_pitch", | |
"left_thigh_yaw", | |
"left_shoulder_roll", | |
"left_foot_roll", | |
"right_shoulder_pitch", | |
"right_thigh_yaw", | |
"right_shoulder_roll", | |
"right_foot_roll", | |
] | |
transition_time_ms = frame["transition_time_ms"] | |
motionDataList = [0,0,0,0,0,0,0,0] | |
outputs = frame["outputs"] | |
for output in outputs: | |
device = output["device"] | |
value = output["value"] | |
if device in device_list: | |
motionDataList[device_list.index(device)] = value | |
scriptFile.write("plenbit.setAngle([" + ",".join(map(str, motionDataList)) + "], " + str(transition_time_ms) + ")") | |
scriptFile.write("\n") | |
motionFile.close() | |
scriptFile.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment