![]() |
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! |
Re: how to toggle motors in c++ using buttons
Have you tried setting the else (the off mode) to 0.5?
|
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...
|
Re: how to toggle motors in c++ using buttons
Quote:
|
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
|
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. |
Re: how to toggle motors in c++ using buttons
Quote:
Code:
/** |
Re: how to toggle motors in c++ using buttons
Quote:
|
Re: how to toggle motors in c++ using buttons
Quote:
|
Re: how to toggle motors in c++ using buttons
Quote:
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())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. |
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...
|
Re: how to toggle motors in c++ using buttons
nothing... absolutely nothing
any ideas? |
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())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? |
| All times are GMT -5. The time now is 16:31. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi