Hi everyone, this is my first post although I have been using this forum as a resource for a little while now. I only have experience with small projects using the Mini Maestro 6 and the scripts are usually very simple. As usual I have used bits and pieces from different post on this forum to create my script, and that usually works, but this time I am having trouble proofing it because of my lack of scripting/programming skills. I could really use a little help if anyone wants to give it a shot ![]()
Here is the basic layou of my project. I have constructed a simple robot that uses two Invacare wheelchair motors driven by Talon SR speed controllers that receive servo signals from the Mini Maestro 6 which is connected to a small netbook running Autohotkey which is in turn receiving keystrokes from another laptop over VNC on my home wifi network. - Whew! That was a mouthful
I have successfully tested the robot using a simple RC transmitter and receiver to control the Talons instead of the Maestro and everything worked fine. I want to control the robot over wifi and eventually through a mobile hotspot using VPN to connect the two laptops, but first I need to get this script working correctly. I keep getting “USCCmd has stopped working” whether I am controlling the robot directly from the onboard netbook or the remote laptop, and if I had to guess I have an obvious script error. I only have Autohotkey running and the Maestro control center is not running, but I still get the error. It happens almost randomly, but especially when I make quick changes in direction. What I would like to achieve is simple forward, reverse, left spin, right spin using the WASD keys. So in my script you will see an attempt to make both motors drive forward when the “W” key is depressed and held, “S” as reverse, and “A” and “D” as left spin right spin, which will require one motor to go forward and the other to reverse.
Here is my novice script:
;Servo control script1
;Use this script to control servos via the keyboard using a Micro Maestro
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
w:: ;key pressed
if (!key_down) ;a toggle so that it doesn't keep repeating
{
key_down := true
RunWait usccmd --accel 0`,0,,Hide
RunWait usccmd --speed 0`,0,,Hide
Run usccmd --servo 1`,5400,,Hide
Run usccmd --servo 0`,5400,,Hide
}
return
w Up:: ;key released
{
key_down := false
RunWait usccmd --accel 0`,0,,Hide
RunWait usccmd --speed 0`,0,,Hide
Run usccmd --servo 1`,6000,,Hide
Run usccmd --servo 0`,6000,,Hide
}
return
s:: ;key pressed
if (!key_down) ;a toggle so that it doesn't keep repeating
{
key_down := true
RunWait usccmd --accel 0`,0,,Hide
RunWait usccmd --speed 0`,0,,Hide
Run usccmd --servo 1`,6600,,Hide
Run usccmd --servo 0`,6600,,Hide
}
return
s Up:: ;key released
{
key_down := false
RunWait usccmd --accel 0`,0,,Hide
RunWait usccmd --speed 0`,0,,Hide
Run usccmd --servo 1`,6000,,Hide
Run usccmd --servo 0`,6000,,Hide
}
return
d:: ;key pressed
if (!key_down) ;a toggle so that it doesn't keep repeating
{
key_down := true
RunWait usccmd --accel 0`,0,,Hide
RunWait usccmd --speed 0`,0,,Hide
Run usccmd --servo 1`,6600,,Hide
Run usccmd --servo 0`,5400,,Hide
}
return
d Up:: ;key released
{
key_down := false
RunWait usccmd --accel 0`,0,,Hide
RunWait usccmd --speed 0`,0,,Hide
Run usccmd --servo 1`,6000,,Hide
Run usccmd --servo 0`,6000,,Hide
}
return
a:: ;key pressed
if (!key_down) ;a toggle so that it doesn't keep repeating
{
key_down := true
RunWait usccmd --accel 0`,0,,Hide
RunWait usccmd --speed 0`,0,,Hide
Run usccmd --servo 1`,5400,,Hide
Run usccmd --servo 0`,6600,,Hide
}
return
a Up:: ;key released
{
key_down := false
RunWait usccmd --accel 0`,0,,Hide
RunWait usccmd --speed 0`,0,,Hide
Run usccmd --servo 1`,6000,,Hide
Run usccmd --servo 0`,6000,,Hide
}
return
q:: ;key pressed
if (!key_down) ;a toggle so that it doesn't keep repeating
{
key_down := true
RunWait usccmd --accel 0`,0,,Hide
RunWait usccmd --speed 0`,0,,Hide
Run usccmd --servo 1`,6000,,Hide
Run usccmd --servo 0`,5400,,Hide
}
return
q Up:: ;key released
{
key_down := false
RunWait usccmd --accel 0`,0,,Hide
RunWait usccmd --speed 0`,0,,Hide
Run usccmd --servo 1`,6000,,Hide
Run usccmd --servo 0`,6000,,Hide
}
return
e:: ;key pressed
if (!key_down) ;a toggle so that it doesn't keep repeating
{
key_down := true
RunWait usccmd --accel 0`,0,,Hide
RunWait usccmd --speed 0`,0,,Hide
Run usccmd --servo 1`,5400,,Hide
Run usccmd --servo 0`,6000,,Hide
}
return
e Up:: ;key released
{
key_down := false
RunWait usccmd --accel 0`,0,,Hide
RunWait usccmd --speed 0`,0,,Hide
Run usccmd --servo 1`,6000,,Hide
Run usccmd --servo 0`,6000,,Hide
}
return
Here are a couple of images of the Robot in one of its configurations:



I tried a few other things, but ultimately I am coming to the conclusion that this is probably not the best method for controlling this robot. It would seem that synced motor operation and reliable a start and stop is not as easy to script as I originally anticipated.
How would I script the ability to run one sequence such as forward, but then allow for left or right to be added while still running the forward sequence?
Could this be accomplished using an if/else statement that listens for all repeated commands and runs the “stop” sequence when no commands are being received?