Reverse dead band? Is it Possible??

So i was wondering for when you’re programming joystick controls you can set dead bands so that from 0%-10% of the joystick the robot won’t move. But is there a way to say from lets say 80%-100% of the joystick it goes at max speed??

This is from robot c

if(vexRT[ch3]>80) {
motor[left drive] =100;
}

edit: I haven’t been to robotics club in a while so sorry if my values are off

I modified Dan’s code so that it represents 80% rather than 80 and works in both directions:

if((vexRT[ch3])/127.0 > 0.8) {
motor[left drive] = 127;
}else if((vexRT[ch3])/127.0 < -0.8) {
motor[left drive] = -127;
}

(Edited as per Tabor’s warning)

You should be more careful with your integer division. None of that would work.

You’ll want at least one change to that, and for best practice you’ll want others. First, you need to get a value even if you don’t exceed those limits. Second, you should really only query in input a single time when expecting the same response from it. Third, you probably want normal headbands as well. Finally, you might really want to make a smooth transition; and if you go over 127 it caps at 127 (likewise on the negative side).

motorSpeed = 1.2*vexRT[ch3]; // anything beyond 104 will make it hit 127, so everything beyond that is capped
if(abs(motorSpeed) < 12) {
   motorSpeed = 0; // deadband to 10, adjusted for the *1.2
}
motor[leftDrive] = motorSpeed;

I also have this feeling I read about the motors not going much faster with values over 100, but I really can’t remember that for sure. If that’s the case, the upper cap may essentially already be there.

Would this work

//Test of tank control with reverse deadband
      if (Controller1.Axis3.value() <= 80)
      {
          LeftDrive.spin(directionType::fwd,FullSpeed,velocityUnits::pct);
      }
      
      else
      {
          LeftDrive.spin(directionType::fwd,Controller1.Axis3.value(),velocityUnits::pct);
      }
      
      if (Controller1.Axis3.value() >= -80)
      {
          LeftDrive.spin(directionType::rev,FullSpeed,velocityUnits::pct);
      }
      
      else 
      {
          LeftDrive.spin(directionType::fwd,Controller1.Axis3.value(),velocityUnits::pct);
      }
      
      if (Controller1.Axis2.value()<= 80)
      {
          RightDrive.spin(directionType::rev,FullSpeed,velocityUnits::pct);
      }
      
      else 
      {
          RightDrive.spin(directionType::rev,Controller1.Axis2.value(),velocityUnits::pct);
      }
      
      if(Controller1.Axis2.value() >= -80)
      {
          RightDrive.spin(directionType::fwd,FullSpeed,velocityUnits::pct);
      }
      
      else
      {
          RightDrive.spin(directionType::fwd,Controller1.Axis2.value(),velocityUnits::pct);
      }

No, it won’t. The problem is the pair of if-else’s for each axis. You really want if-else if-else once for each axis. Here is what will happen with yours:

Axis 3 reads 50.

That’s under 80, so you set your motor to full speed forward. A moment later you check and 50 is greater than -80, so you now set it to full speed backward.

Hopefully that highlights it. You’re using your >= and <= backward, and you’re using pairs of if-else when you should use a single if-else if-else.

IMO a deadband like this looks best as a function:


int deadband(int power) {
    if(abs(power)<15) return 0;
    if(abs(power)>80) return power < 0 ? -80 : 80;
    return power;
}

which can be used like this:


Drive.spin(directionType::fwd, deadband(Controller1.Axis3.value()), velocityUnits::pct);

@callen so I changed my code but I’m getting this error

*10:52:34 -- warning -- warning: comparison of constant 80 with expression of type 'bool' is always true -Wtautological-constant-out-of-range-compare] 
      if (10 < Controller1.Axis3.value() < 80) 
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~ 
./main.cpp:216:42: 
10:52:34 -- warning -- warning: comparison of constant 80 with expression of type 'bool' is always true -Wtautological-constant-out-of-range-compare] 
      if (10 < Controller1.Axis2.value() < 80) 
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *

Here’s the full drive code

//Test of tank control with reverse deadband
      if (10 < Controller1.Axis3.value() < 80)
      {
          LeftDrive.spin(directionType::fwd,FullSpeed,velocityUnits::pct);
      }
      
      else if (-10 > Controller1.Axis3.value() > -80)
      {
          LeftDrive.spin(directionType::rev,FullSpeed,velocityUnits::pct);
      }
      
      else 
      {
          LeftDrive.spin(directionType::fwd,Controller1.Axis3.value(),velocityUnits::pct);
      }
      
      if (10 < Controller1.Axis2.value() < 80)
      {
          RightDrive.spin(directionType::rev,FullSpeed,velocityUnits::pct);
      }
      
      else if(-10 > Controller1.Axis2.value() > -80)
      {
          RightDrive.spin(directionType::fwd,FullSpeed,velocityUnits::pct);
      }
      
      else
      {
          RightDrive.spin(directionType::fwd,Controller1.Axis2.value(),velocityUnits::pct);
      }

You’re comparing an axis value to 10 or -10 and getting true or false. You’re then comparing true or false to 80. You want things like this if you want to write your code this way:

if (10 < axis && axis < 80)

ok thank you