Autohotkey to Mini Maestro 12

ok… I am trying to create the control of a device in AHK without using the pololu software. NOT because I don’t like the software!! but to eliminate the additional layer of actions to control my device.

As it stands, control of my device is as follows (quite a stack of dominoes):
Motorola Xoom tablet. wireless to…
Belkin N300 protable router. wireless to…
Lenovo Netbook (W7 HP 64b) (sharing desktop back to Xoom) running…
Autohotkey GUI. scripted to perform keyboard macros on…
Pololu Control software. Controlling by USB…
Mini Maestro 12 which operates my creation.

The problem is, while sending keystrokes and values to the Pololu control software is an effective way to accomplish control, I wouldnt mind trimming up my control layers with Autohotkey itself as it seems this is an alternative.

Problem is, UscCmd crashes every time I try to send anything. Is there something I am missing in the interface? I have AHK_L installed and I have Pololu 1.4.0.0 installed. Is there something else I need or need to identify in my script other than simply executing for example:

Gui, Add, Button, x202 y50 w80 h70 , full
Gui, Add, Button, x202 y130 w80 h60 , mid
Gui, Add, Button, x202 y200 w80 h70 , zero
Gui, Add, Button, x302 y50 w80 h70 , fast
Gui, Add, Button, x302 y130 w80 h60 , slow
Gui, Show, x337 y140 h379 w479, New GUI Window
Return

buttonfull:
Gui, Submit
Run usccmd --servo 0`,900,,Hide
Run usccmd --servo 0`,2100,,Hide
Gui, Show,, New GUI Window
return

buttonmid:
Gui, Submit
Run usccmd --servo 0`,1500,,Hide
Run usccmd --servo 0`,2000,,Hide
Run usccmd --servo 0`,1500,,Hide
Run usccmd --servo 0`,2000,,Hide
Gui, Show,, New GUI Window
return

GuiClose:
ExitApp

It moved my servo 1 time, but then after that, everytime I push a button on the GUI, I get ‘UscCmd has stopped working…’

is there something I am missing in my script or in the UscCmd?


Hello.

I expect it is crashing because you have the control center already connected to the Maestro. You can only have the control center OR usccmd connected to it at one time. You also are not using RunWait when you need to. Have you see our application note on using AutoHotkey with Pololu USB devices?

Sounds like an interesting project, please post some pictures or video once you have it working well!

- Ryan

Actually, that is what I am trying Not to do. My UscCmd crashes occur when I try to run AHK independently, without the use of the Control Center.

I read and fully get that thw two programs cannot control the MM12 at the same time. I read the Guidelines which actually fueled the idea to attempt direct MM12 control with AHK as it is a language I am somewhat familiar with.

The setup I have outlined above is actually my ellaborate work around to this. Currently, I run my AHK GUI at the same time as the Control Center, but not so AHK controls the MM12 directly, rather so that my AHK GUI controls the Control Center software by sending a series of keystroke Macros manipulating the Control Center, which in turn manipulates the MM12. This setup works but is inefficient.

I would like to avoid this process by having my AHK send commands directly to the MM12 (like it says in the guideline here). But again, my UscCmd crashes when I try controlling my MM12 with AHK directly.

:question: I am wondering if there is something that I need to put in the AHK script that is required to identify maybe the USB port… The device… or anything in addition to the simple sending of commands in to the computer and hoping it lands on the MM12.

I have many items hooked to my computer via USB and maybe the crash is occurring because the computer is sending commands to all of them…

Ok… RunWait… I guess that was my bad I was using Run like in some of the examples in the guideline…

and my UscCmd has not crashed today… dunno why…

I seem to be getting closer…

but I have a new problem… in my script I have all 5 servos going when I push the B button… but all my servos go to their extreme minimum… not just to 1500. (1500 +/- is their middle value in Control Center)

Button A and Button C don’t do anything… I don’t see a difference in the syntax other than the value given…

is there a difference in the values I give in AHK than those I give in Control Center? ie AHK-1500 = CC-800 or something…

Gui, Add, Button, x202 y50 w80 h70 , A
Gui, Add, Button, x202 y130 w80 h60 , B
Gui, Add, Button, x202 y200 w80 h70 , C
Gui, Add, Button, x302 y50 w80 h70 , fast
Gui, Add, Button, x302 y130 w80 h60 , slow
Gui, Show, x337 y140 h379 w479, New GUI Window
Return

buttonA:
Gui, Submit

RunWait usccmd --servo 1`,900,,Hide
Gui, Show,, New GUI Window
return


buttonB:
Gui, Submit

RunWait usccmd --servo 1`,1500,,Hide
RunWait usccmd --servo 2`,1500,,Hide
RunWait usccmd --servo 3`,1500,,Hide
RunWait usccmd --servo 4`,1500,,Hide
Run usccmd --servo 5`,1500,,Hide
Gui, Show,, New GUI Window
return

buttonC:
Gui, Submit

RunWait usccmd --servo 1`,1000,,Hide
RunWait usccmd --servo 2`,1000,,Hide
RunWait usccmd --servo 3`,1000,,Hide
RunWait usccmd --servo 4`,1000,,Hide
Run usccmd --servo 5`,1000,,Hide
Gui, Show,, New GUI Window
return

GuiClose:
ExitApp

just to be clear, I am looking to push buttons on my GUI, have it send position commands to my MM12 and then return to the GUI, waiting for the next command.

The units of the NUM parameter to the --servo switch are in quarter microseconds, so you should be trying to keep it between 4000 and 8000 for the standard 1-2 ms servo pulse widths. You can see a description of the commands if you just type usccmd with nothing else at the command line.

- Ryan

nope… didn’t see that one coming. (milliseconds) gonna try… I am half way finished with my Keystroke Macro version…

be right back…

WHAMMO!

It works!!

I changed some values per your numbers

Gui, Add, Button, x202 y50 w80 h70 , A
Gui, Add, Button, x202 y130 w80 h60 , B
Gui, Add, Button, x202 y200 w80 h70 , C
Gui, Add, Button, x302 y50 w80 h70 , fast
Gui, Add, Button, x302 y130 w80 h60 , slow
Gui, Show, x337 y140 h379 w479, New GUI Window
Return

buttonA:
Gui, Submit

RunWait usccmd --servo 1`,4000,,Hide
RunWait usccmd --servo 2`,4000,,Hide
RunWait usccmd --servo 3`,4000,,Hide
RunWait usccmd --servo 4`,4000,,Hide
Run usccmd --servo 5`,4000,,Hide
Gui, Show,, New GUI Window
return


buttonB:
Gui, Submit

RunWait usccmd --servo 1`,6000,,Hide
RunWait usccmd --servo 2`,6000,,Hide
RunWait usccmd --servo 3`,6000,,Hide
RunWait usccmd --servo 4`,6000,,Hide
Run usccmd --servo 5`,6000,,Hide
Gui, Show,, New GUI Window
return

buttonC:
Gui, Submit

RunWait usccmd --servo 1`,8000,,Hide
RunWait usccmd --servo 2`,8000,,Hide
RunWait usccmd --servo 3`,8000,,Hide
RunWait usccmd --servo 4`,8000,,Hide
Run usccmd --servo 5`,8000,,Hide
Gui, Show,, New GUI Window
return

GuiClose:
ExitApp

now I just have to reset my min and max values in Control Center to their limits, apply and close… Then re-equate my position values in my actual control script.

So basically my script was working (or at least trying to) but my values were way off as I was using the numbers from Control Center and not the milliseconds you just pointed out… WOW, that is going to cut my script by at least 500 lines… and everything will be instant instead of one servo at a time…

Thanks!!!

I’ll post both scripts when I’m done

WOW did that make my script short!!! :smiley: and faster reaction!!

Well, I have tested it on the bench… now for application…

Use at will… nothing more than servo positioning…

; GUI Generated using SmartGUI Creator 4.0
; WRITTEN BY CTRL+1
; 01 values are start position, 100 percent is 100 percent action
;
; IN config
; 100 is the full OUT position, and 01 is the IN position
;
; OUT config
; 100 is the full IN position, and 01 is the OUT position
; servo 0 unused
; servo 1 Left servos
; servo 2 Half Left servos
; servo 3 Motor
; servo 4 Half Right servos
; servo 5 Right servos
; servo 6 - 11 unused 


;------------------------------vALUES
;Motor Stop  6000
;Motor 25    6500
;Motor 50    7000
;Motor 75    7500
;Motor Full  8000
Gui, Add, Edit, readonly x532 y160 w80 h20 vM100 , 8000
Gui, Add, Edit, readonly x532 y180 w80 h20 vM75 , 7500
Gui, Add, Edit, readonly x532 y200 w80 h20 vM50 , 7000
Gui, Add, Edit, readonly x532 y220 w80 h20 vM25 , 6500
Gui, Add, Edit, readonly x532 y240 w80 h20 vM01 , 6000

;Left half IN  8000
;Left half i25 7500
;Left half i50 7000
;Left half i75 6500
;Left half pos 6000
;Left half o75 5500
;Left half o50 5000
;Left half o25 4500
;Left half OUT 4000
Gui, Add, Edit, readonly x462 y280 w70 h20 vLH100 , 6000
Gui, Add, Edit, readonly x462 y300 w70 h20 vLH75 , 6500
Gui, Add, Edit, readonly x462 y320 w70 h20 vLH50 , 7000
Gui, Add, Edit, readonly x462 y340 w70 h20 vLH25 , 7500
Gui, Add, Edit, readonly x462 y360 w70 h20 vLH01 , 8000

;Right half IN  4000
;Right half i25 4500
;Right half i50 5000
;Right half i75 5500
;Right half pos 6000
;Right half o75 6500
;Right half o50 7000
;Right half o25 7500
;Right half OUT 8000
Gui, Add, Edit, readonly x612 y280 w70 h20 vRH100 , 6000
Gui, Add, Edit, readonly x612 y300 w70 h20 vRH75 , 5500
Gui, Add, Edit, readonly x612 y320 w70 h20 vRH50 , 5000
Gui, Add, Edit, readonly x612 y340 w70 h20 vRH25 , 4500
Gui, Add, Edit, readonly x612 y360 w70 h20 vRH01 , 4000

;Left in  8000
;Left 25  7000
;Left 50  6000
;Left 75  5000
;Left out 4000
Gui, Add, Edit, readonly x462 y160 w70 h20 vLP100 , 4000
Gui, Add, Edit, readonly x462 y180 w70 h20 vLP75 , 5000
Gui, Add, Edit, readonly x462 y200 w70 h20 vLP50 , 6000
Gui, Add, Edit, readonly x462 y220 w70 h20 vLP25 , 7000
Gui, Add, Edit, readonly x462 y240 w70 h20 vLP01 , 8000

;Right in  4000
;Right 25  5000
;Right 50  6000
;Right 75  7000
;Right out 8000
Gui, Add, Edit, readonly x612 y160 w70 h20 vRP100 , 8000
Gui, Add, Edit, readonly x612 y180 w70 h20 vRP75 , 7000
Gui, Add, Edit, readonly x612 y200 w70 h20 vRP50 , 6000
Gui, Add, Edit, readonly x612 y220 w70 h20 vRP25 , 5000
Gui, Add, Edit, readonly x612 y240 w70 h20 vRP01 , 4000


;------------------------------BUTTONS

Gui, Add, Button, x2 y0 w120 h100 , L100
Gui, Add, Button, x2 y100 w120 h100 , L75
Gui, Add, Button, x2 y200 w120 h100 , L50
Gui, Add, Button, x2 y300 w120 h100 , L25
Gui, Add, Button, x2 y400 w120 h100 , L00

Gui, Add, Button, x152 y0 w120 h100 , F100
Gui, Add, Button, x152 y100 w120 h100 , F75
Gui, Add, Button, x152 y200 w120 h100 , F50
Gui, Add, Button, x152 y300 w120 h100 , F25

Gui, Add, Button, x302 y0 w120 h100 , R100
Gui, Add, Button, x302 y100 w120 h100 , R75
Gui, Add, Button, x302 y200 w120 h100 , R50
Gui, Add, Button, x302 y300 w120 h100 , R25
Gui, Add, Button, x302 y400 w120 h100 , R00

Gui, Add, Button, x722 y0 w120 h100 , M100
Gui, Add, Button, x722 y100 w120 h100 , M75
Gui, Add, Button, x722 y200 w120 h100 , M50
Gui, Add, Button, x722 y300 w120 h100 , M25
Gui, Add, Button, x722 y400 w120 h100 , M00

Gui, Add, Button, x462 y0 w220 h140 , CENTER

Gui, Add, Button, x462 y390 w220 h130 , PARK



Gui, Add, Button, x892 y390 w60 h60 , Windows

Gui, Add, Button, x872 y0 w60 h60 , FAST
Gui, Add, Button, x872 y60 w60 h60 , DEFAULT
Gui, Add, Button, x872 y120 w60 h60 , SLOW
Gui, Add, Button, x872 y180 w60 h60 , SLOWEST


;------------------------------TEXT

Gui, Add, Text, x462 y140 w70 h20 +Center, L Pushers
Gui, Add, Text, x462 y260 w70 h20 +Center, L Halfs
Gui, Add, Text, x532 y140 w90 h20 +Center, Motors
Gui, Add, Text, x622 y140 w60 h20 +Center, R Pushers
Gui, Add, Text, x532 y260 w80 h20 +Center, Speed
Gui, Add, Text, x612 y260 w70 h20 +Center, R Halfs



Gui, Show, x399 y131 h534 w950, Rali Control
Return

;------------------------------Speeds
buttonFAST:
Gui, Submit
RunWait usccmd --speed 1`,0,,Hide
RunWait usccmd --speed 2`,0,,Hide
RunWait usccmd --speed 3`,4,,Hide
RunWait usccmd --speed 4`,0,,Hide
Run usccmd --speed 5`,0,,Hide
Gui, Show,, Rali Control
SoundBeep, 750, 500  ; Play a higher pitch for half a second.
return

buttonDEFAULT:
Gui, Submit
RunWait usccmd --speed 1`,4,,Hide
RunWait usccmd --speed 2`,4,,Hide
RunWait usccmd --speed 3`,4,,Hide
RunWait usccmd --speed 4`,4,,Hide
Run usccmd --speed 5`,4,,Hide
SoundBeep, 750, 500  ; Play a higher pitch for half a second.
Gui, Show,, Rali Control
SoundBeep, 750, 500  ; Play a higher pitch for half a second.
return

buttonSLOW:
Gui, Submit
RunWait usccmd --speed 1`,2,,Hide
RunWait usccmd --speed 2`,2,,Hide
RunWait usccmd --speed 3`,4,,Hide
RunWait usccmd --speed 4`,2,,Hide
Run usccmd --speed 5`,2,,Hide
Gui, Show,, Rali Control
SoundBeep, 750, 500  ; Play a higher pitch for half a second.
return

buttonSLOWEST:
Gui, Submit
RunWait usccmd --speed 1`,1,,Hide
RunWait usccmd --speed 2`,1,,Hide
RunWait usccmd --speed 3`,4,,Hide
RunWait usccmd --speed 4`,1,,Hide
Run usccmd --speed 5`,1,,Hide
Gui, Show,, Rali Control
SoundBeep, 750, 500  ; Play a higher pitch for half a second.
return

;------------------------------movements
; 1 Left, 2 Half Left, 4 Half Right, 5 Right
;------------------LEFTS
buttonL00:
Gui, Submit
RunWait usccmd --servo 1`,%LP01%,,Hide
Run usccmd --servo 2`,%LH01%,,Hide
Gui, Show,, Rali Control
SoundBeep, 750, 500  ; Play a higher pitch for half a second.
return

buttonL25:
Gui, Submit
RunWait usccmd --servo 1`,%LP25%,,Hide
Run usccmd --servo 2`,%LH25%,,Hide
Gui, Show,, Rali Control
SoundBeep, 750, 500  ; Play a higher pitch for half a second.
return

buttonL50:
Gui, Submit
RunWait usccmd --servo 1`,%LP50%,,Hide
Run usccmd --servo 2`,%LH50%,,Hide
Gui, Show,, Rali Control
SoundBeep, 750, 500  ; Play a higher pitch for half a second.
return

buttonL75:
Gui, Submit
RunWait usccmd --servo 1`,%LP75%,,Hide
Run usccmd --servo 2`,%LH75%,,Hide
Gui, Show,, Rali Control
SoundBeep, 750, 500  ; Play a higher pitch for half a second.
return

buttonL100:
Gui, Submit
RunWait usccmd --servo 1`,%LP100%,,Hide
Run usccmd --servo 2`,%LPH00%,,Hide
Gui, Show,, Rali Control
SoundBeep, 750, 500  ; Play a higher pitch for half a second.
sleep 500
SoundBeep, 750, 500  ; Play a higher pitch for half a second.
return

; 1 Left, 2 Half Left, 4 Half Right, 5 Right
;------------------RIGHTS
buttonR00:
Gui, Submit
RunWait usccmd --servo 5`,%RP01%,,Hide
Run usccmd --servo 4`,%RH01%,,Hide
Gui, Show,, Rali Control
SoundBeep, 750, 500  ; Play a higher pitch for half a second.
return

buttonR25:
Gui, Submit
RunWait usccmd --servo 5`,%RP25%,,Hide
Run usccmd --servo 4`,%RH25%,,Hide
Gui, Show,, Rali Control
SoundBeep, 750, 500  ; Play a higher pitch for half a second.
return

buttonR50:
Gui, Submit
RunWait usccmd --servo 5`,%RP50%,,Hide
Run usccmd --servo 4`,%RH50%,,Hide
Gui, Show,, Rali Control
SoundBeep, 750, 500  ; Play a higher pitch for half a second.
return

buttonR75:
Gui, Submit
RunWait usccmd --servo 5`,%RP75%,,Hide
Run usccmd --servo 4`,%RH75%,,Hide
Gui, Show,, Rali Control
SoundBeep, 750, 500  ; Play a higher pitch for half a second.
return

buttonR100:
Gui, Submit
RunWait usccmd --servo 5`,%RP100%,,Hide
Run usccmd --servo 4`,%RH100%,,Hide
Gui, Show,, Rali Control
SoundBeep, 750, 500  ; Play a higher pitch for half a second.
sleep 500
SoundBeep, 750, 500  ; Play a higher pitch for half a second.
return

; 1 Left, 2 Half Left, 4 Half Right, 5 Right
;------------------forwards

buttonF25:
Gui, Submit
RunWait usccmd --servo 1`,%LP25%,,Hide
RunWait usccmd --servo 5`,%RP25%,,Hide
RunWait usccmd --servo 2`,%LH25%,,Hide
Run usccmd --servo 4`,%RH25%,,Hide
Gui, Show,, Rali Control
SoundBeep, 750, 500  ; Play a higher pitch for half a second.
return

buttonF50:
Gui, Submit
RunWait usccmd --servo 1`,%LP50%,,Hide
RunWait usccmd --servo 5`,%RP50%,,Hide
RunWait usccmd --servo 2`,%LH50%,,Hide
Run usccmd --servo 4`,%RH50%,,Hide
Gui, Show,, Rali Control
SoundBeep, 750, 500  ; Play a higher pitch for half a second.
return

buttonF75:
Gui, Submit
RunWait usccmd --servo 1`,%LP75%,,Hide
RunWait usccmd --servo 5`,%RP75%,,Hide
RunWait usccmd --servo 2`,%LH75%,,Hide
Run usccmd --servo 4`,%RH75%,,Hide
Gui, Show,, Rali Control
SoundBeep, 750, 500  ; Play a higher pitch for half a second.
return

buttonF100:
Gui, Submit
RunWait usccmd --servo 1`,%LP100%,,Hide
RunWait usccmd --servo 5`,%RP100%,,Hide
RunWait usccmd --servo 2`,%LH100%,,Hide
Run usccmd --servo 4`,%RH100%,,Hide
Gui, Show,, Rali Control
SoundBeep, 750, 500  ; Play a higher pitch for half a second.
sleep 500
SoundBeep, 750, 500  ; Play a higher pitch for half a second.
return

;------------------------------CENTER
buttonCENTER:
Gui, Submit
RunWait usccmd --servo 1`,%LP01%,,Hide
RunWait usccmd --servo 5`,%RP01%,,Hide
RunWait usccmd --servo 2`,%LH01%,,Hide
Run usccmd --servo 4`,%RH01%,,Hide
Gui, Show,, Rali Control
SoundBeep, 750, 500  ; Play a higher pitch for half a second.
sleep 500
SoundBeep, 750, 500  ; Play a higher pitch for half a second.
return

;------------------------------PARK
buttonPARK:
Gui, Submit
RunWait usccmd --speed 3`,0,,Hide
RunWait usccmd --servo 3`,%M01%,,Hide
RunWait usccmd --servo 1`,%LP01%,,Hide
RunWait usccmd --servo 5`,%RP01%,,Hide
RunWait usccmd --servo 2`,%LH01%,,Hide
RunWait usccmd --servo 4`,%RH01%,,Hide
sleep 1000
Run usccmd --speed 3`,4,,Hide
Gui, Show,, Rali Control
SoundBeep, 750, 500  ; Play a higher pitch for half a second.
sleep 500
SoundBeep, 750, 500  ; Play a higher pitch for half a second.
sleep 500
SoundBeep, 750, 500  ; Play a higher pitch for half a second.
return

;------------------------------Motor Speeds

buttonM00:
Gui, Submit
RunWait usccmd --servo 3`,%M01%,,Hide
sleep 500
Run usccmd --servo 3`,%M01%,,Hide
Gui, Show,, Rali Control
SoundBeep, 750, 500  ; Play a higher pitch for half a second.
sleep 500
SoundBeep, 750, 500  ; Play a higher pitch for half a second.
return

buttonM25:
Gui, Submit
RunWait usccmd --servo 3`,%M25%,,Hide
sleep 500
Run usccmd --servo 3`,%M25%,,Hide
Gui, Show,, Rali Control
SoundBeep, 750, 500  ; Play a higher pitch for half a second.
return

buttonM50:
Gui, Submit
RunWait usccmd --servo 3`,%M50%,,Hide
sleep 500
Run usccmd --servo 3`,%M50%,,Hide
Gui, Show,, Rali Control
SoundBeep, 750, 500  ; Play a higher pitch for half a second.
return

buttonM75:
Gui, Submit
RunWait usccmd --servo 3`,%M75%,,Hide
sleep 500
Run usccmd --servo 3`,%M75%,,Hide
Gui, Show,, Rali Control
SoundBeep, 750, 500  ; Play a higher pitch for half a second.
return

buttonM100:
Gui, Submit
RunWait usccmd --servo 3`,%M100%,,Hide
sleep 500
Run usccmd --servo 3`,%M100%,,Hide
Gui, Show,, Rali Control
SoundBeep, 750, 500  ; Play a higher pitch for half a second.
return

buttonWindows:
send {LWin}
return



GuiClose:
ExitApp

Thanks again Ryan!! :wink:

I’m glad you got it working! We’d be interested in seeing any pictures/screenshots/videos of your project in action!

- Ryan