Issues with new robot

So my D team is having an issue with their autonomous, the first line of autonomous runs, but nothing runs after that. Driver control works fine, its just their auto doesnt.

They did an update to the brains and to VS Code, but both programmers (Different computers) are having this issue:

# ---------------------------------------------------------------------------- #
#                                                                              #
# 	Module:       main.py                                                  #
# 	Author:       student                                                  #
# 	Created:      11/27/2023, 3:45:27 PM                                   #
# 	Description:  V5 project                                               #
#                                                                              #
# ---------------------------------------------------------------------------- #

# Library imports
from vex import *

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

brain.screen.print("Hello V5")
# Robot Configuration Code
LeF = Motor(Ports.PORT6)
LeB = Motor(Ports.PORT8)
MiDL = Motor(Ports.PORT7,True)
RiF = Motor(Ports.PORT5,True)
RiB = Motor(Ports.PORT10)
MidR = Motor(Ports.PORT9,True)
IntaK = Motor(Ports.PORT11,True)
PunchEr = Motor(Ports.PORT1,GearSetting.RATIO_36_1)
PiS1 = DigitalOut(brain.three_wire_port.h)
PiS2 = DigitalOut(brain.three_wire_port.g)
Inert = Inertial(Ports.PORT18)
#Motor groups
LefG = MotorGroup(LeF,LeB,MiDL)
RiG = MotorGroup(RiF,RiB,MidR)
#drivetrain and Controller
DrT = SmartDrive(LefG, RiG, Inert, 300, 320, 320, MM, 1)
Cont = Controller(PRIMARY)



#drivetrain and Controller
DrT = SmartDrive(LefG, RiG, Inert, 300, 320, 320, MM)
Cont = Controller(PRIMARY)


#Functions
def DrivE(distance,speed,direction):
   DrT.set_drive_velocity(speed,PERCENT)
   DrT.drive_for(direction, distance, INCHES)


def TurN(direction,angle,speed):
   DrT.set_turn_velocity(speed, PERCENT)
   DrT.turn_for(direction,angle,DEGREES)


def IntakE(direction,angle,speed):
        IntaK.set_velocity(speed,PERCENT)
        IntaK.spin_for(direction,angle,DEGREES)

def puNch(direction, time, speed):
        PunchEr.set_velocity(speed, PERCENT) 
        PunchEr.spin(direction)
        wait(time, MSEC)
        PunchEr.stop()

def WiNg(time,dare,bob):
        PiS1.set(dare)
        PiS2.set(dare)
        wait(time,MSEC)
        PiS1.set(bob)
        PiS2.set(bob)
        
def DriveW(time,dare,distance,speed,direction,bob):
        PiS1.set(dare)
        PiS2.set(dare)
        DrT.set_turn_velocity(speed,PERCENT)
        DrT.drive_for(direction,distance,INCHES)
        wait(time,MSEC)
        PiS1.set(bob)
        PiS2.set(bob)
   
def DriveI(distance,speed,direction,angle):
       IntaK.set_velocity(speed,PERCENT)
       IntaK.spin_for(direction,angle,DEGREES)
       DrT.set_drive_velocity(speed,PERCENT)
       DrT.drive_for(direction,distance,INCHES)






  #Competition Code
def pre_autonomous():
    count = 0
    brain.screen.clear_screen()
    while True:
       brain.screen.print_at("Pre_Auton.... %6d"%(count), x=10, y=40)
       count = count + 1
       DrT.set_stopping(COAST)
       Inert.calibrate()
       DrT.set_turn_constant(1.7)
       DrT.set_turn_threshold(1.77)


def autonomous():
   while True:
        DrivE(44,70,FORWARD)
        TurN(RIGHT,90,70)
        IntakE(REVERSE,1450,100)
        DrivE(20,70,REVERSE)
        TurN(LEFT,48,70)
        DrivE(9,70,FORWARD)
        IntakE(FORWARD,600,100)
        TurN(RIGHT,52,70)
        IntakE(REVERSE,1200,80)
        TurN(LEFT,173,70)
        DrivE(20,90,REVERSE)
        DrivE(10,90,FORWARD)
        wait(500000,MSEC)
       









def usercontrol():
        while True:
           


# controller with joy sticks
           RiG.set_velocity((Cont.axis2.position() + Cont.axis1.position()),PERCENT)
           LefG.set_velocity((Cont.axis2.position() - Cont.axis1.position()),PERCENT)
           LefG.spin(FORWARD)
           RiG.spin(FORWARD)


#Buttons
           if Cont.buttonR1.pressing():
                   PunchEr.set_velocity(100,PERCENT)
                   PunchEr.spin(REVERSE)


           elif Cont.buttonR2.pressing():
                   PunchEr.set_velocity(100,PERCENT)
                   PunchEr.spin(FORWARD)
           else:
                   PunchEr.stop()
                  
           if Cont.buttonL1.pressing():
                   IntaK.set_velocity(100,PERCENT)
                   IntaK.spin(REVERSE)


           elif Cont.buttonL2.pressing():
                   IntaK.set_velocity(100,PERCENT)
                   IntaK.spin(FORWARD)
           
           else:
                   IntaK.stop()
           

           if   Cont.buttonDown.pressing():
                   PiS1.set(True)

           elif Cont.buttonUp.pressing():
                   PiS1.set(False)

           if   Cont.buttonLeft.pressing():
                   PiS2.set(True)

           elif Cont.buttonRight.pressing():
                   PiS2.set(False)



comp = Competition(usercontrol, autonomous) #do not touch this

2nd Student:

# ---------------------------------------------------------------------------- #
#                                                                              #
# 	Module:       main.py                                                      #
# 	Author:       student                                                      #
# 	Created:      1/4/2024, 12:27:34 PM                                        #
# 	Description:  V5 project                                                   #
#                                                                              #
# ---------------------------------------------------------------------------- #

# Library imports
from vex import *

# Brain should be defined by default
brain=Brain()
# Robot Configuration Code
LeF = Motor(Ports.PORT6)
LeB = Motor(Ports.PORT8)
MiDL = Motor(Ports.PORT7,True)
RiF = Motor(Ports.PORT5,True)
RiB = Motor(Ports.PORT10)
MidR = Motor(Ports.PORT9,True)
inke = Motor(Ports.PORT11) 
PunchEr = Motor(Ports.PORT1,GearSetting.RATIO_36_1)
PiS1 = DigitalOut(brain.three_wire_port.h)
PiS2 = DigitalOut(brain.three_wire_port.g)
PiS3 = DigitalOut(brain.three_wire_port.f)
Inert = Inertial(Ports.PORT18)
#Motor groups
LefG = MotorGroup(LeF,LeB,MiDL)
RiG = MotorGroup(RiF,RiB,MidR)
#drivetrain and Controller
DrT = SmartDrive(LefG, RiG, Inert, 300, 320, 320, MM, 1)
Cont = Controller(PRIMARY)
#Functions
def DrivE(distance,speed,direction):
    DrT.set_drive_velocity(speed,PERCENT)
    DrT.drive_for(direction, distance, INCHES)
def TurN(angle, speed):
    DrT.turn_to_heading(angle, DEGREES)
    DrT.set_turn_velocity(speed, PERCENT)
def IntaK(speed,time,direction):
    inke.spin_for(direction,time)
    inke.set_velocity(speed, PERCENT)
def puNch(speed,direction,time):
    PunchEr.set_position(direction,time)
    PunchEr.set_velocity(speed, PERCENT) 
def WiNg(time,dare,bob):
       PiS1.set(dare)
       PiS2.set(dare)
       wait(time,MSEC)
       PiS1.set(bob)
       PiS2.set(bob)
   #Competition Code
def pre_autonomous():
    count = 0
    brain.screen.clear_screen()
    while True:
        brain.screen.print_at("Pre_Auton.... %6d"%(count), x=10, y=40)
        count = count + 1
        #DrT.set_stopping(COAST)
        Inert.calibrate()
        DrT.set_turn_constant(1.7)
        DrT.set_turn_threshold(1.77)
def autonomous():
    count = 0
    brain.screen.clear_screen()
    while True:
        brain.screen.print_at("Auton.... %6d" %(count), x=10, y=40)
        count = count + 1
        DrivE(8,90,REVERSE)
        DrivE(28,90,FORWARD)

        wait(250000)
def usercontrol():
        count = 0
        brain.screen.clear_screen()
        while True:
        
            brain.screen.print_at("User Control.... %6d" %(count), x=10, y=40)
# controller with joy sticks
            RiG.set_velocity((Cont.axis2.position() + Cont.axis1.position()),PERCENT)
            LefG.set_velocity((Cont.axis2.position() - Cont.axis1.position()),PERCENT)
            LefG.spin(FORWARD)
            RiG.spin(FORWARD)
#Buttons
            if Cont.buttonL1.pressing():
                inke.set_velocity(100,PERCENT)
                inke.spin(REVERSE)
            elif Cont.buttonL2.pressing():  
                inke.set_velocity(100,PERCENT)
                inke.spin(FORWARD)
            else:
                inke.stop()
            
            if Cont.buttonR2.pressing():
                PunchEr.set_velocity(100,PERCENT)
                PunchEr.spin(FORWARD)
            elif Cont.buttonR1.pressing():
                 PunchEr.set_velocity(100,PERCENT)
                 PunchEr.spin(REVERSE)

            else:
                PunchEr.stop()

comp = Competition(usercontrol, autonomous) #do not touch this

I haven’t properly looked into the program yet, but based on what your saying, it runs the first line of the Auton function but not any other.

Maybe because when it calls the DrivE() it fails to exit the function once “completed”. To avoid these scenarios you’d normally want to force it to exit if it is:

  1. within an area (measurement) where a slight deviation from its intended position
  2. Time it and see how long it takes, if it takes unnecessarily long cancel that / all other operations because something has gone wrong.

If this is similar to the C++ API (which I assume it is), .drive_for() returns a Boolean which is set to true when it has reached its target.

When you think it has stopped check if this has been set to true. This is so we know that the drive has reached its desired distance.

Hope this helps :slight_smile:

When doing the initial drive, does the robot run into anything (i.e. goal, wall)? That would probably be the issue. If the robot can’t finish one action, it won’t start the next. If the Drive Forward causes the robot to run into, say, a goal, and misses out on maybe 10 inches worth of intended driving, it will not continue running until you physically pull the robot out of the goal. You have to lower the number to be precise or make a timer that automatically starts the next line if it stops on a previous one.

If this is not the issue, please give more details as for what is happening.

Sorry I should have prefaced with saying this is a new bot for them, they went from a 4 motor drive to a 6 motor drive. Previous versions of the code worked fine with running their auto, line after line worked perfectly. They wanted a bot with more consistent power in their drive train so they chose a 6 motor base in a new bot.

We did the program in a open area with no obstructions, so the bot hits its movement distance with no issues on the first line, but then stops. We’ve changed the first lines to both Forward and Reverse, issues persists, runs the first line and 2nd line is nothing.

Tried a turning command, and the robot just spins. We tried replacing the inertial sensor and the robot radio I believe, but I am up for trying it again.

Possible solutions to the robot “just spinning” when you do a turn command:

First, I would take everything out of the “while True” loop in pre_autonomous. You’re restarting the calibration over and over again in that loop, which means that it’s still calibrating when auton starts. Most of that stuff only needs to be done once; you could leave the counting and printing in the while loop if you wanted – but add a wait command.

If that doesn’t fix it, check your motor setup for which ones are reversed. On direct drive, the right side motors should be reversed and the left side should be normal direction. On a geared drivetrain you may need to do the opposite. If you get it wrong, it will turn the wrong way and never get to the desired heading, so it will keep spinning.

For the problem of not going on to the second line, try adding a timeout. Before the first line of auton, do

Drivetrain.setTimeout(1, seconds);

1 Like

Alright the issue is, we need some of those to calibrate the turning, they did a trial and error section to make sure their turning is the best for what their bot needs. I can probably tell them remove the inert calibrate for sure though.

For the problem of not going on to the second line, try adding a timeout. Before the first line of auton, do

Drivetrain.setTimeout(1, seconds);

I’ll try the drivetrain time out, I didnt try putting the robot on its side to see if the wheels spin or not, I just assumed since Drive Forward worked fine, then Drive Reverse would be the same.

Thanks I’ll give that a shot today with them, they leave on the plane tomorrow to the 6th NorCal Signature event, I wont be going with them since I’m helping my wife run VEXIQ Regionals here.

Thanks again

I haven’t had any luck with drivetrain.turnFor. For me it just spins in a circle… So instead I made my own function in C++ its something like this (please note I have a 4 motor drivetrain but the process is similar you just have to add the other 2 motors):

void old_Turn(double desiredRotation,int speed = 20, double rangeoferror = 1){
// CalulatedRotationDeg ( is the tuned rotation of the sensor)
desiredRotation = CalulatedRotationDeg + desiredRotation;
LF.spin(forward, (desiredRotation-CalulatedRotationDeg)/absd(desiredRotation-CalulatedRotationDeg)* speed, percent);
LR.spin(forward, (desiredRotation-CalulatedRotationDeg)/absd(desiredRotation-CalulatedRotationDeg)* speed, percent);
RF.spin(forward, -(desiredRotation-CalulatedRotationDeg)/absd(desiredRotation-CalulatedRotationDeg)* speed, percent);
RR.spin(forward, -(desiredRotation-CalulatedRotationDeg)/absd(desiredRotation-CalulatedRotationDeg)* speed, percent);
    while(true){
    if(((desiredRotation + rangeoferror) <= CalulatedRotationDeg ) && (desiredRoation - rangeoferror) >=CalulatedRoationDeg){
break; // Is in tolerable range break out of while loop
  }
task::sleep(20); // Wait for 20 millseconds
    }
stopallmotors(hold) // stopallmotors(braketype) Stops all of the motors in the drivetrain
}

Also absd needs to be defined as this

double absd(double x) {
if(x < 0){
return - x;
}
return x ;
}

This works well but can sometimes skip the angle and do a full 360 so if you want you can put these :

LF.spin(forward, (desiredRotation-CalulatedRotationDeg)/absd(desiredRotation-CalulatedRotationDeg)* speed, percent);
LR.spin(forward, (desiredRotation-CalulatedRotationDeg)/absd(desiredRotation-CalulatedRotationDeg)* speed, percent);
RF.spin(forward, -(desiredRotation-CalulatedRotationDeg)/absd(desiredRotation-CalulatedRotationDeg)* speed, percent);
RR.spin(forward, -(desiredRotation-CalulatedRotationDeg)/absd(desiredRotation-CalulatedRotationDeg)* speed, percent);

into the while loop.

Replace CalulatedRoationDeg with inertial.rotation(deg) or drivetrain.rotation(deg)

python version :

import math

def old_Turn(desiredRotation, speed=20, rangeoferror=1):
    global CalulatedRotationDeg  # Assuming CalulatedRotationDeg is defined elsewhere
    desiredRotation += CalulatedRotationDeg
    direction = math.copysign(1, desiredRotation - CalulatedRotationDeg)
    
    # Assuming LF, LR, RF, RR are motor objects defined elsewhere with methods to spin
    LF.spin('forward', direction * speed)
    LR.spin('forward', direction * speed)
    RF.spin('forward', -direction * speed)
    RR.spin('forward', -direction * speed)
    
    while True:
        if (desiredRotation + rangeoferror) <= CalulatedRotationDeg and (desiredRotation - rangeoferror) >= CalulatedRotationDeg:
            break
        time.sleep(0.02)  # Sleep for 20 milliseconds
    
    stop_all_motors('hold')  # Assuming stop_all_motors is a function defined elsewhere

(AI converted this into python)

1 Like

To clarify: Keep all those commands (set_stopping, calibrate, set_turn_constant, set_turn_threshold) but put them before the while True so they only happen once.

OH gotcha… ok once again I feel dumb

Ok so tried moving the pre auton out of the program, and running it, issues persists, there is what sounds like a clicking sound after the first program, we tried commenting out the set turn thresh and constant but issues persists too.

Here’s a link to the video, it runs the drive forward function they made and then stops and just makes a noise:

just a comment on pre_autonomous, it nevers runs as far as I can tell from a quick read of the code because the pre_autonomous function is never called. The competition control doesn’t understand anything other than the functions to run during auton and driver control periods. The concept of pre_auton came from RobotC but all it really means is “the code you run before autonomous”, how and what that is is left up to the programmer.

1 Like

Is this setup correct ? All motors are green cartridge ? Right motor setup doesn’t seem to mirror left motor setup ?

1 Like

So here’s the funny thing, we tried the mirror, and the motors ran into each other. Not sure why, this was the only way all 6 motors would run properly.

If u look at the video they are mirrored properly physically, but program wise this was the only way to make all 6 turn right.

As for your pre auton question, so would it be better to just place all the calibration stuff outside the whole true in auton?