Chameleon Vision Auto Align not Working

Using the example code found on , https://chameleon-vision.readthedocs.io/en/latest/getting-started/robot-code-example.html, we have followed it very closely and adjusted it to our camera, but when we run the code nothing happens. I’m not sure where in the code does it actually move the drive base and I don’t know how it is supposed to understand where to go based off our drive base.

I am planning on using the auto align, to take data and make a function to make a relationship between pitch and distance in order to determine the distance from the camera to the robot. I calibrated 3D, but I have no clue how to use it and I fear I might run into more issues…

SO if anyone could help me troubleshoot with auto align or chameleon vision that would be great. Thank you!

Which example are you referring to? If the second one it drives using arcadeDrive at the bottom.

Yeah, so far we have used the second code example and have been unsuccessful in getting it to work.

I can’t open github for some reason but here’s my code at the moment.

/*----------------------------------------------------------------------------*/

/* Copyright (c) 2018 FIRST. All Rights Reserved.                             */

/* Open Source Software - may be modified and shared by FRC teams. The code   */

/* must be accompanied by the FIRST BSD license file in the root directory of */

/* the project.                                                               */

/*----------------------------------------------------------------------------*/

package frc.robot;

import com.ctre.phoenix.motorcontrol.can.WPI_TalonFX;

import edu.wpi.first.networktables.NetworkTable;

import edu.wpi.first.networktables.NetworkTableEntry;

import edu.wpi.first.networktables.NetworkTableInstance;

import edu.wpi.first.wpilibj.Joystick;

import edu.wpi.first.wpilibj.SpeedControllerGroup;

import edu.wpi.first.wpilibj.TimedRobot;

import edu.wpi.first.wpilibj.drive.DifferentialDrive;

/**

 * The VM is configured to automatically run this class, and to call the

 * functions corresponding to each mode, as described in the TimedRobot

 * documentation. If you change the name of this class or the package after

 * creating this project, you must also update the build.gradle file in the

 * project.

 */

public class Robot extends TimedRobot {

  //Variables

  //Robot vars (not directly related to the vision system)

  public Joystick joystick;

  //This example uses 4 spark motors controllers for the drivetrain with 2 motors on each side

  WPI_TalonFX m_frontLeft, m_frontRight, m_rearLeft, m_rearRight;

  DifferentialDrive m_drive;

  /*

  NetworkTable is a collection of databases stored in the RoboRIO

  The co processor can change data inside it

  This database can be viewed in a program named OutlineViewer

  "table" represents a single database called "MyCamName" under "Chameleon Vision`"

  */

  NetworkTable table;

  /*

  targetX represents the horizontal angle

  targetY represents the vertical angle

  */

  NetworkTableEntry targetX;

  NetworkTableEntry targetY;

  //Error values for the control loop

  double rotationError;

  double distanceError;

  //Control loop constants

  /*

      This example uses proportional control loop with constant force

      After you master proportional control use might want to try PID control loop

  */

  double KpRot=-0.1;

  double KpDist=-0.1;

  //Deadzone is necessary because the robot can only get so accurate and cannot be pefectly head on the target

  double angleTolerance=5;//Deadzone for the angle control loop

  double distanceTolerance=5;//Deadzone for the distance control loop

  /*

  There is a minimum power that you need to give to the drivetrain in order to overcome friction

  It helps the robot move and rotate at low speeds

  */

  double constantForce=0.05;

  /*

  rotationAjust is rotational signal for the drivetrain

  distanceAjust is forward signal for the drivetrain

  */

  double rotationAjust;

  double distanceAjust;

  //Initilazition function

  public void robotInit(){

      SpeedControllerGroup m_left = new SpeedControllerGroup(m_frontLeft, m_rearLeft);

      SpeedControllerGroup m_right = new SpeedControllerGroup(m_frontRight, m_rearRight);

      //Initilazition of robot drivetrain and joystick

      joystick = new Joystick(1);

      m_frontLeft = new WPI_TalonFX(1);

      m_rearLeft = new WPI_TalonFX(2);

      m_left = new SpeedControllerGroup(m_frontLeft, m_rearLeft);

      m_frontRight = new WPI_TalonFX(3);

      m_rearRight = new WPI_TalonFX(4);

      m_right = new SpeedControllerGroup(m_frontRight, m_rearRight);

      m_drive = new DifferentialDrive(m_left, m_right);

      //Points "table" to the NetworkTable database called "chameleon-vision"

      table=NetworkTableInstance.getDefault().getTable("chameleon-vision").getSubTable("MyCamName");

      //Points to the database value named "yaw" and "pitch"

      targetX=table.getEntry("yaw");

      targetY=table.getEntry("pitch");

  }

  //Periodic function

  public void teleopPeriodic()

  {

      rotationAjust=0;

      distanceAjust=0;

      if (joystick.getRawButton(1))// the "A" button

      {

          /*

              Fetches the rotation and distance values from the vision co processor

              sets the value to 0.0 if the value doesnt exist in the database

          */

          rotationError=targetX.getDouble(0.0);

          distanceError=targetY.getDouble(0.0);

          /*

              Proportional (to targetX) control loop for rotation

              Deadzone of angleTolerance

              Constant power is added to the direction the control loop wants to turn (to overcome friction)

          */

          if(rotationError>angleTolerance)

              rotationAjust=KpRot*rotationError+constantForce;

          else

              if(rotationError<angleTolerance)

                  rotationAjust=KpRot*rotationError-constantForce;

          /*

              Proportional (to targetY) control loop for distance

              Deadzone of distanceTolerance

              Constant power is added to the direction the control loop wants to turn (to overcome friction)

          */

          if(distanceError>distanceTolerance)

              distanceAjust=KpDist*distanceError+constantForce;

          else

              if(distanceError<distanceTolerance)

                  distanceAjust=KpDist*distanceError-constantForce;

          //Output the power signals to a arcade drivetrain

          m_drive.arcadeDrive(distanceAjust,rotationAjust);

      }

  }

}

Don’t forget to use triple back ticks.

what does this mean sorry?

Your code is more readable if you use ` three times before and after.

ah okay thank you very much, sorry.

Okay so what’s the actual problem?

I am unsure, I am trying to line the robot up with the target which has reflective tape of it however it does not move to align with the target, it does nothing. I am sure I am missing something but i don’t know what.

What Can Ids are your falcons on?

they are on 1, 2, 3 and 4

Try arcade drive using the Xbox controller. If that works then attempt vision. Does basic drive work fine? Except the fact that I would use curly brackets on your if else statements. Also, you are only taking values from the network table once during init. I haven’t used anything but command based in a while, is there a periodic method? If so, put
targetX=table.getEntry(“yaw”);

  targetY=table.getEntry("pitch");

in there. Or try putting them in teleop periodic.

Alright thank you! I will try that now.

targetX=table.getEntry(“yaw”);

targetY=table.getEntry("pitch");

Need to go in teleport periodic so it can update the values.

I would also make sure your talons are being powered properly, CAN loop is connected properly(terminating resistor, etc), and that the talonFX id’s values are correct.

If you’re using the latest version of ChameleonVision, shouldn’t the network table entries for yaw and pitch be “targetYaw” and “targetPitch”, not just “yaw” and “pitch”?
And is “MyCamName” the actual name of your camera? You’re probably not getting the right subtable either
https://chameleon-vision.readthedocs.io/en/latest/getting-started/networktables.html

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.