{"mode":"Text","hardwareTarget":"brain","textContent":"#region VEXcode Generated Robot Configuration\nfrom vex import *\nimport urandom\nimport math\n\n# Brain should be defined by default\nbrain=Brain()\n\n# Robot configuration code\nleft_drive_smart = Motor(Ports.PORT1, GearSetting.RATIO_18_1, False)\nright_drive_smart = Motor(Ports.PORT10, GearSetting.RATIO_18_1, True)\ndrivetrain = DriveTrain(left_drive_smart, right_drive_smart, 319.19, 295, 40, MM, 1)\noptical_2 = Optical(Ports.PORT2)\n\n\n# wait for rotation sensor to fully initialize\nwait(30, MSEC)\n\n\n# Make random actually random\ndef initializeRandomSeed():\n    wait(100, MSEC)\n    random = brain.battery.voltage(MV) + brain.battery.current(CurrentUnits.AMP) * 100 + brain.timer.system_high_res()\n    urandom.seed(int(random))\n      \n# Set random seed \ninitializeRandomSeed()\n\n\n# Color to String Helper\ndef convert_color_to_string(col):\n    if col == Color.RED:\n        return \"red\"\n    if col == Color.GREEN:\n        return \"green\"\n    if col == Color.BLUE:\n        return \"blue\"\n    if col == Color.WHITE:\n        return \"white\"\n    if col == Color.YELLOW:\n        return \"yellow\"\n    if col == Color.ORANGE:\n        return \"orange\"\n    if col == Color.PURPLE:\n        return \"purple\"\n    if col == Color.CYAN:\n        return \"cyan\"\n    if col == Color.BLACK:\n        return \"black\"\n    if col == Color.TRANSPARENT:\n        return \"transparent\"\n    return \"\"\n\ndef play_vexcode_sound(sound_name):\n    # Helper to make playing sounds from the V5 in VEXcode easier and\n    # keeps the code cleaner by making it clear what is happening.\n    print(\"VEXPlaySound:\" + sound_name)\n    wait(5, MSEC)\n\n# add a small delay to make sure we don't print in the middle of the REPL header\nwait(200, MSEC)\n# clear the console to make sure we don't have the REPL in the console\nprint(\"\\033[2J\")\n\n#endregion VEXcode Generated Robot Configuration\n\n# Import necessary libraries from the VEX Robotics module\nfrom vex import *\n\ndef begin_sd_datalogging():\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\ndatalog_thread = Thread(begin_sd_datalogging)\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(10,PERCENT)\ndrivetrain.drive_for(FORWARD,400,MM,wait=False);","textLanguage":"python","robotConfig":[{"port":[1,10,0],"name":"drivetrain","customName":false,"deviceType":"Drivetrain","deviceClass":"smartdrive","setting":{"type":"2-motor","wheelSize":"wheel4in","gear":"ratio18_1","gearRatio":"1:1","direction":"fwd","gyroType":"none","width":"295","unit":"mm","wheelbase":"40","wheelbaseUnit":"mm","xOffset":"0","xOffsetUnit":"mm","yOffset":"0","yOffsetUnit":"mm","thetaOffset":"180"},"triportSourcePort":null},{"port":[2],"name":"optical_2","customName":false,"deviceType":"Optical","deviceClass":"optical","setting":{},"triportSourcePort":22}],"slot":0,"platform":"V5","sdkVersion":"20240802.15.00.00","appVersion":"4.65.0","minVersion":"4.60.0","fileFormat":"2.0.0","targetBrainGen":"First","v5Sounds":[{"name":"game over","url":"static/sounds/mixkit-arcade-retro-game-over-213.wav"}],"v5SoundsEnabled":false,"aiVisionSettings":{"colors":[],"codes":[],"tags":true,"AIObjects":true,"AIObjectModel":[],"aiModelDropDownValue":null},"target":"Physical"}