Coding .help

ive been trying to get the script wrote for a project im working on. im building a iron man suit with a motorized face. i have tried to write one but it hasnt worked.

[code]0000: 063D00 – goto main_loop
0003: – sub button
0003: 02002E01F40128 – 0 get_position 500 less_than
000A: 05 – return
000B: –
000B: – sub wait_for_button
000B: 83 – wait_for_button_closed_10ms
000C: 05 – return
000D: – sub wait_for_button_press_10ms
000D: 09 – get_ms
000E: – begin
000E: 80 – button
000F: 071700 – if
0012: 0B09 – drop get_ms
0014: 062200 – else
0017: 090D1D020A29 – get_ms over minus 10 greater_than
001D: 0722000B05 – if drop return endif
0022: – endif
0022: 060E00 – repeat
0025: –
0025: – sub wait_for_button_closed_10ms
0025: 09 – get_ms
0026: – begin
0026: 80 – button
0027: 073800 – if
002A: 090D1D020A29 – get_ms over minus 10 greater_than
0030: 0735000B05 – if drop return endif
0035: 063A00 – else
0038: 0B09 – drop get_ms
003A: – endif
003A: 062600 – repeat
003D: – main_loop:
003D: – begin
003D: 840200 – frame 0
0040: 840201 – frame 1
0043: 063D00 – repeat
0046: –
0046: – sub frame
0046: 81 – wait_for_button
0047: 02012A – 1 servo
004A: 05 – return
004B: –

Subroutines:
Hex Decimal Address Name
00 000 0003 BUTTON
01 001 000B WAIT_FOR_BUTTON
02 002 000D WAIT_FOR_BUTTON_PRESS_10MS
03 003 0025 WAIT_FOR_BUTTON_CLOSED_10MS
04 004 0046 FRAME[/code]
any help from anyone

Hello.

You did not make it clear which controller you are using, but from the code you posted, it looks like you are using a Maestro servo controller.

I tried loading your code onto my Maestro, and it gives me a stack underflow error. I recommend using the “Step Script” button to go through your code to figure out at what point your script needs more values on the stack. You can see the number of values from the stack that each command consumes in the “Command Reference” section of the Maestro user’s guide.

- Amanda

yes i am using the 6 channel Maestro controler. im very new at writing script

how do i fix a stack overflow error

Hello.

It looks like you are using the SERVO command with only one argument; the SERVO command takes two arguments from the stack: position and servo channel number. In your code, you have the channel number specified, but not the servo position. For example, the command to send the servo on channel 1 to a position of 1500 microseconds (or 6000 quarter microseconds) should look something like 6000 1 servo. What is happening in your code right now, is that it tries to take the top two values from the stack when it calls the SERVO command, but it runs out of values, resulting in the stack underflow error. If you try to fix your script and still cannot get the desired behavior, could you post your updated script and describe the behavior you want (e.g. I want servo 1 to move to a target position of 6000 and servo 2 to move to a target position of 4000 when the button is pressed)?

-Brandon

is there a way you could write a script off mine to show what im doing wrong.

I have modified the code that you posted, but please note that since I do not know the specifics of your system (e.g. what positions you want to move the servo to or how many servos you are using), I chose arbitrary positions to move a single servo as an example. Leaving the rest of the code untouched, the code below are the only lines I modified:

main_loop:
begin
  4500 frame  #The number before "frame" is the target position (in quarter microseconds) for the servo on channel 1
  7500 frame  #This gives the servo a second position for when the button is pushed again
repeat

sub frame 
  wait_for_button
  1 servo
  wait_for_button_press_10ms  #This line makes it so holding the button only counts as one press instead of looping
return

With these changes, the code should move a servo from one arbitrary position to another (4500 to 7500, or 1125 us to 1875 us), waiting for the button to be pressed in between movements. The only three lines I made changes to are the ones with comments next to them. Please note that I added the call to the wait_for_button_press_10ms subroutine after moving the servo to make the code wait for the button to be released before looking moving on and checking if the button is pressed again. Without this line, the servo will continuously loop between the two positions when the button is held down.

-Brandon

thanks ill try this will let you know, thanks alot

and i would just put what you tryed in where main loop is?

i got it, thanks so much now one more. i want to add leds into the mix. i want it so that when the servo is at position 1 it turns the leds on and when at two it they are off.? any ideas?

You should be able to turn basic LEDs on and off with the Maestro. If your LEDs draw less than what the Maestro is able to output (up to 30mA), you could configure a channel to be an output and send high or low signals to turn your LEDs on and off. You will need to add code in your script to toggle the value sent to that channel after moving your servo. Also, make sure you use a current limiting resistor in series with your LED.

If your LEDs are rated to take more than 30mA, you should use a MOSFET connected to the Maestro’s channel to turn your LEDs on and off. You can probably find plenty of guides online for controlling an LED with a MOSFET.

- Amanda

would i wire up the leds just like a servo is. using only the two outer pegs on the board?
and would i act like the leds are like servos when addding them into my script?
thanks

and also i was looking at having a switch in the bottom of the suit and my mistro in the helmate of my suit. would i be able to use a set of Wixel to do so?

You can connect the LED using the GND and signal pins of a Maestro channel, but you will need to connect a resistor between the signal pin and the anode of the LED for protection. You can find more information (in detail) about connecting and controlling an LED in the “Attaching Servos and Peripherals” section of the Maestro user’s guide. In your script, you can use the same “Set Target” command used for controlling servos, to control your LEDs on and off.

You could use a pair of Wixels to set up a wireless link from the switch to your Maestro. You can probably use the Wixel’s I/O Repeater App to do that. Information about this app can be found in the Wixel user’s guide under the Resources tab of its product page.

- Amanda

[code]goto main_loop
sub button
0 get_position 500 less_than
return
sub wait_for_button
wait_for_button_closed_10ms
return
sub wait_for_button_press_10ms
get_ms
begin
button
if
drop get_ms
else
get_ms over minus 10 greater_than
if drop return endif
endif
repeat

sub wait_for_button_closed_10ms
get_ms
begin
button
if
get_ms over minus 10 greater_than
if drop return endif
else
drop get_ms
endif
repeat
main_loop:
begin
1 2500 frame
1 20000 frame
repeat
begin
6000 frame
2000 frame
repeat
sub frame
wait_for_button
1 servo
wait_for_button_press_10ms #This line makes it so holding the button only counts as one press instead of looping
return[/code]

this is what i have sofar. and my leds are not turning on. what am i doing wrong??

I tested your code with a similar setup (using a button and an LED with a Maestro), and it worked. Specifically, I followed the setup for connecting those two peripherals to the Maestro as described in the “Attaching Servos and Peripherals” section of the Maestro user’s guide. I see a few things that could be the issue: improper channel settings, insufficient or no power supplied to peripherals (button and LED), and incorrect connections.

  1. Can you verify that your button is connected on channel 0, and channel 0’s mode is set to “Input” under the “Channel Settings” tab of the Maestro Control Center?

  2. If you have a multimeter available, could you measure the voltage for both peripherals (button and LED) to see if they are powered?

  3. Can you post pictures of your setup that show all your connections?

By the way, while testing you code, I encountered an overflow error. It looks like in your first begin repeat code block an extra value (1) is added to the stack before calling your frame subroutine, and it is not consumed during the runtime of your script. The extra value keeps adding to the stack with each button press, resulting in the stack overflow error. I recommend removing those extra 1’s in that code block.

- Amanda

channel 0 i have a switch that is working properly. channel 2 i have a servo with is working properly and channel 3 i have a set of leds that when using the sliders in the minus after 1500 they turn on and under 1500 they turn off. but when i run the script i have now the server goes to positon one. then button is hit and goes to position two and repeats every button hit, with is what i want. but when the servo goes to postion two i want the leds off. if this helps out any.
thanks
Marcus

Hi, Marcus.

Thank you for explaining your setup in detail. To turn off your LEDs, you would need to configure channel 3 to be in “Output” mode and set the target for that channel to a value less than 6000. For example:

7000 1 servo      # Send servo to position value 7000
2000 3 servo      # Send 2000 to output channel 3 to turn off LEDs

By the way, I just noticed that your code is trying to send your a target position of 20,000, which might be fine, but there is a possibility of damaging your servo by extending it beyond its range. You could probably reduce it to 8000 (which corresponds to a 2ms signal).

- Amanda

i had to put the range to 20,000 due to needing 180 degrees of rotation.
ill try and add to the script, and will let you know.
thanks
marcus

goto main_loop sub button 0 get_position 500 less_than return sub wait_for_button wait_for_button_closed_10ms return sub wait_for_button_press_10ms get_ms begin button if drop get_ms else get_ms over minus 10 greater_than if drop return endif endif repeat sub wait_for_button_closed_10ms get_ms begin button if get_ms over minus 10 greater_than if drop return endif else drop get_ms endif repeat main_loop: begin 4460 1 servo 7616 1 servo 7000 2 servo 2000 2 servo repeat sub frame wait_for_button 1 servo 2 servo wait_for_button_press_10ms return

help now my servo is going crazy and my leds are staying on… and i changed my servo locations