Pages: [1]   Go Down
Author Topic: Mini Maestro + Arduino Multiple Inputs  (Read 458 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am working on an animatronic project that will have around 10 switches (buttons) and, eventually, 3 Parallax PIR sensors as inputs.  I have all the sensors hooked to the Arduino Mega 2560 which then sends commands to the Mini Maestro.  Currently, my program allows me to press any of these buttons and a series of commands and delays are sent to the Meastro to perform an animation with the servos (Currently there are 10 but there will be 20 servos).

The problem is that I would like for the buttons to interrupt an animation that is currently running to start a new animation instead of having to wait for the current animation to end.

Also, is it possible to perform a command in the background that is always running (breathing). I have not tried this but is there a way to run internal scripting in the Maestro while also receiving serial commands? I have read a little about interrupts but there are a limited number of interrupt ports.  However, this may still be the way to go.

I am looking for a direction to head with re-structuring my logic in the code so I do not waste time wondering about. Are interrupts the best way to go about this? 

Thanks
Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What is 'Mini Maestro'? How is your system working currently? It's not clear what functions the Arduino performs. It can certainly do the sort of thing you're describing if the control logic runs on the Arduino, but I have no idea whether it currently does.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Ayer, Massachusetts, USA
Offline Offline
Edison Member
*
Karma: 54
Posts: 1857
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What is 'Mini Maestro'? How is your system working currently? It's not clear what functions the Arduino performs. It can certainly do the sort of thing you're describing if the control logic runs on the Arduino, but I have no idea whether it currently does.
Mini-maestro is a servo controller made by Pololu: http://www.pololu.com/catalog/category/12

I would imagine if the OP is using the scriptting language interface, that in that script, you would have to have the ability of a signal to kill the current program.

If the OP is controlling the mini maestro from the Arduino, it likely has hard coded delays in the code.  The OP will then need to recode his/her program so that it doesn't have delays, but instead maintains a work queue of when to turn things on or off using a state machine.  The blink without delay example shows how to do this, but I tend to think that blink without delay probably doesn't help people getting to the next step of using a time based state machine.
Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If the OP is controlling the mini maestro from the Arduino, it likely has hard coded delays in the code.  The OP will then need to recode his/her program so that it doesn't have delays, but instead maintains a work queue of when to turn things on or off using a state machine.  The blink without delay example shows how to do this, but I tend to think that blink without delay probably doesn't help people getting to the next step of using a time based state machine.

That does seem to be what the OP is doing, and the approach you're suggesting seems sensible.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What is 'Mini Maestro'? How is your system working currently? It's not clear what functions the Arduino performs. It can certainly do the sort of thing you're describing if the control logic runs on the Arduino, but I have no idea whether it currently does.
Mini-maestro is a servo controller made by Pololu: http://www.pololu.com/catalog/category/12

I would imagine if the OP is using the scriptting language interface, that in that script, you would have to have the ability of a signal to kill the current program.

If the OP is controlling the mini maestro from the Arduino, it likely has hard coded delays in the code.  The OP will then need to recode his/her program so that it doesn't have delays, but instead maintains a work queue of when to turn things on or off using a state machine.  The blink without delay example shows how to do this, but I tend to think that blink without delay probably doesn't help people getting to the next step of using a time based state machine.

Yes, I am sending serial commands to the Maestro from the Arduino.  Here is a simplified example of what I am doing:

Code:
int button1 = 22; //the pin where the first switch is connected
int button2 = 23; 
int button3 = 24;
int button4 = 25;
int button5 = 26;

void setup() {
   //initialize the button pin as an input
   pinMode(button1, INPUT);
   pinMode(button2, INPUT);
   pinMode(button3, INPUT);
   pinMode(button4, INPUT);
   pinMode(button5, INPUT);
   
   // initialize serial communication:
   Serial1.begin(9600);
 }


void loop() {

  //read the pushbotton input pin
  digitalRead(button1);
  digitalRead(button2);
  digitalRead(button3);
  digitalRead(button4);
  digitalRead(button5);
 
    if (button1 == HIGH)  {
      //if the current state is HIGH then the button went from off to on
      Serial1.println("on");
   
      acceleration_headlift();   
      headlift_minimum();
     
      delay(1000);
     
      headlift_maximum();
     
      delay(5000);
     
      headlift_minimum();
     
      delay(1000);
   
   
     } 
     else {

     }
  }



The headlift and acceleration commands are just a set of numbers sent to the Meastro using Serial.write using voids...  I looked at the blink without delay led example and I see how it can take the place of delays.  Will this method allow for me to change the time between the functions that different buttons command?  Is a time based state machine the same as a finite state machine?  I will have to read more on the state machines over the weekend but they sound interesting.

Basically what is happening is I have a creature that looks around until he is "poked" (button is pressed) on the left or right side and he looks that direction.  So the looking around needs to be interrupted when poked and the poked needs to be interrupted if poked in another location.
Logged

Pages: [1]   Go Up
Jump to: