I have Maya, an animation program controlling my arduino through Dan Thompson’s servo tools plugin.
I want to take animation that I’ve done in Maya with simple rotation values (3 in this case) and export from maya to use as code in arduino. The actual conversion out of maya is simple. I can write some python code to turn the keys into something usable if the arduino side can parse it. So that’s not a problem.
I’m wondering what is the most feasible way to store this information in the arduino itself instead of listening to serial port. I could export a string of the animation keys something like this: “0.0:0,5.0:45” ← Translating to “At 0.0 seconds servo should be 0, at 5.0 seconds servo should be 45” Then maybe in arduino I could split by comma to get each keyframe, and then split by colon to get the time and value. Then after elapsed time passes the earliest keyframe time, set to value. Currently not worried about interpolating or tangents, just want the data. I hope this makes sense.
I’m not super great at coding in arduino yet and I’m not sure if one big string is the way to go. Does anyone have advice on how to go about this?
[Edited for clarity]
The examples in serial input basics may be useful. It includes and example of parsing data.
Thanks but I’m currently using serial data and trying to move away from that to something baked into the code.
A maybe not so great example in pseudocode:
stringFromMaya = "0:0,5:45,7:90,10:0"
listOfKeyframes = stringFromMaya.split(',')
currentIndex = 0
dataList = listOfKeyframes[currentIndex].split(':')
if currentTime > dataList:
currentIndex += 1
In the above example the servo will turn to 0 degrees immediately, 45 degrees at 5 seconds, 90 degrees at 7 seconds, and back to 0 at 10 seconds. The “0:0,5:45,7:90,10:0” is what I’ll get out of my script in maya.
Im a fan of the KISS principle. What you have looks simple and reliable, so why not ?
Second, you should make functions “compileAnimation” and “parseArnimation” for example,
and have all the string work done in there. So that in the future, if you want to change
your format, you simply change those functions only, so that the rest of the program
continues to work without changing anything there.
This architecture will allow you to move on with confidence that even if you need to change
the format, this will not affect the rest of the program.
You might be able to put a script file on an SD card then open the file and read the script commands.
Thanks but I'm currently using serial data and trying to move away from that to something baked into the code.
Ahh .. I misunderstood. However I think my parse example should be appropriate.
The trick is to figure out a system that is easy to use on the Arduino and then get Python to produce data to that spec. Python has lots more time and resources.
Another important aspect is to design the Arduino program to be as simple and general as possible so that it is (ideally) never necessary to change it. All the changes are done by changing the data prepared by the PC. I think I am going a little further than @dtrip when I say this. I have written some Arduino code to drive 3 stepper motors on a small lathe using data sent by a Python program. I am continually developing and figuring out the Python code but it is months since I wrote the Arduino code - to the extent that I have almost forgotten how it works.
As people have said an SD Card may be a good idea because it could be written on the PC and read on the Arduino. Different SD cards for different animations.
Do you intend to recompile the program each time the animation changes? It seems undesirable - hence Zoomkat's suggestion of reading the string from an SD card. If so though, you might as well emit the data as source code and create a pair of arrays of data (time and angle) or better, an array of structs. Then you can just paste it in and dispense with any parsing.
Thanks for all the tips guys!
The sd card is a cool idea but might be overkill. I've already animated it and am done with the project which was just an experiment with maya. But then when my mom found out I'd be tearing it apart for parts she insisted I refrain and instead install it in her house. So I don't want to dedicate one of my laptops to it and train her on how to use maya.
Do you intend to recompile the program each time the animation changes?
Indeed I would have to, but I don't intend on changing the animation.
you might as well emit the data as source code and create a pair of arrays of data (time and angle) or better, an array of structs. Then you can just paste it in and dispense with any parsing.
This sounds like what I'm doing, so I might be mistaken on what 'parse' means. To google!
[Edit] After talking with some coworkers I'm not going to use a string. And I now understand more what you meant about the pair of arrays and really like that idea. You also suggested that structs would be better - I'll look into how to do that. Thanks!