Send script from arduino to Maestro

Hello, i hope somebody give me at least a guide or adivce for doing this.:unamused: :unamused:

im building and hexapod.
what i want to do is:

create forward, backward motion etc… using maestro control center because its easier to position the servos exactly where you want.

then copy the forward… sequence to Script.

and here is where arduino comes.

i wonder if there is way i can send the whole script to the pololu board using serial comunicaction or another way you know?.

THIS IS SOMETHING DIFFERENT I COULD DO ALSO

I have been reading that is posible to for example: save the script to the board using maestro software, then from arduino send the stop script or restart script command using serial comunication.;

but i see the command expects a rutine parameter , is there a way to start the whole sequence?

i could do 4 sequences for motion in all directions and then from arduino call the sequence depending on what the user inputs.

Thanks!! hope you could help me out with this!. :neutral_face: :neutral_face:

Hello.

There is no way to load a script onto the Maestro from an Arduino; however, there are a couple of other options that you might consider. You could translate your sequences into serial commands in your Arduino sketch and have the sequences handled by the Arduino. You can find a list of Maestro serial commands for servos in the “Serial Servo Commands” section of the Maestro controller’s user’s guide.

Alternatively, you could make your four sequences using the “Sequence” tab of the Maestro Control Center and use the “Copy All Sequences to Script” button. Then you can use the “Restart Script at Subroutine” serial command to trigger the subroutines using your Arduino. Please note that you might need to edit the script slightly since the subroutines will end with a return statement by default (simply changing the return to quit or repeat might work depending on the behavior you want. Information about this command can be found in the Serial Script Commands" section of the Maestro controller’s user’s guide.

If you try this and run into problems, you could post what you have so far, and I would be happy to take a look.

-Brandon

Thanks for answering!. :wink: :wink:

Yep i have already done this , but this would be like my last option.

This is what im doing right now.

I create the sequence for forward motion—> generate the script and save it to .txt(for later edition)

Then with all the sequences done, i put them all together in one script.

I just add sub forward where it says begins - quit and APPLY SETTINGS ON THE MAESTRO CONTROL CENTER

Then i look at the compiled code and see the address of my sequence and call it from arduino and to my surprise it worked at the first try. But sequence repeats and repeats and never stops(i suppose its because of the repeat before quit, havent try removing it yet, cuz i want it like that).

So in my control app, i designed another button for stopping the hexapod, but it doesnt work, i dont know why. :unamused: :unamused:

Here is the script(only has forward and left sequences)

sub left
begin
  500 8000 3968 8000 3968 0 0 
  0 0 0 0 0 0 
  0 0 0 0 0 0 
  0 0 0 0 0 0 frame_0..88 # Frame 0
  500 3968 7980 3968 8000 frame_0..3 # Frame 1
  500 5945 5964 frame_0_3 # Frame 2
  500 5964 5945 frame_1_2 # Frame 3
  500 8000 frame_0 # Frame 4
  500 3968 frame_1 # Frame 5
  500 8000 frame_2 # Frame 6
  500 3968 frame_3 # Frame 7
  500 3968 0 0 0 frame_0..3 # Frame 8
  500 10816 frame_0 # Frame 9
  500 3968 frame_0 # Frame 10
  500 10816 frame_0 # Frame 11
  500 3968 frame_0 # Frame 12
  repeat
quit



sub fordward
begin
  500 7631 0 0 4394 0 0 
  5730 0 0 4413 0 0 
  5441 0 0 6584 0 0 
  0 0 0 0 0 0 frame_0..23 # Frame 0
  500 2176 9095 2315 9408 2245 9164 frame_1_4_7_10_13_16 # Frame 1
  500 2315 9234 3253 8712 2523 8956 frame_2_5_8_11_14_17 # Frame 2
  500 3601 7878 4609 7287 3984 7843 frame_2_5_8_11_14_17 # Frame 3
  500 5722 4888 5770 6209 5757 6139 
  5061 frame_1_4_6_7_10_13_16 # Frame 4
  500 4814 3641 6557 5339 frame_1_2_10_13 # Frame 5
  500 8431 3613 6241 frame_0_9_12 # Frame 6
  500 5614 5757 6139 frame_1_10_13 # Frame 7
  500 5688 5409 5861 frame_4_7_16 # Frame 9
  500 7631 4413 5441 frame_0_9_12 # Frame 10
  500 3594 6570 5784 frame_3_6_15 # Frame 11
  500 4888 6209 5061 frame_4_7_16 # Frame 12
  500 4814 6557 5339 frame_1_10_13 # Frame 13
  500 4394 5770 6584 frame_3_6_15 # Frame 14
repeat
quit

sub frame_0..23
  23 servo
  22 servo
  21 servo
  20 servo
  19 servo
  18 servo
  17 servo
  16 servo
  15 servo
  14 servo
  13 servo
  12 servo
  11 servo
  10 servo
  9 servo
  8 servo
  7 servo
  6 servo
  5 servo
  4 servo
  3 servo
  2 servo
  1 servo
  0 servo
  delay
  return

sub frame_1_4_7_10_13_16
  16 servo
  13 servo
  10 servo
  7 servo
  4 servo
  1 servo
  delay
  return

sub frame_2_5_8_11_14_17
  17 servo
  14 servo
  11 servo
  8 servo
  5 servo
  2 servo
  delay
  return

sub frame_1_4_6_7_10_13_16
  16 servo
  13 servo
  10 servo
  7 servo
  6 servo
  4 servo
  1 servo
  delay
  return

sub frame_1_2_10_13
  13 servo
  10 servo
  2 servo
  1 servo
  delay
  return

sub frame_0_9_12
  12 servo
  9 servo
  0 servo
  delay
  return

sub frame_1_10_13
  13 servo
  10 servo
  1 servo
  delay
  return

sub frame_4_7_16
  16 servo
  7 servo
  4 servo
  delay
  return

sub frame_3_6_15
  15 servo
  6 servo
  3 servo
  delay
  return



sub frame_0..88
  23 servo
  22 servo
  21 servo
  20 servo
  19 servo
  18 servo
  17 servo
  16 servo
  15 servo
  14 servo
  13 servo
  12 servo
  11 servo
  10 servo
  9 servo
  8 servo
  7 servo
  6 servo
  5 servo
  4 servo
  3 servo
  2 servo
  1 servo
  0 servo
  delay
  return

sub frame_0..3
  3 servo
  2 servo
  1 servo
  0 servo
  delay
  return

sub frame_0_3
  3 servo
  0 servo
  delay
  return

sub frame_1_2
  2 servo
  1 servo
  delay
  return

sub frame_0
  0 servo
  delay
  return

sub frame_1
  1 servo
  delay
  return

sub frame_2
  2 servo
  delay
  return

sub frame_3
  3 servo
  delay
  return

And here its my arduino code, when bluedat==‘4’… I call stop_script function, but nothing happens , hexapod keeps walking…

#include <SoftwareSerial.h>


SoftwareSerial myserial(10,11);

int bluedat;


void setup(){

myserial.begin(9600);
Serial.begin(57600);
myserial.print("Bluetooth ON");


}

void loop(){

  if(myserial.available()){
  
  bluedat = myserial.read();
  

if(bluedat=='0'){
     Serial.print("Adelante");
     start_script(0x00);
 
  }

  if(bluedat=='1'){
   Serial.print("Atras");
   start_script(0x01);

  }
  

  if(bluedat=='2'){

  Serial.print("Derecha");
  
  
  }
  
  if(bluedat=='3'){
   Serial.print('Izquierda'); 
   
   
  }
  
  
    if(bluedat=='4'){
  
    stop_script();
  
  }
  
  }
delay(100);


}


void set_target(unsigned char servo, unsigned int target)
{
 // target = map(target, 0, 180, 2400, 9500);
  myserial.write(0xAA); //start byte
  myserial.write(0x0C) ; //device id
  myserial.write(0x04); //command number
  myserial.write(servo); //servo number
  myserial.write(target & 0x7F);
  myserial.write((target >> 7) & 0x7F);
}

void start_script(unsigned int script){
 myserial.write(0XAA);
  myserial.write(0x0C);
  myserial.write(0x27);
  myserial.write(script);
  
  }
  
  
  void stop_script(){
   
   
   myserial.write(0xAA); 
   myserial.write(0x0C); 
   myserial.write(0x24); 
   
  }

I did not see anything obviously wrong with your code, so I tried modifying it slightly so I could use the Arduino Serial Monitor to set the bluedat variable, and it seems to be working correctly for me. I can send 0 or 1 and it will run the respective subroutine in a loop until I send 4, which stops the script. From your code, it looks like you are using some kind of Bluetooth module to send signals to the Arduino. You might try simplifying your system so you can be sure your commands are working properly before adding in extra devices.

-Brandon

To be honest i dont know what happened , but the hexapod is working perfect now and stop buttong is doing its job. Anyways thanks for your help!. :mrgreen: :mrgreen: