Robot Movement Issues...

Our robot is having some major issues at the moment. Currently our robot will work with the joystick for a couple seconds before the robot stops moving. We’ve tried lowering the power of all the motors and we’re currently wondering if we need to either change the wheels from mecanum wheels to regular or omni-wheels or change the gear ratio(which would be a massive pain). Here’s a copy of our user control code:

#pragma config(Motor, port1, box, tmotorVex393_HBridge, openLoop)
#pragma config(Motor, port4, liftRight, tmotorVex393_MC29, openLoop, driveRight)
#pragma config(Motor, port5, liftLeft, tmotorVex393_MC29, openLoop, reversed, driveLeft)
#pragma config(Motor, port6, backRight, tmotorVex393_MC29, openLoop, driveRight)
#pragma config(Motor, port7, frontRight, tmotorVex393_MC29, openLoop, reversed, driveRight)
#pragma config(Motor, port8, backLeft, tmotorVex393_MC29, openLoop, reversed, driveLeft)
#pragma config(Motor, port9, frontLeft, tmotorVex393_MC29, openLoop, driveLeft)
#pragma config(Motor, port10, claw, tmotorVex393_HBridge, openLoop)
//!!Code automatically generated by ‘ROBOTC’ configuration wizard !!//

#pragma platform(VEX2)
#pragma competitionControl(Competition)
#include “Vex_Competition_Includes.c”

int BOX_UP = 0;
int BOX_DOWN = 0;

// Setup for competition
void pre_auton()
{
// This code is how many inches the robot moves forward between one tick of the left and right wheel encoders.
// Calculations: Diameter of 4" so C=pi*d circumference (C) is 4pi; accounting for the gear ratio of 60:12 = 5:1 : ticks per revolution (TpR) is 125.44; C/TpR = distance per tick (IpT); IpT=0.100178337.
// Set encoder values to zero
nMotorEncoder [frontRight] = 0;
nMotorEncoder [backRight] = 0;

// Stops extra tasks between auton and driver control
bStopTasksBetweenModes = true;
}
// Converts ticks for the driving encoders to inches that the robot moved
float INCHES_PER_TICK = 0.100178337;
float inchesCalc (float inches)
{
return inches / INCHES_PER_TICK;
}

/*void forward()
{
motor[frontLeft] = 63;
motor[backLeft] = 63;
motor[frontRight] = 63;
motor[backRight] = 63;
}

void left()
{
motor[frontRight] = 63;
motor[frontLeft] = -63;
motor[backRight] = 63;
motor[backLeft] = -63;
}

void right()
{
motor[frontRight] = -63;
motor[frontLeft] = 63;
motor[backRight] = -63;
motor[backLeft] = 63;
}

void counterTurn()
{
motor[leftMotor] = -63;
motor[leftMotor] = -63;
motor[rightMotor] = 63;
motor[rightMotor] = 63;
}

void clockTurn()
{
motor[leftMotor] = 63;
motor[leftMotor] = 63;
motor[rightMotor] = -63;
motor[rightMotor] = -63;
}*/

/*
AUTONOMOUS CODE PLAN

Currently, no plan.

*/
task autonomous()
{
/*int quarterTurn = -6000;
int clockeighthTurn = -3000;

{
while(nMotorEncoder[leftMotor] < inchesCalc (8.5)) //Robot goes forward 8.5 inches
{
forward();
}
while(nMotorEncoder[leftMotor] < inchesCalc (17)) //Robot goes to the right 17.0 inches
{
right();
}
while(SensorValue[leftMotor] < eighthTurn)
{
clockTurn();
}
// while(nMotorEncoder[leftMotor] , inchesCalc (24) //Robot

}*/
}

/*
DRIVER CONTROL PLAN

TODO

Add forward/back/turn control
Make joystick values incorporate whichever type currently isn’t active
Add Mechanum capabilities
Adjust to make robot easy to control
*/
task boxUp ()
{
while (nMotorEncoder[box] < BOX_UP)
{
motor[box] = 63;
}
motor[box] = 0;
}

task boxDown ()
{
while (nMotorEncoder[box] > BOX_DOWN)
{
motor[box] = -63;
}
motor[box] = 0;
}

task usercontrol()
{
while (true)
{
int fCh = (((abs (vexRT [Ch2]) > 20) ? abs (vexRT [Ch2]) : 0) + ((abs (vexRT [Ch3]) > 20) ? abs (vexRT [Ch3]) : 0)) / 2;
int sCh = abs ((((abs (vexRT [Ch1]) > 20) ? vexRT [Ch1] : 0) + ((abs (vexRT [Ch4]) > 20) ? vexRT [Ch4] : 0)) / 2);
writeDebugStream (“%d %d %d\n”, sCh, vexRT [Ch4], vexRT [Ch1]);
if (fCh > sCh)
{
float lF = vexRT [Ch3] / 63;
float rF = vexRT [Ch2] / 63;
float lS = vexRT [Ch4] / 63;
float rS = vexRT [Ch1] / 63;
float lCh = lF * lF + lS * lS;
float rCh = rF * rF + rS * rS;
int l = lCh * 127 * ((vexRT [Ch3] < 0) ? -1 : 1);
int r = rCh * 127 * ((vexRT [Ch2] < 0) ? -1 : 1);
//writeDebugStream (“l: %d\n”, l);
if (abs (r) > 20)
{
motor [frontRight] = r;
motor [backRight] = r;
}
else
{
motor [frontRight] = 0;
motor [backRight] = 0;
}

if (abs (l) > 20)
{
motor [frontLeft] = l;
motor [backLeft] = l;
}
else
{
motor [frontLeft] = 0;
motor [backLeft] = 0;
}
}
else if (sCh > 30)
{
float lF = vexRT [Ch3] / 63;
float rF = vexRT [Ch2] / 63;
float lS = vexRT [Ch4] / 63;
float rS = vexRT [Ch1] / 63;
float lCh = lF * lF + lS * lS;
float rCh = rF * rF + rS * rS;
int l = lCh * 127 * ((vexRT [Ch4] < 0) ? -1 : 1);
int r = rCh * 127 * ((vexRT [Ch1] < 0) ? -1 : 1);
int s = (l + r) / 2;
if (abs (s) > 30)
{
motor [frontLeft] = s;
motor [frontRight] = -s;
motor [backLeft] = -s;
motor [backRight] = s;
}
else
{
motor [frontLeft] = 0;
motor [frontRight] = 0;
motor [backLeft] = 0;
motor [backRight] = 0;
}
}
else
{
motor [frontLeft] = 0;
motor [frontRight] = 0;
motor [backLeft] = 0;
motor [backRight] = 0;
}
if (vexRT[Btn6U])
{
motor[liftLeft] = 80;
motor[liftRight] = 80;
}
else if (vexRT[Btn6D])
{
motor[liftLeft] = -80;
motor[liftRight] = -80;
}
else
{
motor[liftLeft] = 0;
motor[liftRight] = 0;
}
if (vexRT[Btn5U])
{
motor[claw] = 70;
}
else if (vexRT[Btn5D])
{
motor[claw] = -70;
}
else
{
motor[claw] = 0;
}
if (vexRT[Btn8U])
{
startTask (boxUp);
}
if (vexRT[Btn8R])
{
startTask (boxDown);
}
}
}

Please don’t double-post. If you need to change something from the original post, use the Edit feature.

Also, for readability, please enclose your code with the



 tag.

You’ve got some coding issues going on, but I don’t think it’s the reason for your stalling (sorry). But this is important too, and easy to fix.

Tasks are different than functions, but you’re using them in your code as if they were functions. Functions take the main code out of its loop, do the thing they do, and then come back to the main code. Tasks run pseudo-simultaneously with your other code.

If you use a function for box-up & box-down, as you probably know, other joystick action will be locked out during the time that motor runs. I’m guessing that’s why you made them tasks.

Tasks, in general, have their code wrapped in a while(true) loop. Your Box-up and Box-down tasks do not have an infinite loop; they can also be combined together into one single task for efficiency & ease of reading. Imagine them just like the joystick action – joystick commands are in an infinite loop because they are constantly checking to see if buttons were pressed. Same in your task.

Next, you’ll want to start your task in usercontrol BEFORE the while loop, so that you only start it one time. The way you’ve got it written above, you are creating a new instance of the task every time one of the buttons is pressed, each time through the loop.

You want something like the following (please excuse any syntax errors here; I’m just typing this):

// create FUNCTIONS for box-up & box-down
void boxUp() {
   // same code you have now in the box-up task
}
void boxDown() {
   // same code from above
}

// create a TASK to constantly check the joystick buttons
// and do something when needed
task box() {
   while(true) {
      if (vexRT[Btn8U]) {
         boxUP();
      }
      ELSE if (vexRT[Btn8R]) {
         boxDown();
      }
   }
}

task usercontrol() {
   // start the Box task here, just once, before the main while(true) loop
   startTask box();

   while(true) {
      // all of your code EXCEPT the Btn8U & 8R, which are now
      // handled by the task; the code is there instead of here
   }

   // not required, since it's after the infinite loop
   // but probably good to get in the habit of thinking 
   // about when your tasks should stop
   stopTask box();
}

Like I said at the start: sorry I’m not answering your main question, but this will really help your Button8 work the right way.

OK, re-reading your OP.

  1. Mecanum wheels are generally not great; they require a lot of power, and move only slowly when they do.
  2. Are you using normal-speed motors (torque gearing)? Or did you change them to high-speed motors?
  3. You mentioned changing the gear ratio; were you talking about external gears, or changing the gears inside the motor? If you’re talking about inside the motors, then I think the answer to #2 above is that you have high-speed gearing, which will pretty much never work with mecanum wheels, and is probably the source of the problem.

Again, hope this helps.