Ireland
Asked — Edited
Resolved Resolved by Dunning-Kruger!

Adc Motor Control Script

Attempting to control a motor with potentiometer (adc) and get it to move in correct direction (using hbridge) to a specified ADC position

ideally I want the motor to operate like a servo ,give it a value and it will find that position and stop, this adcspecified would vary.

script if ($adcSpecified = 135) (Get error "variable not defined on this line ")

endif

:start

$adcCurrent = GetADC(adc7)

if ($adcCurrent $adcSpecified) goto( Right) endif if ($adcCurrent = $adcSpecified) goto( Stop) endif goto(Start)

: Left Set(d23, on) Set(d22, off) Return() : Right Set(d23, off) Set(d22, on) Return() : Stop Set(d22, off) Set(d23, off) Halt()


ARC Pro

Upgrade to ARC Pro

Experience the transformation – subscribe to Synthiam ARC Pro and watch your robot evolve into a marvel of innovation and intelligence.

#1  

Where is the variable $adcSpecified getting it's value from? Is it set in another script?... You are going to get an error if you haven't specified $adcSpecified at least in another or same script first... your first two lines in your script don't do anything, what do you need them?


if ($adcSpecified = 135) (Get error "variable not defined on this line ")

endif

#what does the above supposed to do?

#2  

Is this what you wanted? If so it should work now...



 $adcSpecified = 135
 :start

$adcCurrent = GetADC(adc7)

if ($adcCurrent $adcSpecified)
 goto( Right)
endif
if ($adcCurrent = $adcSpecified)
 goto( Stop)
endif
goto(Start)

: Left
Set(d23, on)
Set(d22, off)
Return()
: Right
Set(d23, off)
Set(d22, on)
Return()
: Stop
Set(d22, off)
Set(d23, off)
Halt()

Ireland
#3  

Thanks Richard Ah so thats where the $adcspecified comes from I presumed one entered a value on that script must experiment a little more so I can then enter my varing $adcspecified

Ireland
#4  

Richard Thank you so much that worked this is the working version that may be of use to others.You are a genius at programming. Any pointers how one could get this script to accept a varing "$adcspecified "

$adcSpecified = 145 :start

$adcCurrent = GetADC(adc7) if ($adccurrent > $adcspecified) goto(left) endif if ($adcCurrent < $adcSpecified) goto( Right) endif if ($adcCurrent = $adcSpecified) goto( Stop) endif goto(Start)

: Left Set(d22, on) Set(d23, off) Return() : Right Set(d22, off) Set(d23, on) Return() : Stop Set(d22, off) Set(d23, off) Halt()

#5  

Dude, I am no genius by any means, but thanks... Maybe you could use a slide script control to pass your required value to $adcSpecified ...Just change the default value in slide scrip from $SlideValue to $adcSpecified... Now when you move the slider in the control it will change your values automatically...

note you will need to get rid of this line ($adcSpecified = 145) if you use the slide script... The slide script will provide your value from now on....

United Kingdom
#6  

Check the topic Gwen started about needing help with custom movement scripts. Have a look over the project I made for ramping the speed of the sabertooth and check out how I used a script which would accept variables which were set elsewhere.

Basically, a main script which did the thinking, calculations, movements etc. which was triggered by a different script. The second script would first specify the variables, i.e. set the speeds for the motors then it would run the script which sent the commands to the sabertooth to gradually increase the speed of each motor until they reached the desired speeds.

Similar could be done with this. A script which moves the motor on the H-Bridge until the Pot on the ADC port reads the required value. That script is triggered by a different script using ControlCommand() after specifying the desired position.

For accurate positioning you may need the script which monitors the pot on the ADC port to check very quickly (depending on motor speed) though which may cause comms bottlenecks and increased CPU load. It may end up needing to be a bit of a compromise in areas.

#7  

@Bravia, Off topic, but I know you will be following this thread. Last year, there was a long discussion about how a robot could return to a charging location and plug itself in. I think you were the closest to actually building a working solution. did you ever complete that?

Alan

Ireland
#8  

Alan Shall i say I was part of a discussion group that put forward ideas I experimented with a polou ir beacon ( www.pololu.com/product/701) which works well indoors Its built into the upper part of" robot leonardo " which is pictured on my logo

Will demo some of its features once I have completed my present project Pat

Ireland
#9  

Very rewarding evening of scripting with the support of this communities resident experts I can now instruct a dc motor ( using a hbridge ) to move to any desired position by even voice commands. Will publish more details to assist others in the near future. Many thanks to all who assisted Pat

:):P;) :P

#10  

Bravia, I for one am very interested in how this was done. Im currently using wheelchair motors for shoulders, and timed commands are just not accurate enough. PLease keep me in the loop on this. Thanks

                            Chris
#11  

Sorry I missed this thread till now. I overcame this issue a couple years ago. At the time I was using a V3 ezb and was having problems with over shooting my specified variable. I had to use a little math in my scripts to get the motor to center properly without rocking. The V4 may not suffer from this adc lag but if you find this a problem then read over my old and ancient thread. I may be worth reading anyway as it has some scripting you don't see everyday in usual ez scripts. DC Motors, pots & ADC ports

Ireland
#12  

Dave That is one issue I was working on will incorporate your script and see how it works Thank You