How to Code VEX AI Robot

So, our team didn’t get this far last season. This year however we got one Jetson Nano to work. However, when running the code, the robot just starts running in circles. Is there anything that could work to “activate” the Jetson Program?

Here is the main.cpp code:

/*----------------------------------------------------------------------------*/
/*                                                                            */
/*    Module:       main.cpp                                                  */
/*    Author:       Rian Thomas                                               */
/*    Created:      Mon Aug 31 2020                                           */
/*    Description:  V5 project                                                */
/*                                                                            */
/*----------------------------------------------------------------------------*/

// ---- START VEXCODE CONFIGURED DEVICES ----
// ---- END VEXCODE CONFIGURED DEVICES ----
#include "ai_functions.h"

using namespace vex;

brain Brain;
// Robot configuration code.
motor leftDrive = motor(PORT1, ratio18_1, false);
motor rightDrive = motor(PORT2, ratio18_1, true);
gps GPS = gps(PORT12, -127, -165, distanceUnits::mm, 180);
smartdrive Drivetrain = smartdrive(leftDrive, rightDrive, GPS, 319.19, 320, 40, mm, 1);
// Controls arm used for raising and lowering rings
motor Arm = motor(PORT3, ratio18_1, false);
// Controls the chain at the front of the arm
// used for pushing rings off of the arm
motor Chain = motor(PORT8, ratio18_1, false);


// A global instance of competition
competition Competition;

// create instance of jetson class to receive location and other
// data from the Jetson nano
//
ai::jetson  jetson_comms;

/*----------------------------------------------------------------------------*/
// Create a robot_link on PORT1 using the unique name robot_32456_1
// The unique name should probably incorporate the team number
// and be at least 12 characters so as to generate a good hash
//
// The Demo is symetrical, we send the same data and display the same status on both
// manager and worker robots
// Comment out the following definition to build for the worker robot
//#define  MANAGER_ROBOT    1

#if defined(MANAGER_ROBOT)
#pragma message("building for the manager")
ai::robot_link       link( PORT10, "robot_32456_1", linkType::manager );
#else
#pragma message("building for the worker")
ai::robot_link       link( PORT10, "robot_32456_1", linkType::worker );
#endif

/*---------------------------------------------------------------------------*/
/*                                                                           */
/*                          Auto_Isolation Task                              */
/*                                                                           */
/*  This task is used to control your robot during the autonomous isolation  */
/*  phase of a VEX AI Competition.                                           */
/*                                                                           */
/*  You must modify the code to add your own robot specific commands here.   */
/*---------------------------------------------------------------------------*/

void auto_Isolation(void) {
  // Calibrate GPS Sensor
  GPS.calibrate();
  // Optional wait to allow for calibration
  waitUntil(!(GPS.isCalibrating()));
  // Finds and moves robot to over the closest blue ring
  goToObject(OBJECT::BlueRing);
  grabRing();
  // Find and moves robot to the closest mobile drop
  // then drops the ring on the goal
  goToObject(OBJECT::MobileGoal);
  dropRing();
  // Back off from the goal
  Drivetrain.driveFor(-30, distanceUnits::cm);

}


/*---------------------------------------------------------------------------*/
/*                                                                           */
/*                        Auto_Interaction Task                              */
/*                                                                           */
/*  This task is used to control your robot during the autonomous interaction*/
/*  phase of a VEX AI Competition.                                           */
/*                                                                           */
/*  You must modify the code to add your own robot specific commands here.   */
/*---------------------------------------------------------------------------*/


void auto_Interaction(void) {
  // Add functions for interaction phase
}


/*---------------------------------------------------------------------------*/
/*                                                                           */
/*                          AutonomousMain Task                              */
/*                                                                           */
/*  This task is used to control your robot during the autonomous phase of   */
/*  a VEX Competition.                                                       */
/*                                                                           */
/*---------------------------------------------------------------------------*/

bool firstAutoFlag = true;

void autonomousMain(void) {
  // ..........................................................................
  // The first time we enter this function we will launch our Isolation routine
  // When the field goes disabled after the isolation period this task will die
  // When the field goes enabled for the second time this task will start again
  // and we will enter the interaction period. 
  // ..........................................................................

  if(firstAutoFlag)
    auto_Isolation();
  else 
    auto_Interaction();

  firstAutoFlag = false;
}

int main() {
  void vexcodeInit(void);
  // local storage for latest data from the Jetson Nano
  static AI_RECORD local_map;

  // Run at about 15Hz
  int32_t loop_time = 33;

  // start the status update display
  thread t1(dashboardTask);

  // Set up callbacks for autonomous and driver control periods.
  auto_Isolation();

  // print through the controller to the terminal (vexos 1.0.12 is needed)
  // As USB is tied up with Jetson communications we cannot use
  // printf for debug.  If the controller is connected
  // then this can be used as a direct connection to USB on the controller
  // when using VEXcode.
  //
  //FILE *fp = fopen("/dev/serial2","wb");
  this_thread::sleep_for(loop_time);

  Arm.setVelocity(60, percent);

  while(1) {
      // get last map data
      jetson_comms.get_data( &local_map );

      // set our location to be sent to partner robot
      link.set_remote_location( local_map.pos.x, local_map.pos.y, local_map.pos.az, local_map.pos.status );

      // fprintf(fp, "%.2f %.2f %.2f\n", local_map.pos.x, local_map.pos.y, local_map.pos.az)

      // request new data    
      // NOTE: This request should only happen in a single task.    
      jetson_comms.request_map();

      // Allow other tasks to run
      this_thread::sleep_for(loop_time);
  }
}

Hi @Ultimator!

Can you check the two following things?

  • Does the brain show that it is receiving the packets from the Jetson? (the numbers should be non zero)

  • Are you able to access the Web Dashboard from the Jetson? (you can do this on your laptop by connecting your laptop to the Jetson hotpot and then visiting https://10.42.0.1:3000)

  • What drivetrain do you have?

If you have questions about the things listed above or if this isn’t your problem, let me know.
The more context you can provide about successes and failures the better!

Hi @Mikeyoof25,

The brain shows that there are 0 packets from the jetson. It also shows that all the values are zero, even the GPS.

Yes, I can access the Web Dashboard. However, I am only able to do this through connecting the Jetson to a display and connecting to the network there first.

Our drivetrain is a 2-motor drive.

HI @Ultimator

So this is actually 2 different issues.

To fix the Jetson packets problem,

Make sure that you have 2 vex antennas plugged into the brain. The program seems to get cranky if it doesn’t have both antenna which I believe are needed for the vex link.

To fix the Web dashboard problem
  • On the Jetson wifi dropdown click “Edit Connections”

  • A window with all connections should pop up like the one below

  • Select the hotspot that you created and click the gear icon

*Select the general tab

  • Finally, check the checkbox for automatically connecting to the hotspot

  • If you have connected to another network that always connects on its own, I would suggest that you change such settings on those wifi networks to prevent the Jetson from prioritizing them.

  • At this point, you should be able to restart the Jetson and have no trouble connecting with you laptop

Hope this helps! If you have any questions or get stuck, attach some images and I can walk you through it.

(BTW check to make sure your drive train motors aren’t flipped in the code from their true direction)

1 Like

What do you mean by antennas?

1 Like

Sorry! I meant robot radios

I’ve included an image of one below

1 Like

Once I get multiple antennas to connect, it shows a non-zero amount of packages. But for the Jetson column, there are only zero.

hello , i am a student who have the same problem. can i have your wechat so that i can communicate with you about the problem of the vex ai?

Can you send a picture of the brain screen?

1 Like

Hi @tj-messi,

Unfortunately I don’t have WeChat but if you can take any pictures of your setup and the problems you are encountering I would love to help out! Also, make sure you have done the following:

  • Have 2 vex radios connected to brain
  • Have vex GPS connected to BOTH Jetson and Brain (Edit your code to use the correct port)
  • Have your realsense depth camera plugged into the Jetson
  • Try accessing the web dashboard

The more information you can provide with your holdup, the better equipped I will be to assist!

1 Like

do you have ins ? i want to ask you for more assistance more quickly. on the forum i need to wait for a dat to send a text.it is too long for me…

Sorry I can’t connect outside the forum :(. The mods forbid it

ok , here is my problem。i can receive packet from jetson。
but i want to code the ai-demo to achieve “printing “detected” while the camera find objection” but failed. would you please help me?

in another word.i want to find the information in the v5 brain.i print all the data in the “local_map” but find nothing.

i connect everything and find dashboard on the internet(through the jetson wifi
)

this is my brain picture

i have detected the objection and send back the packet and the data.

but i failed to print it on my vscode

in order to offer you more information about my situation.

here is my ai-demo’s github link

cv-computer-visual-tj/vex_ai视觉方案/vex_ai_24_25 at main · tj-messi/cv-computer-visual-tj (github.com)

all i want to do is print the data on vscode.and then based on the data the camera founded.i want to make some decisions automaticially

but now,i failed to print,so please help me

See the comments in the source code. It’s not easy to use printf as the usual USB serial channel is being used for the Jetson communications.

1 Like

i know that while connecting to the v5 brain by usb,it can not printf.

but i want to make movement if i detect objection .

but i failed,would you help me?

Start simple with just a motor that’s spins if an object is detected. In the meantime I will take a look at you code and help out :slightly_smiling_face:

ok i will try it tomorrow and thank you!