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);
}
}