Thanks
On my code its not identifying y in the user control area. Any ideas on how I can get it to do this? I have a callback for y=50, but I don’t know why it won’t register in the user control area.
Post the code so we can see what you are trying to do.
Y=50 would not be a callback, it’s a variable. I think your variable is declared inside a different function than usercontrol, which means that it will only be recognized when you reference it in that function. Put the declaration outside of any function to make it a global variable, which you can call on from anywhere in the code.
I tried putting it outside of the function and it worked, but how would I change the variable?
A global variable can be accessed by all functions and all threads. You declare a local variable inside this function.
void function(){
int y=50;
}
when using global variables it’s best to give them a descriptive name, so if this variable will represent, for example, a speed, perhaps name it.
int liftSpeed;
or if you want an initial value for it
int liftSpeed = 15;
place that line way at the top of main outside of any functions, perhaps under this line of code.
vex::competition Competition;
then, in your function you can set it like this.
void function(){
liftSpeed = 50;
}
and use it later like this.
int DownSpeedPCT = liftSpeed;
(although there’s no real point doing that copy, you could just use it in here directly by replacing DownSpeedPCT with liftSpeed.
LA.spin(vex::directionType::fwd, DownSpeedPCT, vex::velocityUnits::pct);
Im currently looking at another code, but ill give this a try.
When its in the function it does not have any effect on the user control
there should be a speed setting in the spin command.
I know that. What I meant was that our goal is to make the motors spin at different speeds through the use of a button being pressed once.
set a variable like
int speed=0 ;/*always have a initial value for variables or there will be trouble */
and in your operator control loop
while(1)
{
speed= Controller1.ButtonX.pressed()? speed+1:speed;
speed= speed>=4? 0:speed;
switch (speed)
{
case 0: motor.spin(directionType::fwd,50,velocityUnits::pct);
case 1: motor.spin(directionType::fwd,70,velocityUnits::pct);
case 2: motor.spin(directionType::fwd,90,velocityUnits::pct);
case 3: motor. stop(brakeType:hold) ;
}
}
edit : @enothecool
What do you mean by trouble when you say always have a number for variables or something will go wrong
the variable’s value is saved in the brain’s RAM and when you declare a variable you clear up a slot to store it. however the previous stuff saved in there isn’t always cleared and may lead to errors while running the programme.
edit @enothecool
dang it why do I always forget to @
I have now realized that our driver wants us to change the wheel speed not the arm speed, but it is found through an equation. Anyone know how I would slow this down with the press of a button?
LW2.spin(vex::directionType::fwd, Controller1.Axis2.value() + Controller1.Axis4.value() - Controller1.Axis1.value(), vex::velocityUnits::pct);
LW1.spin(vex::directionType::fwd, Controller1.Axis2.value() + Controller1.Axis4.value() + Controller1.Axis1.value(), vex::velocityUnits::pct);
RW2.spin(vex::directionType::fwd, Controller1.Axis2.value() - Controller1.Axis4.value() + Controller1.Axis1.value(), vex::velocityUnits::pct);
RW1.spin(vex::directionType::fwd, Controller1.Axis2.value() - Controller1.Axis4.value() - Controller1.Axis1.value(), vex::velocityUnits::pct);
use a variable as a coefficient of the stick values and have it change with the press of a button
Alright now repeat that in english
int coefficient;
make the motor spin for speed coefficient*joystick value
coefficient = buttonpressed? coefficient + 0.5:coefficient
coefficient = coefficient >1? 0. 5:coefficient;
I think I get what your saying. I use the current equation separately and then multiply it by something to find out it’s value?
yeah you got it BTW r u using mecanums?
No holonomic drive
20 characters