{"mode":"Text","textContent":"#region VEXcode Generated Robot Configuration\nfrom vex import *\nimport urandom\n\n# Brain should be defined by default\nbrain=Brain()\n\n# Robot configuration code\nbrain_inertial = Inertial()\noptical_2 = Optical(Ports.PORT2)\nleft_drive_smart = Motor(Ports.PORT1, 1.0, False)\nright_drive_smart = Motor(Ports.PORT6, 1.0, True)\n\ndrivetrain = SmartDrive(left_drive_smart, right_drive_smart, brain_inertial, 200)\n\n\n\n# Make random actually random\ndef setRandomSeedUsingAccel():\n    wait(100, MSEC)\n    xaxis = brain_inertial.acceleration(XAXIS) * 1000\n    yaxis = brain_inertial.acceleration(YAXIS) * 1000\n    zaxis = brain_inertial.acceleration(ZAXIS) * 1000\n    urandom.seed(int(xaxis + yaxis + zaxis))\n    \n# Set random seed \nsetRandomSeedUsingAccel()\n\nvexcode_initial_drivetrain_calibration_completed = False\ndef calibrate_drivetrain():\n    # Calibrate the Drivetrain Inertial\n    global vexcode_initial_drivetrain_calibration_completed\n    sleep(200, MSEC)\n    brain.screen.print(\"Calibrating\")\n    brain.screen.next_row()\n    brain.screen.print(\"Inertial\")\n    brain_inertial.calibrate()\n    while brain_inertial.is_calibrating():\n        sleep(25, MSEC)\n    vexcode_initial_drivetrain_calibration_completed = True\n    brain.screen.clear_screen()\n    brain.screen.set_cursor(1, 1)\n\n#endregion VEXcode Generated Robot Configuration\n\n# ------------------------------------------\n# \n# \tProject:      VEXcode Project\n# \tAuthor:       VEX\n# \tCreated:\n# \tDescription:  VEXcode IQ Python Project\n# \n# ------------------------------------------\n\n# Library imports\nfrom vex import *\n\n# Begin project code\ndef begin_sd_data_logging():\n    # Ensure SD card compatibility: The SD card must be formatted as FAT32.\n    # It is advised to use SD cards with a capacity of 32GB or less to avoid formatting issues.\n\n    # Configuration variables\n    sd_file_name = \"dataLog1.csv\"  # Name of the CSV file to be saved on the SD card\n    polling_delay_msec = 40  # Delay between each data polling in milliseconds\n    numOfDataEntries = 100  # Total number of data entries to be recorded\n    data_buffer = 0 # Create buffer of data to write to SD card\n    \n    # Setup CSV Header\n    data_buffer = \"time,brightness,hue,color\"\n    data_buffer += \"\\n\"\n\n    # Check for SD card insertion and hold the program if absent\n    if not brain.sdcard.is_inserted():\n        brain.screen.set_cursor(1,1)\n        brain.screen.print(\"SD Card Missing\")\n        # Infinite loop to prevent program progress until an SD card is inserted\n        while(True):\n            wait(5, MSEC)\n\n    # Reset the brain timer before starting data collection\n    brain.timer.clear();\n\n    # Data collection loop: Generate and append data entries to the buffer\n    for i in range(numOfDataEntries):    \n        # Append the current timer value to the buffer\n        data_buffer += \"%1.3f\" % brain.timer.value()\n        data_buffer += \",\"\n\n        # Append the brightness value from the optical sensor to the buffer\n        data_buffer += \"%.0f\" % optical_2.brightness()\n        data_buffer += \",\"\n\n        # Append the hue value from the optical sensor to the buffer\n        data_buffer += \"%.0f\" % optical_2.hue()\n        data_buffer += \",\"\n\n        # Use a conditional block to match the sensor's color output to a color name\n        if   optical_2.color() == Color.BLACK:\n            data_buffer += \"Black\"\n        elif optical_2.color() == Color.WHITE:\n            data_buffer += \"White\"\n        elif optical_2.color() == Color.RED:\n            data_buffer += \"Red\"\n        elif optical_2.color() == Color.GREEN:\n            data_buffer += \"Green\"\n        elif optical_2.color() == Color.BLUE:\n            data_buffer += \"Blue\"       \n        elif optical_2.color() == Color.YELLOW:\n            data_buffer += \"Yellow\"\n        elif optical_2.color() == Color.ORANGE:\n            data_buffer += \"Orange\"\n        elif optical_2.color() == Color.PURPLE:\n            data_buffer += \"Purple\"\n        elif optical_2.color() == Color.CYAN:\n            data_buffer += \"Cyan\"\n        else:\n            data_buffer += \"None\"\n\n        # Append a newline to separate this entry from the next\n        data_buffer += \"\\n\"\n\n        # Pause before the next iteration to respect the polling delay\n        wait(polling_delay_msec, MSEC)\n\n    # Attempt to write the collected data to the SD card and report the result\n    brain.screen.set_cursor(1,1)\n    if brain.sdcard.savefile(sd_file_name, bytearray(data_buffer)) == 0:\n        brain.screen.print(\"SD Write Error\")  # Display an error if the write operation failed\n    else:\n        brain.screen.print(\"Data Written\")  # Confirm that data has been written to the SD card\n\ndata_log_thread = Thread(begin_sd_data_logging)\n\n# Set up the optical sensor: Turn on the LED and set its power to full\noptical_2.set_light(LedStateType.ON)\noptical_2.set_light_power(100)\n\ndrivetrain.set_drive_velocity(15, PERCENT)\ndrivetrain.drive_for(FORWARD, 350, MM)","textLanguage":"python","rconfig":[{"port":[2],"name":"optical_2","customName":false,"deviceType":"Optical","deviceClass":"optical","setting":{}},{"port":[1,6,0],"name":"drivetrain","customName":false,"deviceType":"Drivetrain","deviceClass":"smartdrive","setting":{"type":"2-motor","wheelSize":"200mm","gearRatio":"1:1","direction":"fwd","gyroType":"integrated","width":"173","unit":"mm","wheelbase":"76","wheelbaseUnit":"mm","xOffset":"0","yOffset":"0","thetaOffset":"0"}}],"slot":0,"platform":"IQ","sdkVersion":"20230818.11.00.00","appVersion":"3.0.4","minVersion":"3.0.0","fileFormat":"1.2.0","icon":"","targetBrainGen":"Second","v5SoundsEnabled":false,"target":"Physical"}