u/DaGamesFanatic

Image 1 — Cool monster flowers I make
Image 2 — Cool monster flowers I make
Image 3 — Cool monster flowers I make
Image 4 — Cool monster flowers I make

Cool monster flowers I make

Im sure im not the first person to come up with this, but I’ve not seen anyone else do it! In the first one, the one on the left is for someone I like, and the one on the right is for someone I do not, lol

u/DaGamesFanatic — 3 days ago
▲ 2 r/vex+1 crossposts

#pragma region VEXcode Generated Robot Configuration

// Make sure all required headers are included.

#include <stdio.h>

#include <stdlib.h>

#include <stdbool.h>

#include <math.h>

#include <string.h>

#include "vex.h"

using namespace vex;

// Brain should be defined by default

brain Brain;

// START EXP MACROS

#define waitUntil(condition)                                                   \

  do {                                                                         \

    wait(5, msec);                                                             \

  } while (!(condition))

#define repeat(iterations)                                                     \

  for (int iterator = 0; iterator < iterations; iterator++)

// END EXP MACROS

// Robot configuration code.

inertial BrainInertial = inertial();

// generating and setting random seed

void initializeRandomSeed(){

  wait(100,msec);

  double xAxis = BrainInertial.acceleration(xaxis) * 1000;

  double yAxis = BrainInertial.acceleration(yaxis) * 1000;

  double zAxis = BrainInertial.acceleration(zaxis) * 1000;

  // Combine these values into a single integer

  int seed = int(

    xAxis + yAxis + zAxis

  );

  // Set the seed

  srand(seed);

}

void vexcodeInit() {

  // Initializing random seed.

  initializeRandomSeed(); 

}

#pragma endregion VEXcode Generated Robot Configuration

// ── VEXcode EXP Soccer Robot – 4WD, Blue Ball ───────────────────────── 

// Hardware: 

// Motors : frontLeft→PORT1 frontRight→PORT2 

// rearLeft →PORT3 rearRight →PORT4 

// Distance: PORT8 

// Color : PORT9 

// Switches: frontLeft→PORT5 frontRight→PORT6 

// rearLeft →PORT7 rearRight →PORT10 

// Robot is 4WD skid-steer, max width < 2 ft (610 mm). 

// Arena ~4 x 5 ft (~1220 x 1520 mm). Blue ball. 

// ────────────────────────────────────────────────────────────────────────

#include "vex.h" 

using namespace vex; 

// ── Hardware ────────────────────────────────────────────────────────────── 

motor motorFrontLeft (PORT1, ratio18_1, false); 

motor motorFrontRight(PORT2, ratio18_1, true); // reversed for skid-steer 

motor motorRearLeft (PORT3, ratio18_1, false); 

motor motorRearRight (PORT4, ratio18_1, true); // reversed for skid-steer 

distance distSensor(PORT8); 

optical colorSensor(PORT9); 

digital_in swFrontLeft (Brain.ThreeWirePort.A);

digital_in swFrontRight(Brain.ThreeWirePort.B);

digital_in swRearLeft  (Brain.ThreeWirePort.C);

digital_in swRearRight (Brain.ThreeWirePort.D);

// ── Tunable constants ───────────────────────────────────────────────────── 

const int DRIVE_SPEED = 60; 

const int KICK_SPEED = 100; 

const int TURN_SPEED = 40; 

const int SEARCH_TURN_SPEED = 30; 

const float APPROACH_DIST_MM = 200.0; 

const float KICK_DIST_MM = 80.0; 

const int KICK_DURATION_MS = 300; 

const int BACKUP_MS = 400; 

const int TURN_MS = 350; 

// Blue ball: hue ~200–240, brightness threshold 

const float BALL_HUE_MIN = 180.0; 

const float BALL_HUE_MAX = 250.0; 

const int BALL_BRIGHTNESS = 50; 

// ── State machine ───────────────────────────────────────────────────────── 

enum State { SEARCH, APPROACH, AIM, KICK, WALL_AVOID }; 

State currentState = SEARCH; 

// ── Motor helpers ────────────────────────────────────────────────────────── 

void setLeftSide(directionType dir, int pct) 

  { 

  motorFrontLeft.spin(dir, pct, percent); 

  motorRearLeft.spin(dir, pct, percent); 

  } 

void setRightSide(directionType dir, int pct) 

  { 

  motorFrontRight.spin(dir, pct, percent); 

  motorRearRight.spin(dir, pct, percent); 

  }

  

void driveForward(int pct) 

  { 

    setLeftSide(fwd, pct); 

    setRightSide(fwd, pct); 

  } 

  

void driveReverse(int pct) 

  { 

    setLeftSide(reverse, pct); 

    setRightSide(reverse, pct); 

  } 

  

void turnLeft(int pct) 

  { 

    setLeftSide(reverse, pct); 

    setRightSide(fwd, pct); 

  } 

  

void turnRight(int pct) 

  { 

    setLeftSide(fwd, pct); 

    setRightSide(reverse, pct);

  } 

  

void stopDrive() 

  { 

    motorFrontLeft.stop(brake); 

    motorFrontRight.stop(brake); 

    motorRearLeft.stop(brake); 

    motorRearRight.stop(brake); 

  } 

  

// ── Sensor helpers ──────────────────────────────────────────────────────── 

  

bool frontHit() 

  {

    return swFrontLeft.value() || swFrontRight.value(); 

  } 

  

bool rearHit() 

  { 

    return swRearLeft.value() || swRearRight.value(); 

  } 

  

  bool ballVisible() 

  { 

    colorSensor.setLight(ledState::on); 

    float hue = colorSensor.hue(); 

    int bright = colorSensor.brightness(); 

    return (bright > BALL_BRIGHTNESS) && (hue >= BALL_HUE_MIN && hue <= BALL_HUE_MAX); 

  } 

  

  float ballDist() 

  { 

    return distSensor.isObjectDetected() ? distSensor.objectDistance(mm) : 9999.0; 

  } 

  

// ── State handlers ──────────────────────────────────────────────────────── 

  

int searchDir = 1; 

int searchTicks = 0; 

  

void handleSearch() 

  { 

    Brain.Screen.clearScreen();

    Brain.Screen.setCursor(1,1);

    Brain.Screen.print("Hue");

    Brain.Screen.print(colorSensor.hue());

    Brain.Screen.newLine();

    Brain.Screen.print("Bright: ");

    Brain.Screen.print(colorSensor.brightness());

    Brain.Screen.newLine();

    Brain.Screen.print("Ball: ");

    Brain.Screen.print(ballVisible() ? "YES" : "NO");

    wait(100, msec);

    if (frontHit() || rearHit()) 

    { 

      currentState = WALL_AVOID; return; 

    } 

    

    else if (ballVisible()) 

    { 

      currentState = APPROACH; 

      return; 

    } 

    

    else if (searchDir == 1) turnRight(SEARCH_TURN_SPEED); 

    

    else turnLeft(SEARCH_TURN_SPEED); 

    

    searchTicks++; 

    

    if (searchTicks > 150) 

    { 

      searchDir = -searchDir; 

      searchTicks = 0; 

    } 

  } 

  

void handleApproach() 

  { 

    if (frontHit()) 

      { 

        currentState = WALL_AVOID; return; 

      } 

      

    if (!ballVisible()) 

      { 

        currentState = SEARCH; 

        return; 

      } 

      

      float d = ballDist(); 

    if (d < APPROACH_DIST_MM) 

      { 

        currentState = AIM; 

        return; 

      } 

      

      // Proportional slow-down as we close in 

      

    int speed = (int)(DRIVE_SPEED * (d / 400.0)); 

    if (speed < 25) speed = 25; 

    if (speed > DRIVE_SPEED) speed = DRIVE_SPEED; 

    driveForward(speed); 

  } 

  

  void handleAim() 

  { 

    if (frontHit()) 

      { 

        currentState = WALL_AVOID; 

        return; 

      } 

      

    if (!ballVisible()) 

      { 

        currentState = SEARCH; 

        return; 

      } 

      

      float d = ballDist(); 

      if (d < KICK_DIST_MM) 

        { 

          currentState = KICK; 

          return; 

        } 

        

        driveForward(30); // creep forward 

  } 

  

void handleKick() 

  { 

    stopDrive(); 

    wait(80, msec); 

    driveForward(KICK_SPEED); 

    wait(KICK_DURATION_MS, msec); 

    stopDrive(); 

    currentState = SEARCH; 

  } 

  

void handleWallAvoid() 

  { 

    stopDrive(); 

    bool fl = swFrontLeft.value(); 

    bool fr = swFrontRight.value(); 

    if (fl || fr) 

      { 

        driveReverse(DRIVE_SPEED); 

        wait(BACKUP_MS, msec); 

        stopDrive(); 

        if (fl && !fr) turnRight(TURN_SPEED); 

        else if (fr && !fl) turnLeft(TURN_SPEED); 

        else turnRight(TURN_SPEED); 

        wait(TURN_MS, msec); 

      } 

    else 

      { 

        // Rear switch hit 

        driveForward(DRIVE_SPEED); 

        wait(BACKUP_MS, msec); 

        stopDrive(); 

        if (swRearLeft.value()) turnRight(TURN_SPEED); 

        else turnLeft(TURN_SPEED); 

        wait(TURN_MS, msec); 

      } 

      stopDrive(); 

      searchTicks = 0; 

      currentState = SEARCH; 

  } 

  

// ── Main ────────────────────────────────────────────────────────────────── 

int main() 

  { 

    colorSensor.setLight(ledState::on); 

    colorSensor.setLightPower(100, percent); 

    Brain.Screen.print("4WD Soccer Bot Ready"); 

    const char* stateNames[] = { "SEARCH", "APPROACH", "AIM", "KICK", "WALL_AVOID" }; 

    

    while (true) 

      { 

        // Wall hit overrides any state except WALL_AVOID itself 

        

        if (currentState != WALL_AVOID && (frontHit() || rearHit())) currentState = WALL_AVOID; 

        switch (currentState) 

          { 

            case SEARCH: handleSearch(); 

            break; 

            case APPROACH: handleApproach(); 

            break; 

            case AIM:  handleAim(); 

            break; 

            case KICK: handleKick(); 

            break; 

            case WALL_AVOID: handleWallAvoid(); 

            break; 

          } 

          

        Brain.Screen.clearScreen(); 

        Brain.Screen.setCursor(1, 1); 

        Brain.Screen.print(stateNames[currentState]); 

        Brain.Screen.newLine(); 

        Brain.Screen.print("Hue: "); 

        Brain.Screen.print(colorSensor.hue()); 

        Brain.Screen.newLine(); 

        Brain.Screen.print("Dist: "); 

        if (distSensor.isObjectDetected()) Brain.Screen.print(distSensor.objectDistance(mm)); 

        else Brain.Screen.print("--"); wait(10, msec); 

      } 

  }
reddit.com
u/DaGamesFanatic — 23 days ago