View Single Post
  #4   Spotlight this post!  
Unread 01-23-2016, 02:47 PM
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,002
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: Toggle Button For reverse

Quote:
Originally Posted by 414cnewq View Post
How would I implement a command to have a toggle button (i.e. the joystick button) to set the robot in reverse (press button once, in reverse, press button again, back to moving forward)?
You need to toggle the direction only when the "rising edge" of the button is detected.

Here's some C pseudo_code:

Code:
button_now = get_button(); // get the button state (pressed or not pressed)

if (button_now && ! button_previous) // detect rising edge only

{forward = ! forward;} // if rising edge, toggle the direction boolean

button_previous = button_now; // save the button state for comparison in the next iteration
... then use the "forward" boolean to determine whether to command forward or reverse.



Reply With Quote