V5 Vision Sensor with Python

Would anyone happen to have the code for a vision sensor using python, I am at a loss trying to find code
Thanks in advance

Camera Aiming - Python

import vex

#region config
brain          = vex.Brain();
vision_9       = vex.Vision(vex.Ports.PORT9)
sig_TARGETBLOB = vex.VisionSignature(1,101,3217,1659,-4681,-3869,-4275,2.3,0)
vision_9.set_brightness(50);
vision_9.set_signature(sig_TARGETBLOB)
motor_right    = vex.Motor(vex.Ports.PORT15, vex.GearSetting.RATIO18_1, True)
motor_left     = vex.Motor(vex.Ports.PORT16, vex.GearSetting.RATIO18_1, False)
dt             = vex.Drivetrain(motor_left, motor_right, 319.1764, 292.1, vex.DistanceUnits.MM)
#endregion config

screen_middle_x = None
linedup = None


# main thread
# Camera image is 316x212, so 316/2 is the middle
screen_middle_x = 316 / 2
linedup = False
# We're going to be turning, but don't
# need to do so quickly.
dt.set_velocity(5, vex.VelocityUnits.PCT)
while not linedup:
  # Snap a picture
  vision_9.take_snapshot(sig_TARGETBLOB)
  # Did we see anything that we were looking for?
  if vision_9.object_count > 0:
    # Largest thing to the left, right, or middle?
    if vision_9.largest_object.centerX < screen_middle_x - 5:
      # On the left, turn towards it
      dt.turn(vex.TurnType.LEFT)
    elif vision_9.largest_object.centerX > screen_middle_x + 5:
      # On the right, turn towards it
      dt.turn(vex.TurnType.RIGHT)
    else:
      # In the middle! We're done lining up.
      linedup = True
      dt.stop(vex.BrakeType.COAST)
  else:
    # Saw nothing, relax
    dt.stop(vex.BrakeType.COAST)

Is using python for V5 more efficient and advanced than for vex C++, thanks

Sensors values change slowly enough and the V5’s processor is fast enough that which language you use is down to personal preference. As long as you aren’t writing O(n!) algorithms, anyway.

I’ll be implementing bogobogosort (O(n!^(n!))) on my robot this year. What software stack will allow me to most efficiently sort things inefficiently?

/s

I’d recommend using LISP to code a Python emulator which simulates a Dartmouth BASIC interpreter. That should work great.

1 Like

Great! I’ll be sure to set that up inside my favorite development environment.