![]() |
Button programin C++
so my team is using mecanum wheels this year. we would like to make it so when you hit the trigger on the left joystick it reduces the maximum speed of the motor by half. so im my code i have this
Code:
bool GetTrigger (Joystick hand = leftstick);i was trying to create an if statement to change the speed of the motors but its not working. any suggestions? |
Re: Button programin C++
..
|
Re: Button programin C++
Wouldn't doubling the speed make it go faster unless you puss the trigger?
What I'm looking to do is while in operator control drive mecanum drive full power, but when you get close to the pegs you press the trigger and you drive at half the speed. Does that make sense? |
Re: Button programin C++
..
|
Re: Button programin C++
Try this:
if ( !stick.GetTrigger()){ motors.Set(x); } else{ motors.Set(x/2); } This code assumes that x is the input variable that you use for speed. For driver control, this would be the value you get from your joysticks. It works by checking to see if the trigger is pressed. If not, then the speed is just as normal. If the trigger is pressed, then the speed is half of what it would normally be. Hope this is what you meant. |
Re: Button programin C++
That's what I ment thanks :D
|
Re: Button programin C++
would i put that before:
bool GetTrigger.... of after it cause i just tried to build it and i got a boat load of errors |
Re: Button programin C++
If your joystick's name in the program is "hand" then the portion of the code that needs to be the argument for the if statement is as follows: "hang.GetTrigger()".
The code segment would look like if ( !hand.GetTrigger()){ motors.Set(x); } else{ motors.Set(x/2); } You don't need a boolean variable for this code, only the value coming directly from the joystick. |
Re: Button programin C++
it dosent like motors.set(x)
do i have to declare each motor leftmotor.set(x),rightmotor.... |
Re: Button programin C++
I am sorry, I forgot to mention that the "motors.Set()" section was just a stand in for whatever functions you use to move. You would either replace the "motors" part with the motors that you declared earlier in your program or replace the "motors.Set()" function with whatever function you were using to drive.
For example, if you declared your motors previously as LeftMotor and RightMotor, then the code would look like: if ( !stick.GetTrigger()){ LeftMotor.Set(x); RightMotor.Set(x); } else{ LeftMotor.Set(x/2); RightMotor.Set(x/2); } Sorry about forgetting to include that little tidbit. If you have any more problems with your code, post a copy of the driver section so we can see what might be the problem. |
Re: Button programin C++
i tried to put in left motor and other stuff
here is the code Code:
#include "WPILib.h"Thanks for the help sorry to be a bothersum and ask so many question this is my first time using c++ :p |
Re: Button programin C++
If you want it to toggle, (untested)
Code:
bool hasJoystickBeenClicked(Joystick &joystick, bool &prev, bool &cur) { |
Re: Button programin C++
void OperatorControl(void)
{ myRobot.SetSafetyEnabled(true); AxisCamera &robocam = AxisCamera::GetInstance(); robocam.WriteResolution((AxisCamera::Resolution_t) 3); robocam.WriteBrightness(0); Wait(3.0); while (IsOperatorControl()) { if (!leftstick.GetTrigger()){ myRobot.MecanumDrive_Cartesian(leftstick.GetX(), leftstick.GetY(), rightstick.GetY(), 0);// mecanum drive at full speed } else{ myRobot.MecanumDrive_Cartesian(leftstick.GetX()/2, leftstick.GetY()/2, rightstick.GetY()/2, 0);// mecanum drive at full speed } robocam.GetImage(); image.GetImaqImage(); Wait(0.005); // wait for a motor update time } Try this for your OperatorControl function. This should work for you. And have fun with the mecanum drive, it's alot of fun once you get used to driving it. |
Re: Button programin C++
You just need to replace the motor.set() with myRobot.Drive().
Here is your code with the replacements made. It compiles. Code:
#include "WPILib.h" |
Re: Button programin C++
discokittys worked
random question for you guys, i know it is off the topic but... why isnt my camera sending an image to my driverstation? |
| All times are GMT -5. The time now is 13:39. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi