Stopping motor after 750ms

5 years 6 months ago #29530241 by ccsgtech
Hi,
I am having trouble stopping a motor after 750ms of running time in reverse. I am testing in the roborun console but i will be using an r/c remote to control the robot.
Here is my code:


'programme pour arreter le moteur apres 750ms

top:

while(getvalue(_p,1) < -100 )
settimercount (1, 750) 'démarrer timer pour 750ms
wait(10)
if (gettimercount(1) < 1) then
setcommand (_GO,1,0) ' set moteur à 0
wait(500)
end if
end while

goto top

Thanks to all
Carl

Please Log in or Create an account to join the conversation.

5 years 6 months ago #29530253 by TechSupport
You need to look at the timerstate as well.
The following user(s) said Thank You: ccsgtech

Please Log in or Create an account to join the conversation.

5 years 6 months ago #29530257 by ccsgtech
Replied by ccsgtech on topic Stopping motor after 750ms
I have been playing around with timers, starting and stopping the motors. The thing i am not sure about is what value does the controller would prefer to read to let it know its goiing in reverse and what is the best way to duplicate the safety stop function (stop the motor until it as reach 0 or put in other direction).
Thanks

Please Log in or Create an account to join the conversation.

5 years 6 months ago #29530258 by TechSupport
The safety stop function is sending the motor command to 0. This allows for regenerative braking to occur. The problem is that the safety stop function is looking at an actual motor command of 0 after unlatching, or an inverted motor command.

You could in a sense trigger the function as a command and disable as a command to get something like this in your timer.

You could query the motor command as getvalue(_M, nn) 'where nn is motor channel.

Please Log in or Create an account to join the conversation.

5 years 6 months ago #29530273 by ccsgtech
Replied by ccsgtech on topic Stopping motor after 750ms
Got it

this works for me. stops after 1000ms because i changed my mind on legnht of time.
settimercount(0,1200) 'set timer
settimerstate(0,1) 'set timer to off

top:
print ("moteur=",getvalue(_m,1), "\n")
wait (10)
print ("timer=",gettimerstate(0), "\n")
wait (10)
Print("pulse=", getvalue (_pic,1), "\n")
wait (10)
print ("timer=",gettimercount(0), "\n")
wait (100)

while (getvalue (_pic,1)<-100) 'gets pusle converted input
settimerstate(0,0) 'start timer

print ("timer=",gettimercount(0), "\n")
if (gettimercount(0) <1) then
setcommand (_ex, 1) 'emergency stop
end if
end while

setcommand (_mg, 1) 'release emergency stop

settimercount(0,1200) 'set timer
settimerstate(0,1) 'set timer to off


goto top

Hope this helps someone

Please Log in or Create an account to join the conversation.

5 years 6 months ago #29530279 by LROBBINS
Replied by LROBBINS on topic Stopping motor after 750ms
Can you clear up a bit of confusion for me? In this thread, reference is made to timer index 0, but the NextGen user's manual keeps saying things like this:

SetTimerCount/GetTimerCount
These two functions used to set/get timer count.
SetTimerCount(<index>, <milliseconds>)
GetTimerCount(<index>)
Where, index is the timer index (1-4) and milliseconds is the number of milliseconds to
count.

So, are the four timers numbered 0-3 or 1-4?
Ciao,
Lenny

Please Log in or Create an account to join the conversation.

5 years 6 months ago #29530280 by TechSupport
Seems that 0 through 4 work for some reason.

Please Log in or Create an account to join the conversation.

5 years 6 months ago #29530281 by ccsgtech
Replied by ccsgtech on topic Stopping motor after 750ms
I havent tried index 4 because i read in some other thread that it did not work. There is 4 available timers from 0 to 3 is my understanding.
Carl

Please Log in or Create an account to join the conversation.

5 years 6 months ago - 5 years 6 months ago #29530283 by LROBBINS
Replied by LROBBINS on topic Stopping motor after 750ms
I can confirm what ccsgtech has said DO NOT USE Timer (4)! It will compile and seem to work, but it steps on other critical functions. Here are a couple screen shots to illustrate the problem.

First, correct behavior using Timer(0):

Notice that Motor 1 and Motor 2 command curves are superimposed, and that Motor 1 and Motor 2 power curves, also superimposed, smoothly climb to match the commands.


Now, here's what happens if one tries to use Timer(4):

The motor commands are working correctly, but motor power is not. Acceleration is erratic, the two motors do not track each other, and motor output, even for the one that has a smooth power curve, never rises to match what's being commanded.

PLEASE, in the next edition of the user's manual correct all references to indexing of the timers.

Ciao,
Lenny
Attachments:

Please Log in or Create an account to join the conversation.

5 years 6 months ago #29530286 by ccsgtech
Replied by ccsgtech on topic Stopping motor after 750ms
I have a new problem,
The only command function i have found that will stop the motor when its commanded to run is emergency stop. The thing is it shuts off the second motor also. The_ex function will not compile without an index but it shuts off both motors. What would be the best command to shut off only one motor when the rc radio commands it to run.
Carl

Please Log in or Create an account to join the conversation.

Time to create page: 0.221 seconds