View Single Post
  #10   Spotlight this post!  
Unread 12-12-2015, 19:50
nighterfighter nighterfighter is offline
1771 Alum, 1771 Mentor
AKA: Matt B
FRC #1771 (1771)
Team Role: Mentor
 
Join Date: Sep 2009
Rookie Year: 2007
Location: Suwanee/Kennesaw, GA
Posts: 835
nighterfighter has a brilliant futurenighterfighter has a brilliant futurenighterfighter has a brilliant futurenighterfighter has a brilliant futurenighterfighter has a brilliant futurenighterfighter has a brilliant futurenighterfighter has a brilliant futurenighterfighter has a brilliant futurenighterfighter has a brilliant futurenighterfighter has a brilliant futurenighterfighter has a brilliant future
Re: how to toggle motors in c++ using buttons

Quote:
Originally Posted by Poseidon1671 View Post
Yep, there is your issue. Your motor button commands are getting overridden by your myRobot.tankDrive (stick1, stick2) call. If you delete that it should work. You are basically telling the motor to drive, and then immediately telling it to bit drive (or to drive at whatever your stick value is).
That, and the Wait() command.

The code is currently doing this, line by line (assuming the joysticks are in the neutral position)

Both Talons are being set to 0 speed (from the myRobot.TankDrive() method).
The motors run at this speed for 0.005 seconds.

Your if else blocks come into play, and set the speed of the motor to 1, or full speed.

They do this 0.000 seconds, before the loop restarts, and then get set to 0 again, from your TankDrive.

Your code should look like this:

Code:
while (IsOperatorControl() && IsEnabled())
		{
			
			//While buttons are pressed, move the motors.
			if(stick.GetRawButton(1)){
				talon.Set(1);
			}else{
				talon.Set(0);
			}
			if(stick2.GetRawButton(1)){
				talon2.Set(1);
			}else{
				talon2.Set(0);
			}
                        Wait(0.005); //Wait for a motor update time

		}

You'll notice that I removed your TankDrive method, and also those 2 talon.Get(); lines.

What were those talon.Get() for? talon.Get() returns a float value, based on the previous PWM value that object had. In your code, they weren't doing anything, or being assigned to anything.


If you want to implement both TankDrive() and your button pressing, using the same motors, you'll need to do some additional logic. Let me know if you need help implementing that.
__________________
1771- Programmer, Captain, Drive Team (2009-2012)
4509- Mentor (2013-2015)
1771- Mentor (2015)