VEX IQ Robot won't stop turning

This post is being made by a student under a coach account:

In programming mode (no controller), our team’s robot will not stop turning after we tell it to start. We are using the VEX IQ generation 2 brain. Within our program (attached to this post in .iqpython format), we are instructing the robot to “turn_for” 180 degrees. We have also tried “turn_to rotation” using the same value. Both of these yield our robot turning around in circles with no end in sight. We have tried replacing motors, cables, brains, and even new computers to no avail. We’ve also tried to use the default blocks program as well.

Does anyone have any other ideas on how to troubleshoot this? We need help solving this error.

#region VEXcode Generated Robot Configuration
from vex import *
import urandom

# Brain should be defined by default
brain=Brain()

# Robot configuration code
brain_inertial = Inertial()
left_drive_smart = Motor(Ports.PORT10, 1, False)
right_drive_smart = Motor(Ports.PORT11, 1, True)

drivetrain = SmartDrive(left_drive_smart, right_drive_smart, brain_inertial, 200)


def calibrate_drivetrain():
    # Calibrate the Drivetrain Inertial
    sleep(200, MSEC)
    brain.screen.print("Calibrating")
    brain.screen.next_row()
    brain.screen.print("Inertial")
    brain_inertial.calibrate()
    while brain_inertial.is_calibrating():
        sleep(25, MSEC)
    brain.screen.clear_screen()
    brain.screen.set_cursor(1, 1)


#endregion VEXcode Generated Robot Configuration

# ------------------------------------------------------------------------------
#
#    Project:           Turning Accurately
#    Description:       This example will show how to use different drivetrain
#                       turning commands to control the robot
#    Brain Supported:   2nd generation
#    Configuration:     BaseBot (Drivetrain 2-motor, Inertial)
#
# ------------------------------------------------------------------------------

# Library imports
from vex import *

# Begin project code
# Calibrate the Drivetrain Inertial
calibrate_drivetrain()


# A brief delay to observe the result of the turning action
drivetrain.turn_for(LEFT, 180, DEGREES)

# A brief delay to observe the result of the turning action
wait(1, SECONDS)

# A Drivetrain can be used to turn to an exact heading when using a Gyro or
# the Brains Inertial
# based on the sensor's feedback
# This command will point the robot back to a rotation value of 0 (its
# starting orientation) and will determine the fastest direction to turn
drivetrain.turn_to_rotation(0, DEGREES)

You need to stop the drivetrain after the turn using drivetrain.stop()

Is it turning to left or right (clockwise) ?

2 Likes

It is spinning CounterClockwise.

ok, well, I validated the code on an IQ clawbot with motors on ports 10 and 11 as you have it configured, everything works as expected.

How is the IQ2 mounted ? Screen horizontal or vertical ?

Is the brain fully updated to vexos 1.0.4 ?

Check the inertial sensor is working ok using the devices screen, press check to see detailed info after selecting the sensor tab. check that rotating the robot causes the rotation to increase when turning clockwise.

4 Likes

Apologize for the delayed response.

The IQ2 brain been mounted both ways, vertical and horizontal. Each way had the same problem. It’s currently horizontal.

Firmware version is 1.0.4.

Turned on the robot and opened the ‘Detailed Info’. The Heading starts at zero. When we manually rotate the robot clockwise, it increases from zero until it hits 360. At that point it goes back to zero if you keep going clockwise.

Rotating it the other direction works correctly, counting down instead. The values look correct, when the robot is pointing the opposite direction it started, it’s at 180 degrees.

2 Likes

Well, that sounds correct. Heading should wrap at 0/360 going both directions, Rotation will keep incrementing and show positive and negative values.

Any other clues you can give ? I had tested your original program on an IQ generation 2 clawbot and it worked ok.

and VEXcode full updated to 2.3.1-24 ?

Only think I can think of, if it’s not some issue specific to this particular robot, is that for some reason the Python VM is corrupted and the program not running correctly, but I would have thought that would cause other issues on the brain.

All I can suggest at this point is come find me at worlds so I can take a closer look.

5 Likes

Are the motors direct-driven or through gears from motor to wheels? If gears, how many gears between wheel and motor?

The times I have seen this happen, either with using drivetrain or ‘manual’ motor control, the robot is turning opposite of what it’s expecting, and so it never hits the target heading/rotation. If you haven’t already tried, reverse the motor setups (normal → reverse, reverse->normal) and see if the behavior changes.

1 Like

Had more time this weekend, we tried a different gen2 brain than the brain we originally reported on and we are seeing the same behavior. I switched my test to using an Fling build we had around.

We built and Downloaded using the ‘Turning Accurately’ example program from a VEXcode IQ on a Windows and a Mac. The example was used with no modifications. The robot motors had the same motor configuration and there were no other sensors connected to the brain:

Both laptops (Windows and Mac) had latest version of VEXCode IQ, 2.3.1-24.

image

Here’s the details on the robot:

image

image

image

Here is a video of the program running:

1 Like

We’re definitely baffled, earlier this season prior to the State Championships this all worked.

@jpearman Quick question, they’ve been using a Gen1 battery for practice and testing. I wouldn’t think so, but worth a shot: Would this have an impact on the inertial sensor behavior?

I don’t think so.

I guess the next step is to add something to the code to show the IMU value. I will try again today if I get a chance, looks like you are wirelessly downloading the program, again shouldn’t make a difference but I will try that. Was the controller still connected to the PC when you ran the code ?

3 Likes

Yes, the controller was connected in the video. But doesn’t seem to matter when I tested it with the controller off, it gets the same behavior of not stopping.

yea, I did a quick test with controller, still no issues here.
Unfortunately this is bad timing, I’m flying to Dallas tomorrow and have a bunch of other things to do today. I guess the next step would be to see if this is an issue with Python or some more systematic problem with the IMU. I was interested in the controller because the IMU is actually connected to the radio CPU inside the brain and its data sent along with controller and other data to the primary CPU, but you eliminated that theory.

Is this on a critical path for your worlds robot ?

4 Likes

For this team, it’ll be a critical component for their robot. They made good use of rotating the robot for positioing in their program before the State Championship.

I’ll be in Dallas on May 7th, Saturday. Maybe we can connect then, hopefully find the source and solution that afternoon. They’re smart kids, I’m sure they can get their programming back by Sunday afternoon. We’ll have a field where we’re staying, they’d be smooth sailing once this obstacle is removed.

sent you a DM, in the mean time, add this to the top of the Python program to display IMU rotation value on the screen, lets see what it thinks is happening.

def display_task():
    while True:
        brain.screen.print_at("%.2f" %brain_inertial.rotation(), x=2, y=80 )
        sleep(50)

Thread(display_task)

# Begin project code

you should see it turn to -180 and the turn back to 0.

4 Likes

Think we have something here, it’s accumulating the value, never returning to zero. Here’s the value after several rotations.

rotation() is absolute, it will keep accumulating. heading() is only 0 to 359.99 range.

what should happen for the example code is that robot will turn until rotation() is -180, then pause, then rotate the other way until the value is 0 again.

3 Likes

Ah, then it’s working. It does go to -180 degrees, and goes back up from there.

I see both values look correct, I adjusted the display_task() to be:

def display_task():
    while True:
        brain.screen.print_at("%.2f" %brain_inertial.rotation(), x=2, y=80 )
        brain.screen.print_at("%.2f" %brain_inertial.heading(), x=2, y=100 )
        sleep(50)

Thread(display_task)

The rotation value keeps accumulating, the Heading value is reseting at 360.

1 Like

Did you ever sort this out? My team is currently having this issue with their Gen2 brain. They are at a point where they are just going to use dead reckoning…

My recollection was we sorted this out at worlds in May, may just have been incorrect configuration of the drivetrain.

What is the specific issue you are having ? Is it programmed in blocks, Python or C++ ?

4 Likes