olsonk / pyRosita

0 stars 0 forks source link

Re-work the Sequencer.add() method away from current string -> actions[string] format #8

Open olsonk opened 6 years ago

olsonk commented 6 years ago

It's very error-prone to ask the user to type in a string in a certain format, and then lookup that key in a dictionary. It's not easily expandable, requires a long dictionary, and is not intuitive.

Create a simple grammar for parsing a string and calling actions based on the string. Ex: "left grip" becomes "set left_grip 1", "left arm move", x=20, y=70 becomes "set left_arm_move 20,70"

Follow format for all methods.

jteller commented 6 years ago

The parameterized x/y coordinate I think is just fine, as it allows you to be a little more flexible passing in arguments. So I think : "set left_arm_move", x=20, x=70 would work well, as long as you can then do: "set left_grip", 1

olsonk commented 6 years ago

Began re-working Sequencer.add(). Now accepts a string, *args, and *kwargs. String is .split(" ") to separate verb from noun. If verb is "set" or "change" then checks if noun is a recognized part name or robot action, and calls methods appropriately. Checks args for a tuple for (x, y) methods, or simply checks if *args[0] is an int OR if kwargs contains a recognized keyword, and passes it to a method. See this commit.

olsonk commented 6 years ago

Still seems very inefficient, though - need to investigate ways to simplify conditional structure

olsonk commented 6 years ago

Removed unnecessary set_nod(), set_up(), etc. methods from each robot class. Removed Sequencer.actions dict, since the new approach is simply to parse string and use conditionals to determine what actions are being added. See this commit.