Go to Post You never really graduate out of FIRST.... - Gnomegirl [more]
Home
Go Back   Chief Delphi > Technical > Technical Discussion
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 12-12-2015, 11:33
Bluejackets's Avatar
Bluejackets Bluejackets is offline
Bluejacket Robotics
FRC #5464 (Bluejacket Robotics)
 
Join Date: Dec 2014
Rookie Year: 2015
Location: Cambridge Isanti HS
Posts: 110
Bluejackets is a splendid one to beholdBluejackets is a splendid one to beholdBluejackets is a splendid one to beholdBluejackets is a splendid one to beholdBluejackets is a splendid one to beholdBluejackets is a splendid one to beholdBluejackets is a splendid one to behold
Question how to toggle motors in c++ using buttons

hey guys! I am new to C++ and I am told to try to get motors to run by pushing button 1 on the joystick... I am having issues doing that... anytime I try doing it it runs like tank drive... I try using an if statement like below.

if(stick.GetRawButton(1)){
talon.Set(1);
}else{
talon.Set(0);
}
if(stick2.GetRawButton(1)){
talon2.Set(1);
}else{
talon2.Set(0);

thanks for your time!
bluejacket robotics!
  #2   Spotlight this post!  
Unread 12-12-2015, 11:52
Anthony Galea's Avatar
Anthony Galea Anthony Galea is offline
Formerly known as 3175student17
no team
Team Role: College Student
 
Join Date: Aug 2012
Rookie Year: 2013
Location: Riverview, Michigan
Posts: 583
Anthony Galea has a brilliant futureAnthony Galea has a brilliant futureAnthony Galea has a brilliant futureAnthony Galea has a brilliant futureAnthony Galea has a brilliant futureAnthony Galea has a brilliant futureAnthony Galea has a brilliant futureAnthony Galea has a brilliant futureAnthony Galea has a brilliant futureAnthony Galea has a brilliant futureAnthony Galea has a brilliant future
Re: how to toggle motors in c++ using buttons

Have you tried setting the else (the off mode) to 0.5?
__________________
2013-2016: FRC 3175 Knight Vision, student
2014 Center Line District Finalists with 815 and 280
2016 Woodhaven District Winners with 3604 and 6116
2017-?: Rose-Hulman Institute of Technology
  #3   Spotlight this post!  
Unread 12-12-2015, 12:01
Bluejackets's Avatar
Bluejackets Bluejackets is offline
Bluejacket Robotics
FRC #5464 (Bluejacket Robotics)
 
Join Date: Dec 2014
Rookie Year: 2015
Location: Cambridge Isanti HS
Posts: 110
Bluejackets is a splendid one to beholdBluejackets is a splendid one to beholdBluejackets is a splendid one to beholdBluejackets is a splendid one to beholdBluejackets is a splendid one to beholdBluejackets is a splendid one to beholdBluejackets is a splendid one to behold
Re: how to toggle motors in c++ using buttons

just did... still the exact same results... only moves with the joysticks. i tried changing it to arcade drive and that did not make a difference...
  #4   Spotlight this post!  
Unread 12-12-2015, 12:34
Poseidon5817's Avatar
Poseidon5817 Poseidon5817 is offline
Founder and CEO, DeadMemes Studios
AKA: Mitchel Stokes
FRC #5817 (Uni-Rex)
Team Role: Mentor
 
Join Date: Aug 2013
Rookie Year: 2014
Location: Clovis, CA
Posts: 383
Poseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud of
Re: how to toggle motors in c++ using buttons

Quote:
Originally Posted by Bluejackets View Post
just did... still the exact same results... only moves with the joysticks. i tried changing it to arcade drive and that did not make a difference...
Are the motors a part of a RobotDrive object somewhere else? If so, the commands that you are sending the RobotDrive are probably overriding your motor commands. Try deleting the line where you use the tankDrive or arcadeDrive method and see if that works.
__________________
My FRC History:

2014 - Team 1671: Central Valley Regional Finalist and Chairman's Award Winner, Sacramento Regional Finalist, Archimedes Quarterfinalist
2015 - Team 1671: Central Valley Regional Semifinalist, Sacramento Regional Semifinalist and Chairman's Award Winner, Newton Winner, Einstein Winner
2016 - Team 5817: Central Valley Regional Finalist and Rookie All-Star, Orange County Regional Quarterfinalist and Rookie All-Star, Newton Division
2017 - Team 5817: Return of the bench grinder



Last edited by Poseidon5817 : 12-12-2015 at 12:34. Reason: Fixed a typo on the quote tags.
  #5   Spotlight this post!  
Unread 12-12-2015, 12:42
Bluejackets's Avatar
Bluejackets Bluejackets is offline
Bluejacket Robotics
FRC #5464 (Bluejacket Robotics)
 
Join Date: Dec 2014
Rookie Year: 2015
Location: Cambridge Isanti HS
Posts: 110
Bluejackets is a splendid one to beholdBluejackets is a splendid one to beholdBluejackets is a splendid one to beholdBluejackets is a splendid one to beholdBluejackets is a splendid one to beholdBluejackets is a splendid one to beholdBluejackets is a splendid one to behold
Re: how to toggle motors in c++ using buttons

okay... i'll try that poseidon. i have to leave for a meeting and will get back to you monday wheather it worked
  #6   Spotlight this post!  
Unread 12-12-2015, 13:42
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

If you can post your entire code (or just the teleoperated part) that will help.

I imagine the problem is what Poseidon said, your Robot object's TankDrive() method is taking priority over your code.

The code that you posted SHOULD be working,(when the trigger is pressed on the joystick, the Talon moves the motor at full speed), assuming everything is initialized properly and the robot class isn't using those Talons for tank drive.
__________________
1771- Programmer, Captain, Drive Team (2009-2012)
4509- Mentor (2013-2015)
1771- Mentor (2015)
  #7   Spotlight this post!  
Unread 12-12-2015, 19:25
Bluejackets's Avatar
Bluejackets Bluejackets is offline
Bluejacket Robotics
FRC #5464 (Bluejacket Robotics)
 
Join Date: Dec 2014
Rookie Year: 2015
Location: Cambridge Isanti HS
Posts: 110
Bluejackets is a splendid one to beholdBluejackets is a splendid one to beholdBluejackets is a splendid one to beholdBluejackets is a splendid one to beholdBluejackets is a splendid one to beholdBluejackets is a splendid one to beholdBluejackets is a splendid one to behold
Re: how to toggle motors in c++ using buttons

Quote:
Originally Posted by nighterfighter View Post
If you can post your entire code (or just the teleoperated part) that will help.

I imagine the problem is what Poseidon said, your Robot object's TankDrive() method is taking priority over your code.

The code that you posted SHOULD be working,(when the trigger is pressed on the joystick, the Talon moves the motor at full speed), assuming everything is initialized properly and the robot class isn't using those Talons for tank drive.
okay here is the whole code


Code:
         /**
	 * Runs during test mode
	 */
	#include "WPILib.h"


	/**
 * This is a demo program showing the use of the RobotDrive class.
 * The SampleRobot class is the base of a robot application that will automatically call your
 * Autonomous and OperatorControl methods at the right time as controlled by the switches on
 * the driver station or the field controls.
 *
 * WARNING: While it may look like a good choice to use for your code if you're inexperienced,
 * don't. Unless you know what you are doing, complex code will be much more difficult under
 * this system. Use IterativeRobot or Command-Based instead if you're new.
 */
	class Robot: public SampleRobot
{
	RobotDrive myRobot; // robot drive system
	Joystick stick; // only joy stick
	Joystick stick2;
	TalonSRX talon;
	TalonSRX talon2;


public:
	Robot() :
			myRobot(0, 1),	// these must be initialized in the same order
			stick(0),		// as they are declared above.
			stick2(1),
			talon(2),
			talon2(1)
{
		myRobot.SetExpiration(0.1);
	}

	/**
	 * Drive left & right motors for 2 seconds then stop
	 */
	void Autonomous()
	{
		myRobot.SetSafetyEnabled(false);
		myRobot.Drive(-1.0, 1.0); 	// drive forwards half speed
		Wait(2.0); 				//    for 2 seconds
		myRobot.Drive(0.0, 0.0); 	// stop robot


	}

	/**
	 * Runs the motors with arcade steering.
	 */
	void OperatorControl()
	{
		myRobot.SetSafetyEnabled(true);
		while (IsOperatorControl() && IsEnabled())
		{
			myRobot.TankDrive(stick, stick2); // drive with arcade style (use right stick)
			Wait(0.005);				// wait for a motor update time
			talon.Get();
			talon2.Get();
			if(stick.GetRawButton(1)){
				talon.Set(1);
			}else{
				talon.Set(0);
			}
			if(stick2.GetRawButton(1)){
				talon2.Set(1);
			}else{
				talon2.Set(0);
			}
		}

	}



	/**
	 * Runs during test mode
	 */
	void Test()
	{
	}
};

START_ROBOT_CLASS(Robot);
  #8   Spotlight this post!  
Unread 12-12-2015, 19:38
Poseidon5817's Avatar
Poseidon5817 Poseidon5817 is offline
Founder and CEO, DeadMemes Studios
AKA: Mitchel Stokes
FRC #5817 (Uni-Rex)
Team Role: Mentor
 
Join Date: Aug 2013
Rookie Year: 2014
Location: Clovis, CA
Posts: 383
Poseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud of
Re: how to toggle motors in c++ using buttons

Quote:
Originally Posted by Bluejackets View Post
okay here is the whole code


Code:
         /**
	 * Runs during test mode
	 */
	#include "WPILib.h"


	/**
 * This is a demo program showing the use of the RobotDrive class.
 * The SampleRobot class is the base of a robot application that will automatically call your
 * Autonomous and OperatorControl methods at the right time as controlled by the switches on
 * the driver station or the field controls.
 *
 * WARNING: While it may look like a good choice to use for your code if you're inexperienced,
 * don't. Unless you know what you are doing, complex code will be much more difficult under
 * this system. Use IterativeRobot or Command-Based instead if you're new.
 */
	class Robot: public SampleRobot
{
	RobotDrive myRobot; // robot drive system
	Joystick stick; // only joy stick
	Joystick stick2;
	TalonSRX talon;
	TalonSRX talon2;


public:
	Robot() :
			myRobot(0, 1),	// these must be initialized in the same order
			stick(0),		// as they are declared above.
			stick2(1),
			talon(2),
			talon2(1)
{
		myRobot.SetExpiration(0.1);
	}

	/**
	 * Drive left & right motors for 2 seconds then stop
	 */
	void Autonomous()
	{
		myRobot.SetSafetyEnabled(false);
		myRobot.Drive(-1.0, 1.0); 	// drive forwards half speed
		Wait(2.0); 				//    for 2 seconds
		myRobot.Drive(0.0, 0.0); 	// stop robot


	}

	/**
	 * Runs the motors with arcade steering.
	 */
	void OperatorControl()
	{
		myRobot.SetSafetyEnabled(true);
		while (IsOperatorControl() && IsEnabled())
		{
			myRobot.TankDrive(stick, stick2); // drive with arcade style (use right stick)
			Wait(0.005);				// wait for a motor update time
			talon.Get();
			talon2.Get();
			if(stick.GetRawButton(1)){
				talon.Set(1);
			}else{
				talon.Set(0);
			}
			if(stick2.GetRawButton(1)){
				talon2.Set(1);
			}else{
				talon2.Set(0);
			}
		}

	}



	/**
	 * Runs during test mode
	 */
	void Test()
	{
	}
};

START_ROBOT_CLASS(Robot);
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).
__________________
My FRC History:

2014 - Team 1671: Central Valley Regional Finalist and Chairman's Award Winner, Sacramento Regional Finalist, Archimedes Quarterfinalist
2015 - Team 1671: Central Valley Regional Semifinalist, Sacramento Regional Semifinalist and Chairman's Award Winner, Newton Winner, Einstein Winner
2016 - Team 5817: Central Valley Regional Finalist and Rookie All-Star, Orange County Regional Quarterfinalist and Rookie All-Star, Newton Division
2017 - Team 5817: Return of the bench grinder


  #9   Spotlight this post!  
Unread 12-12-2015, 19:45
Bluejackets's Avatar
Bluejackets Bluejackets is offline
Bluejacket Robotics
FRC #5464 (Bluejacket Robotics)
 
Join Date: Dec 2014
Rookie Year: 2015
Location: Cambridge Isanti HS
Posts: 110
Bluejackets is a splendid one to beholdBluejackets is a splendid one to beholdBluejackets is a splendid one to beholdBluejackets is a splendid one to beholdBluejackets is a splendid one to beholdBluejackets is a splendid one to beholdBluejackets is a splendid one to behold
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).
okay thanks! ill have to check it out in morning... no bot at home! thank you!
  #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)
  #11   Spotlight this post!  
Unread 12-12-2015, 19:55
Bluejackets's Avatar
Bluejackets Bluejackets is offline
Bluejacket Robotics
FRC #5464 (Bluejacket Robotics)
 
Join Date: Dec 2014
Rookie Year: 2015
Location: Cambridge Isanti HS
Posts: 110
Bluejackets is a splendid one to beholdBluejackets is a splendid one to beholdBluejackets is a splendid one to beholdBluejackets is a splendid one to beholdBluejackets is a splendid one to beholdBluejackets is a splendid one to beholdBluejackets is a splendid one to behold
Re: how to toggle motors in c++ using buttons

yeah i will need help mplimenting that... im used to labview... the talon.get was there because i left my pc with my team to work with while at a training i could not attend, so they added it to the code...
  #12   Spotlight this post!  
Unread 13-12-2015, 07:24
Bluejackets's Avatar
Bluejackets Bluejackets is offline
Bluejacket Robotics
FRC #5464 (Bluejacket Robotics)
 
Join Date: Dec 2014
Rookie Year: 2015
Location: Cambridge Isanti HS
Posts: 110
Bluejackets is a splendid one to beholdBluejackets is a splendid one to beholdBluejackets is a splendid one to beholdBluejackets is a splendid one to beholdBluejackets is a splendid one to beholdBluejackets is a splendid one to beholdBluejackets is a splendid one to behold
Re: how to toggle motors in c++ using buttons

nothing... absolutely nothing
any ideas?
  #13   Spotlight this post!  
Unread 13-12-2015, 14:22
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

Here is a quick and dirty way to do it.

What this code will do: While you are pressing a joystick trigger, the respective motor will spin at full speed. If you are not pressing the trigger, it will drive like normal tank drive.

The first thing you'll see is that I made 2 float variables, starting at 0.0. These will be passed into the TankDrive function.

The next thing is the "if" statement. If you are pressing the trigger on stick OR stick2, you then check to see which stick is being pressed, and assign 1.0 to the respective float values.

If you are NOT pressing the joysticks trigger, then the float values will be determined by the Y axis of the joystick.

Finally, those float values will be passed to the TankDrive method.

Forgive any formatting, I wrote it all in here. Also you might have to make one of the values negative, depending on how your motors are set up.


Code:
while (IsOperatorControl() && IsEnabled())
		{
			float leftValueToUse = 0.0; //2 values that will
                        float rightValueToUse = 0.0; // be passed to TankDrive
			
                       if(stick.GetRawButton(1) || stick2.GetRawButton(1) )
                      {
			if(stick.GetRawButton(1))
                       {
				leftValueToUse = 1.0;
			}
			if(stick2.GetRawButton(1))
                       {
				rightValueToUse = 1.0;
			}
                       
                      }
                    else
                    {
                    leftValueToUse = stick.GetY();
                    rightValueToUse = stick.GetY();
                     
                     }
                    myRobot.TankDrive(leftValueToUse,rightValueToUse);

                        Wait(0.005); //Wait for a motor update time

		}

Also, this isn't the best way to do it. There is a problem with this way. Think about what will happen if you are driving like normal, and then press and hold one of the joystick triggers. What will happen to the motor you are NOT pressing the respective joystick for? How can you fix that?
__________________
1771- Programmer, Captain, Drive Team (2009-2012)
4509- Mentor (2013-2015)
1771- Mentor (2015)
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 16:31.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi