/*----------------------------------------------------------------------------*/
/* */
/* Module: main.cpp */
/* Author: james */
/* 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(PORT4, 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;
static AI_RECORD local_map;
/*----------------------------------------------------------------------------*/
// 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()));
// Set brake mode for the arm
Arm.setStopping(brakeType::hold);
// Reset the position of the arm while its still on the ground
Arm.resetPosition();
// Lift the arm to prevent dragging
Arm.spinTo(75, rotationUnits::deg);
// 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);
if(local_map.detectionCount>0)
{
Arm.spin(fwd);
}
}
/*---------------------------------------------------------------------------*/
/* */
/* 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) {
if(local_map.detectionCount>0)
{
Arm.spin(fwd);
}
// 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() {
// 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);//打开一个在v5 brain 主控上执行的broad
// Set up callbacks for autonomous and driver control periods.
Competition.autonomous(autonomousMain);
// 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();
//printf("%d %d %d \n", local_map.detections[0].screenLocation.x,local_map.detections[0].screenLocation.y,local_map.detectionCount);
// Allow other tasks to run
this_thread::sleep_for(loop_time);
if(local_map.detectionCount>0)
{
Arm.spin(fwd);
}
/*
jetson_comms.get_data( &local_map );
printf("%d %d %d \n", local_map.detections[0].screenLocation.x,local_map.detections[0].screenLocation.y,local_map.detectionCount);
this_thread::sleep_for(loop_time);
jetson_comms.get_data( &local_map );
printf("%d %d %d \n", local_map.detections[0].screenLocation.x,local_map.detections[0].screenLocation.y,local_map.detectionCount);
this_thread::sleep_for(loop_time);
this_thread::sleep_for(loop_time);
*/
}
}
that is my code but it doesn’t work properly.can you help me?

