View Single Post
  #11   Spotlight this post!  
Unread 21-10-2010, 21:26
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,120
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: How do I use interrupts?

Quote:
Originally Posted by Jon236 View Post
Even if the entire state machine (say, for raising an arm) is contained inside another case statement (collision imminent, true or false), if you are executing state machine logic within the 'collision false' case, wouldn't there be a significant delay (20 ms) before switching to the 'collision true' case?
Yes, if you are running the state machine at 50Hz. You can't achieve the immediate response you are seeking simply by changing the design of the state machine.

Quote:
My concern would be how to truly interrupt a process such as raising an arm when an imminent collision is sensed.
In the design you are referring to, would it suffice to simply remove power from the motor as quickly as possible to "interrupt the process", and then allow the next 20ms iteration to handle it from there?

If so, you could use the example Mark provided here and put your "event handler" code (to depower the motor) where the "react" note is in the diagram. You could also set a flag (like a global variable) that your state machine could read, to keep it from un-doing the motor depower. One possible way would be to test this flag after every motor command in the state machine, and depower the motor if the flag is set.

You could experiment with putting a small capacitor across the microswitch to help de-bounce it.



Reply With Quote