{"mode":"Blocks","hardwareTarget":"brain","workspace":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable id=\"_2.^beQjx|FGt38A,8(E\">myVariable</variable><variable id=\"i!+fr@4x_goQ2$X5^;G.\">block</variable></variables><block type=\"iq_events_when_started\" id=\".NsXwU_L.OuU1l7Sho$F\" x=\"70\" y=\"-10\"><next><block type=\"iq_other_comment\" id=\"Bw|5s|=J!!lYrF,Ek9Tz\"><value name=\"COMMENT\"><shadow type=\"comment_text\" id=\"=`.$^RRM!EPE)a8o$Ol,\"><field name=\"comment\">Turn on the Optical light to allow it to see the block color better</field></shadow></value><next><block type=\"iq_sensing_optical_set_light\" id=\"W}u#IT7FS(c%IPTDug,r\"><field name=\"OPTICAL\">Optical2</field><field name=\"OPTION\">on</field><next><block type=\"iq_other_comment\" id=\"28L/8)9_Yp:LbW~`JB~5\"><value name=\"COMMENT\"><shadow type=\"comment_text\" id=\"-:LiwOV1]0,;N|Wk0zj^\"><field name=\"comment\">This variable changes to which block out of the 5 the robot is currently on</field></shadow></value><next><block type=\"iq_variables_set_variable\" id=\"@}iNg5ic$Dysf05@hNv!\"><field name=\"VARIABLE\" id=\"i!+fr@4x_goQ2$X5^;G.\">block</field><value name=\"VALUE\"><shadow type=\"math_number\" id=\"8C%[!{|aqD*Ng+#MMD**\"><field name=\"NUM\">1</field></shadow></value><next><block type=\"iq_control_repeat\" id=\"2rSC#L6sijldm8=rhXD;\"><value name=\"TIMES\"><shadow type=\"math_whole_number\" id=\"+#=FwQ!,DJ-.Cm0gF)A7\"><field name=\"NUM\">5</field></shadow></value><statement name=\"SUBSTACK\"><block type=\"iq_other_comment\" id=\"F6f1Z$^2-G+lfMCahQ#z\"><value name=\"COMMENT\"><shadow type=\"comment_text\" id=\"z=/=6gUe_MHU#6U0fYyf\"><field name=\"comment\">Move to the block</field></shadow></value><next><block type=\"iq_drivetrain_drive_for\" id=\"u3=3Gu1yFHOK42c:qn+]\"><field name=\"DIRECTION\">fwd</field><field name=\"UNITS\">mm</field><field name=\"anddontwait_mutator\">false</field><value name=\"AMOUNT\"><shadow type=\"math_number\" id=\"e45S50(l4=|q;UXGiYpd\"><field name=\"NUM\">305</field></shadow></value><next><block type=\"iq_drivetrain_turn_for\" id=\"))U^{%ZkZpTh;uO@Xxf+\"><field name=\"TURNDIRECTION\">left</field><field name=\"anddontwait_mutator\">false</field><value name=\"AMOUNT\"><shadow type=\"math_number\" id=\"dBQk1Aa(nBW0MWqz)ma1\"><field name=\"NUM\">90</field></shadow></value><next><block type=\"iq_drivetrain_drive_for\" id=\")gUXsx)MyOJ~UQTXAz7}\"><field name=\"DIRECTION\">fwd</field><field name=\"UNITS\">mm</field><field name=\"anddontwait_mutator\">false</field><value name=\"AMOUNT\"><shadow type=\"math_number\" id=\"v~@gN0v~bknUC:kU%Q=Z\"><field name=\"NUM\">150</field></shadow></value><next><block type=\"iq_control_wait\" id=\"`dnU0H#0[o+rZ){{kt3{\"><value name=\"DURATION\"><shadow type=\"math_positive_number\" id=\"iN8HD%$*L^eTxvkE@!71\"><field name=\"NUM\">1</field></shadow></value><next><block type=\"iq_other_comment\" id=\"N?,2E3zvtFP!HshGyZYf\"><value name=\"COMMENT\"><shadow type=\"comment_text\" id=\"tP+hPRvlJka{FpdkcDmH\"><field name=\"comment\">Detects if the block color is red</field></shadow></value><next><block type=\"iq_control_if_then_else\" id=\"!TWiDq}*#0#i[(n%3*ai\"><value name=\"CONDITION\"><block type=\"iq_sensing_optical_detect\" id=\"H,8]a%9!50^0nuBDQ,@1\"><field name=\"OPTICAL\">Optical2</field><field name=\"COLORS\">red</field></block></value><statement name=\"SUBSTACK\"><block type=\"iq_other_comment\" id=\"X;COyI{?RCE{7Zw9glf[\"><value name=\"COMMENT\"><shadow type=\"comment_text\" id=\"kV!jDI^buASO=+DJVtDX\"><field name=\"comment\">If the block is red the claw will close</field></shadow></value><next><block type=\"iq_motion_spin_for\" id=\"jv]oU.NTAU~xNThh(M7*\"><field name=\"MOTOR\">ClawMotor</field><field name=\"DIRECTION\">fwd</field><field name=\"UNITS\">deg</field><field name=\"anddontwait_mutator\">false</field><value name=\"AMOUNT\"><shadow type=\"math_number\" id=\"GPOGq})MzEX4CGoay$iU\"><field name=\"NUM\">30</field></shadow></value><next><block type=\"iq_drivetrain_drive_for\" id=\"/c`.SK;$Gwi1tKGpA!mI\"><field name=\"DIRECTION\">rev</field><field name=\"UNITS\">mm</field><field name=\"anddontwait_mutator\">false</field><value name=\"AMOUNT\"><shadow type=\"math_number\" id=\"FV9xl2OEZE5(2nXY2g?H\"><field name=\"NUM\">150</field></shadow></value><next><block type=\"iq_drivetrain_turn_for\" id=\"X!)Veq},_ItX=*mm[=b!\"><field name=\"TURNDIRECTION\">right</field><field name=\"anddontwait_mutator\">false</field><value name=\"AMOUNT\"><shadow type=\"math_number\" id=\"d[;}9daoVs(Z(4MV~S+#\"><field name=\"NUM\">90</field></shadow></value><next><block type=\"iq_other_comment\" id=\"XfLyXQTA6{3XxRF#jq.[\"><value name=\"COMMENT\"><shadow type=\"comment_text\" id=\"hq/D38O|ii%^7KNpx3F!\"><field name=\"comment\">1650mm is the distance to the end of the field</field></shadow></value><next><block type=\"iq_other_comment\" id=\"ECQ+#t9$3i0j7*kCy}2x\"><value name=\"COMMENT\"><shadow type=\"comment_text\" id=\"c5H]F.Ro3gDP]BU-/G@?\"><field name=\"comment\">The block times 300mm is subtracted to get the distance from the current block to the end</field></shadow></value><next><block type=\"iq_other_comment\" id=\"J$RaadSPwTb1fJd,u)2[\"><value name=\"COMMENT\"><shadow type=\"comment_text\" id=\"x,:1=QF$n%S._OYe;~Z.\"><field name=\"comment\">E.g. if on the 3rd block, 1650 - 900 = 750 which is the remaining distance to the end</field></shadow></value><next><block type=\"iq_drivetrain_drive_for\" id=\"BIzL5viX_(|RuPs(!cnt\"><field name=\"DIRECTION\">fwd</field><field name=\"UNITS\">mm</field><field name=\"anddontwait_mutator\">false</field><value name=\"AMOUNT\"><shadow xmlns=\"http://www.w3.org/1999/xhtml\" type=\"math_number\" id=\"2=yF6?P4n`2Ak}k)uN+3\"><field name=\"NUM\">200</field></shadow><block type=\"iq_operator_subtract\" id=\"[wW?H(V27TMDVqouJ+YB\"><value name=\"NUM1\"><shadow type=\"math_number\" id=\"%yScSoYz,7NqugkH.LKm\"><field name=\"NUM\">1650</field></shadow></value><value name=\"NUM2\"><shadow xmlns=\"http://www.w3.org/1999/xhtml\" type=\"math_number\" id=\"%kAI{K4*Q0pfM1lwB%bW\"><field name=\"NUM\"></field></shadow><block type=\"iq_operator_multiply\" id=\"*{B+KWuxj![Y=FX~H6,v\"><value name=\"NUM1\"><shadow xmlns=\"http://www.w3.org/1999/xhtml\" type=\"math_number\" id=\"li^}^P:H9Dr#Bg$rvmBZ\"><field name=\"NUM\"></field></shadow><block type=\"iq_variables_variable\" id=\"Z]a`RoiAf4IR4t1`f%!U\"><field name=\"VARIABLE\" id=\"i!+fr@4x_goQ2$X5^;G.\">block</field></block></value><value name=\"NUM2\"><shadow type=\"math_number\" id=\"h;?Q+x[8Uz;%LF0.NOY5\"><field name=\"NUM\">300</field></shadow></value></block></value></block></value><next><block type=\"iq_other_comment\" id=\"[}u1a/Kocfv]cwQoVUm4\"><value name=\"COMMENT\"><shadow type=\"comment_text\" id=\"Ev,f2D*/hJj.}#:Uz9ud\"><field name=\"comment\">Open the claw and go back</field></shadow></value><next><block type=\"iq_motion_spin_to_position\" id=\"eM0.4v_tRm69-V0AUyfU\"><field name=\"MOTOR\">ClawMotor</field><field name=\"UNITS\">deg</field><field name=\"anddontwait_mutator\">false</field><value name=\"AMOUNT\"><shadow type=\"math_number\" id=\"B,;$r2zG7}zibNO_VN*I\"><field name=\"NUM\">0</field></shadow></value><next><block type=\"iq_drivetrain_drive_for\" id=\"3)xs|rXxi`]y=Oi[-^K(\"><field name=\"DIRECTION\">rev</field><field name=\"UNITS\">mm</field><field name=\"anddontwait_mutator\">false</field><value name=\"AMOUNT\"><shadow xmlns=\"http://www.w3.org/1999/xhtml\" type=\"math_number\" id=\"}6[4:uh{@HS,V7.0!?w}\"><field name=\"NUM\">200</field></shadow><block type=\"iq_operator_subtract\" id=\"7m%Ztk)~|Vaeny_pS^_%\"><value name=\"NUM1\"><shadow type=\"math_number\" id=\"DDveOy^v9VH^@giYQ#.n\"><field name=\"NUM\">1650</field></shadow></value><value name=\"NUM2\"><shadow xmlns=\"http://www.w3.org/1999/xhtml\" type=\"math_number\" id=\"F]qD1-XZTLTf.h/NiM=@\"><field name=\"NUM\"></field></shadow><block type=\"iq_operator_multiply\" id=\"S%#C|nZp+/}~M.x~S~^$\"><value name=\"NUM1\"><shadow xmlns=\"http://www.w3.org/1999/xhtml\" type=\"math_number\" id=\"/qY6U6h5|Bw=Tf(1@qVk\"><field name=\"NUM\"></field></shadow><block type=\"iq_variables_variable\" id=\"v5R*-lp65N7[W0tbea2Z\"><field name=\"VARIABLE\" id=\"i!+fr@4x_goQ2$X5^;G.\">block</field></block></value><value name=\"NUM2\"><shadow type=\"math_number\" id=\"$TcDsHMRq:_6I/z~V49!\"><field name=\"NUM\">300</field></shadow></value></block></value></block></value><next><block type=\"iq_other_comment\" id=\"sAm)P#=eM[%1RoGy:d[g\"><value name=\"COMMENT\"><shadow type=\"comment_text\" id=\"N)$j44KgjW!A(D8-Eih|\"><field name=\"comment\">Changes the variable as it is now moving onto the next block</field></shadow></value><next><block type=\"iq_variables_change_variable\" id=\"YqH3Zh!4hyrLoqT/J*4|\"><field name=\"VARIABLE\" id=\"i!+fr@4x_goQ2$X5^;G.\">block</field><value name=\"VALUE\"><shadow type=\"math_number\" id=\"-oyA82bF,IUvTx;9D9$_\"><field name=\"NUM\">1</field></shadow></value></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></statement><statement name=\"SUBSTACK2\"><block type=\"iq_other_comment\" id=\"_V)WH3VI*M3SbfCz{Mz)\"><value name=\"COMMENT\"><shadow type=\"comment_text\" id=\"Dy+[W~qF:HBVxY1z8((g\"><field name=\"comment\">If the block is not red then the robot will drive back to the center</field></shadow></value><next><block type=\"iq_drivetrain_drive_for\" id=\"(AFh?:kOe,a#dWL$le:6\"><field name=\"DIRECTION\">rev</field><field name=\"UNITS\">mm</field><field name=\"anddontwait_mutator\">false</field><value name=\"AMOUNT\"><shadow type=\"math_number\" id=\"vXc^q,)xBLN8B%|jNiB.\"><field name=\"NUM\">150</field></shadow></value><next><block type=\"iq_drivetrain_turn_for\" id=\"p{k~:fpBNei;L^%W+y+@\"><field name=\"TURNDIRECTION\">right</field><field name=\"anddontwait_mutator\">false</field><value name=\"AMOUNT\"><shadow type=\"math_number\" id=\"0AX4zO0.nZ#gw%tjp)!j\"><field name=\"NUM\">90</field></shadow></value><next><block type=\"iq_other_comment\" id=\",w$S9~!N!-gZ^?BVAOMR\"><value name=\"COMMENT\"><shadow type=\"comment_text\" id=\"~o_S*WN18YkCst*7D?:|\"><field name=\"comment\">Changes the variable as it is now moving onto the next block</field></shadow></value><next><block type=\"iq_variables_change_variable\" id=\"Wxph2;IN#aW6b=wZuFxB\"><field name=\"VARIABLE\" id=\"i!+fr@4x_goQ2$X5^;G.\">block</field><value name=\"VALUE\"><shadow type=\"math_number\" id=\"QR7mU+rOLs9Z}rXg7cYh\"><field name=\"NUM\">1</field></shadow></value></block></next></block></next></block></next></block></next></block></statement></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></next></block></next></block></next></block></next></block></next></block></xml>","robotConfig":[{"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"},"triportSourcePort":22},{"port":[4],"name":"ClawMotor","customName":true,"deviceType":"Motor","deviceClass":"motor","setting":{"reversed":"false","fwd":"forward","rev":"reverse"},"triportSourcePort":22},{"port":[2],"name":"Optical2","customName":false,"deviceType":"Optical","deviceClass":"optical","setting":{},"triportSourcePort":22}],"slot":0,"platform":"IQ","sdkVersion":"20230818.11.00.00","appVersion":"4.0.7","minVersion":"3.0.0","fileFormat":"1.3.0","targetBrainGen":"Second","v5SoundsEnabled":false,"downloadLanguage":"python","cppStatus":"true","cpp":"// Make sure all required headers are included.\n#include <stdio.h>\n#include <stdlib.h>\n#include <stdbool.h>\n#include <math.h>\n#include <string.h>\n\n\n#include \"vex.h\"\n\nusing namespace vex;\n\n// Brain should be defined by default\nbrain Brain;\n\n\n// START IQ MACROS\n#define waitUntil(condition)                                                   \\\n  do {                                                                         \\\n    wait(5, msec);                                                             \\\n  } while (!(condition))\n\n#define repeat(iterations)                                                     \\\n  for (int iterator = 0; iterator < iterations; iterator++)\n// END IQ MACROS\n\n\n// Robot configuration code.\ninertial BrainInertial = inertial();\nmotor LeftDriveSmart = motor(PORT1, 1, false);\nmotor RightDriveSmart = motor(PORT6, 1, true);\n\nsmartdrive Drivetrain = smartdrive(LeftDriveSmart, RightDriveSmart, BrainInertial, 200);\n\nmotor ClawMotor = motor(PORT4, false);\noptical Optical2 = optical(PORT2);\n\n\n// generating and setting random seed\nvoid initializeRandomSeed(){\n  wait(100,msec);\n  double xAxis = BrainInertial.acceleration(xaxis) * 1000;\n  double yAxis = BrainInertial.acceleration(yaxis) * 1000;\n  double zAxis = BrainInertial.acceleration(zaxis) * 1000;\n  // Combine these values into a single integer\n  int seed = int(\n    xAxis + yAxis + zAxis\n  );\n  // Set the seed\n  srand(seed); \n}\n\nbool vexcode_initial_drivetrain_calibration_completed = false;\nvoid calibrateDrivetrain() {\n  wait(200, msec);\n  Brain.Screen.print(\"Calibrating\");\n  Brain.Screen.newLine();\n  Brain.Screen.print(\"Inertial\");\n  BrainInertial.calibrate();\n  while (BrainInertial.isCalibrating()) {\n    wait(25, msec);\n  }\n  vexcode_initial_drivetrain_calibration_completed = true;\n  // Clears the screen and returns the cursor to row 1, column 1.\n  Brain.Screen.clearScreen();\n  Brain.Screen.setCursor(1, 1);\n}\n\nvoid vexcodeInit() {\n\n  // Calibrate the Drivetrain\n  calibrateDrivetrain();\n\n  // Initializing random seed.\n  initializeRandomSeed(); \n}\n\n\n// Generated code.\n\n// Include the IQ Library\n#include \"vex.h\"\n  \n// Allows for easier use of the VEX Library\nusing namespace vex;\n\nfloat myVariable, block;\n\n// \"when started\" hat block\nint whenStarted1() {\n  // Turn on the Optical light to allow it to see the block color better\n  Optical2.setLight(ledState::on);\n  // This variable changes to which block out of the 5 the robot is currently on\n  block = 1.0;\n  repeat(5) {\n    // Move to the block\n    Drivetrain.driveFor(forward, 305.0, mm, true);\n    Drivetrain.turnFor(left, 90.0, degrees, true);\n    Drivetrain.driveFor(forward, 150.0, mm, true);\n    wait(1.0, seconds);\n    // Detects if the block color is red\n    if (Optical2.color() == red) {\n      // If the block is red the claw will close\n      ClawMotor.spinFor(forward, 30.0, degrees, true);\n      Drivetrain.driveFor(reverse, 150.0, mm, true);\n      Drivetrain.turnFor(right, 90.0, degrees, true);\n      // 1650mm is the distance to the end of the field\n      // The block times 300mm is subtracted to get the distance from the current block to the end\n      // E.g. if on the 3rd block, 1650 - 900 = 750 which is the remaining distance to the end\n      Drivetrain.driveFor(forward, (1650.0 - block * 300.0), mm, true);\n      // Open the claw and go back\n      ClawMotor.spinToPosition(0.0, degrees, true);\n      Drivetrain.driveFor(reverse, (1650.0 - block * 300.0), mm, true);\n      // Changes the variable as it is now moving onto the next block\n      block = block + 1.0;\n    }\n    else {\n      // If the block is not red then the robot will drive back to the center\n      Drivetrain.driveFor(reverse, 150.0, mm, true);\n      Drivetrain.turnFor(right, 90.0, degrees, true);\n      // Changes the variable as it is now moving onto the next block\n      block = block + 1.0;\n    }\n    wait(20, msec);\n  }\n  return 0;\n}\n\n\nint main() {\n  // Initializing Robot Configuration. DO NOT REMOVE!\n  vexcodeInit();\n\n  whenStarted1();\n}","target":"Physical"}