Get Help
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Get Help
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
PoMoCo has a feature to generate Arduino code for use with your controller. You can find the button to do so in the upper-left hand corner, above the moves:
This will show the Record Arduino Moves dialog:
The instruction to generate the code for Arduino are in the box, but here they are for reference:
How to record a move for Arduino:
0.) (Optional) Choose a move name in the box above
1.) Press the red record above button above
2.) Run a move or multiple moves in PoMoCo
3.) Press the black stop button above
4.) Copy the generated move code to the Arduino IDE
When we follow these steps for the move “Reset” with an uncalibrated Hexy using a Servotor32, we get the following code generated:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
#include <avr/pgmspace.h> #define MOVE_HEXY_SIZE 168 const PROGMEM uint16_t move_hexy_time[MOVE_HEXY_SIZE] = { 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 400, 401, 401, 401, 402, 402, 402, 402, 403, 403, 403, 403, 403, 403, 403, 404, 404, 404, 501, 501, 501, 501, 501, 502, 502, 502, 502, 503, 503, 503, 503, 503, 503, 504, 504, 504, 601, 601, 601, 601, 602, 602, 602, 602, 602, 603, 603, 603, 603, 603, 603, 603, 604, 604, 901, 901, 901, 902, 902, 902, 902, 902, 902, 903, 903, 903, 1302, 1302, 1302, 1303, 1303, 1303, 1303, 1303, 1303, 1303, 1304, 1304, 1304, 1304, 1304, 1304, 1304, 1304, 1402, 1402, 1402, 1402, 1402, 1402, 1403, 1403, 1403, 1403, 1403, 1403, 1403, 1403, 1404, 1404, 1404, 1404, 1501, 1501, 1501, 1501, 1501, 1501, 1502, 1502, 1502, 1502, 1502, 1503, 1503, 1503, 1503, 1503, 1503, 1503, 1804, 1805, 1805, 1805, 1806, 1806, 1807, 1808, 1808, 1809, 1811, 1811, 1811, 1811, 1812, 1812, 1813, 1813, 1813, 1814, 1814, 1814, 1814, 1814, 1814, 1815, 1815, 1815, 1815, 1815, 1815, 1815, 1815, 1816, 1816, 1816}; const PROGMEM uint8_t move_hexy_servo[MOVE_HEXY_SIZE] = { 6, 6, 21, 5, 21, 5, 22, 14, 22, 14, 13, 13, 6, 6, 5, 21, 5, 21, 7, 22, 14, 7, 22, 14, 13, 20, 13, 20, 15, 15, 6, 6, 5, 5, 7, 7, 21, 14, 14, 21, 13, 22, 13, 22, 15, 20, 15, 20, 6, 6, 5, 5, 7, 7, 14, 21, 14, 21, 13, 22, 13, 22, 15, 20, 15, 20, 25, 25, 26, 10, 26, 10, 17, 9, 17, 9, 18, 18, 25, 25, 26, 10, 26, 10, 24, 17, 9, 24, 17, 9, 18, 11, 18, 11, 16, 16, 25, 25, 26, 26, 24, 24, 17, 10, 17, 10, 18, 9, 18, 9, 16, 11, 16, 11, 25, 25, 26, 26, 24, 24, 17, 10, 17, 10, 18, 9, 18, 9, 16, 11, 16, 11, 6, 6, 5, 10, 5, 10, 14, 9, 14, 25, 9, 13, 21, 25, 13, 21, 26, 7, 22, 26, 17, 7, 22, 17, 20, 20, 18, 18, 15, 15, 24, 24, 11, 11, 16, 16}; const PROGMEM uint8_t move_hexy_pos[MOVE_HEXY_SIZE] = { 153 , 153 , 146 , 156 , 146 , 56 , 147 , 152 , 47 , 152 , 153 , 53 , 153 , 160 , 56 , 146 , 63 , 205 , 150 , 47 , 152 , 161 , 106 , 159 , 53 , 153 , 60 , 153 , 147 , 136 , 160 , 160 , 63 , 63 , 161 , 172 , 205 , 159 , 159 , 205 , 60 , 106 , 60 , 106 , 136 , 153 , 125 , 153 , 160 , 212 , 63 , 115 , 172 , 183 , 159 , 205 , 211 , 205 , 60 , 106 , 112 , 106 , 125 , 153 , 114 , 153 , 153 , 153 , 153 , 140 , 53 , 140 , 153 , 153 , 153 , 53 , 153 , 53 , 153 , 160 , 53 , 140 , 60 , 199 , 150 , 153 , 53 , 138 , 160 , 112 , 53 , 152 , 60 , 152 , 145 , 156 , 160 , 160 , 60 , 60 , 138 , 127 , 160 , 199 , 160 , 199 , 60 , 112 , 60 , 112 , 156 , 152 , 167 , 152 , 160 , 212 , 60 , 112 , 127 , 116 , 160 , 199 , 212 , 199 , 60 , 112 , 112 , 112 , 167 , 152 , 178 , 152 , 212 , 212 , 115 , 199 , 115 , 199 , 211 , 112 , 211 , 212 , 112 , 112 , 205 , 212 , 112 , 205 , 112 , 183 , 106 , 112 , 212 , 183 , 106 , 212 , 153 , 153 , 112 , 112 , 114 , 114 , 116 , 116 , 152 , 152 , 178 , 178 }; void move_hexy(){ int startTime = hexy.millis_new(); int currentTime = 0; int last_update = 0; for(int i=0; i<MOVE_HEXY_SIZE; i++){ delayMicroseconds(10); currentTime = hexy.millis_new() - startTime; uint16_t move_time = pgm_read_word_near(move_hexy_time + i); while(currentTime < move_time){ delayMicroseconds(10); currentTime = hexy.millis_new() - startTime; } uint8_t servo_time = pgm_read_byte_near(move_hexy_servo + i); uint8_t servo_pos = pgm_read_byte_near(move_hexy_pos + i); hexy.changeServo(servo_time, servo_pos*10); last_update = currentTime; } } //Move Size is 672 bytes //Run this move by using: // move_hexy() |
The code is mostly a lot of numbers that indicate which servos are moving at what times to what positions. These numbers are stored in the program memory of the controller so that ram isn’t ever utilized. This move shows it uses 672 bytes to store, or 0.65KB. The Servotor32 for example has 28KB of usable program memory space, so you can store plenty of moves on a Servotor32 without doing any modifications.
If you were to copy the move into the default firmware with some modification, and include the move function in the main loop, you would get something like this. This code runs the move every 5 seconds in a loop:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
#include "Servotor32.h" // call the servotor32 Library Servotor32 hexy; // create a servotor32 object void setup() { hexy.begin(); } void loop() { hexy.delay_ms(5000); // wait 5000mS, or 5s move_hexy(); } #include <avr/pgmspace.h> #define MOVE_HEXY_SIZE 168 const PROGMEM uint16_t move_hexy_time[MOVE_HEXY_SIZE] = { 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 400, 401, 401, 401, 402, 402, 402, 402, 403, 403, 403, 403, 403, 403, 403, 404, 404, 404, 501, 501, 501, 501, 501, 502, 502, 502, 502, 503, 503, 503, 503, 503, 503, 504, 504, 504, 601, 601, 601, 601, 602, 602, 602, 602, 602, 603, 603, 603, 603, 603, 603, 603, 604, 604, 901, 901, 901, 902, 902, 902, 902, 902, 902, 903, 903, 903, 1302, 1302, 1302, 1303, 1303, 1303, 1303, 1303, 1303, 1303, 1304, 1304, 1304, 1304, 1304, 1304, 1304, 1304, 1402, 1402, 1402, 1402, 1402, 1402, 1403, 1403, 1403, 1403, 1403, 1403, 1403, 1403, 1404, 1404, 1404, 1404, 1501, 1501, 1501, 1501, 1501, 1501, 1502, 1502, 1502, 1502, 1502, 1503, 1503, 1503, 1503, 1503, 1503, 1503, 1804, 1805, 1805, 1805, 1806, 1806, 1807, 1808, 1808, 1809, 1811, 1811, 1811, 1811, 1812, 1812, 1813, 1813, 1813, 1814, 1814, 1814, 1814, 1814, 1814, 1815, 1815, 1815, 1815, 1815, 1815, 1815, 1815, 1816, 1816, 1816}; const PROGMEM uint8_t move_hexy_servo[MOVE_HEXY_SIZE] = { 6, 6, 21, 5, 21, 5, 22, 14, 22, 14, 13, 13, 6, 6, 5, 21, 5, 21, 7, 22, 14, 7, 22, 14, 13, 20, 13, 20, 15, 15, 6, 6, 5, 5, 7, 7, 21, 14, 14, 21, 13, 22, 13, 22, 15, 20, 15, 20, 6, 6, 5, 5, 7, 7, 14, 21, 14, 21, 13, 22, 13, 22, 15, 20, 15, 20, 25, 25, 26, 10, 26, 10, 17, 9, 17, 9, 18, 18, 25, 25, 26, 10, 26, 10, 24, 17, 9, 24, 17, 9, 18, 11, 18, 11, 16, 16, 25, 25, 26, 26, 24, 24, 17, 10, 17, 10, 18, 9, 18, 9, 16, 11, 16, 11, 25, 25, 26, 26, 24, 24, 17, 10, 17, 10, 18, 9, 18, 9, 16, 11, 16, 11, 6, 6, 5, 10, 5, 10, 14, 9, 14, 25, 9, 13, 21, 25, 13, 21, 26, 7, 22, 26, 17, 7, 22, 17, 20, 20, 18, 18, 15, 15, 24, 24, 11, 11, 16, 16}; const PROGMEM uint8_t move_hexy_pos[MOVE_HEXY_SIZE] = { 153 , 153 , 146 , 156 , 146 , 56 , 147 , 152 , 47 , 152 , 153 , 53 , 153 , 160 , 56 , 146 , 63 , 205 , 150 , 47 , 152 , 161 , 106 , 159 , 53 , 153 , 60 , 153 , 147 , 136 , 160 , 160 , 63 , 63 , 161 , 172 , 205 , 159 , 159 , 205 , 60 , 106 , 60 , 106 , 136 , 153 , 125 , 153 , 160 , 212 , 63 , 115 , 172 , 183 , 159 , 205 , 211 , 205 , 60 , 106 , 112 , 106 , 125 , 153 , 114 , 153 , 153 , 153 , 153 , 140 , 53 , 140 , 153 , 153 , 153 , 53 , 153 , 53 , 153 , 160 , 53 , 140 , 60 , 199 , 150 , 153 , 53 , 138 , 160 , 112 , 53 , 152 , 60 , 152 , 145 , 156 , 160 , 160 , 60 , 60 , 138 , 127 , 160 , 199 , 160 , 199 , 60 , 112 , 60 , 112 , 156 , 152 , 167 , 152 , 160 , 212 , 60 , 112 , 127 , 116 , 160 , 199 , 212 , 199 , 60 , 112 , 112 , 112 , 167 , 152 , 178 , 152 , 212 , 212 , 115 , 199 , 115 , 199 , 211 , 112 , 211 , 212 , 112 , 112 , 205 , 212 , 112 , 205 , 112 , 183 , 106 , 112 , 212 , 183 , 106 , 212 , 153 , 153 , 112 , 112 , 114 , 114 , 116 , 116 , 152 , 152 , 178 , 178 }; void move_hexy(){ int startTime = hexy.millis_new(); int currentTime = 0; int last_update = 0; for(int i=0; i<MOVE_HEXY_SIZE; i++){ delayMicroseconds(10); currentTime = hexy.millis_new() - startTime; uint16_t move_time = pgm_read_word_near(move_hexy_time + i); while(currentTime < move_time){ delayMicroseconds(10); currentTime = hexy.millis_new() - startTime; } uint8_t servo_time = pgm_read_byte_near(move_hexy_servo + i); uint8_t servo_pos = pgm_read_byte_near(move_hexy_pos + i); hexy.changeServo(servo_time, servo_pos*10); last_update = currentTime; } } //Move Size is 672 bytes //Run this move by using: // move_hexy() |