Skip to content
This repository has been archived by the owner on Feb 2, 2024. It is now read-only.
/ VexEmulator Public archive

A V5 brain emulator that can run most .v5python programs

License

Notifications You must be signed in to change notification settings

DylanBruner/VexEmulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

84 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VEX v5 Brain Emulator



Note: Vex, if you see this and want me to remove the assets for some reason create a issue and i'll remove them


This is still very much in development if you find a issue, report it and i'll try to get around to fixing it asap


What it is and isn't

  • It's not, a virtual machine that can run C++ programs

    • It is, a pygame powered interface that's capable of running VEX v5python programs
  • It's not, (at least not yet) a full simulation, the devices dont talk to each other to figure out location data and such

    • It is, a way to test programs without a brain, the web interface can be used to simulate the devices actually being there
  • It's not, a professional grade emulator

    • It is, a hobby project, I've created this as a side project so bugs are to be expected
  • It's not, a seemless replacment for a physical brain

    • It is, a emulator that supports most devices (eventually will support all)

Currently Supported Devices

  • All devices

  • Core Devices

    • Controller
    • Motor
    • Motor Group
    • Drivetrain (Only 2-Wheel at the moment) (No Inertial, Gps or Gyro)
    • Electro Magnet
    • Gyroscope
    • Optical Sensor (not tested)
    • Distance Sensor
    • Rotation Sensor
    • Inertial Sensor
    • Vision Sensor
    • Gps
  • Three wire (Most un-tested)

    • Bumper
    • Limit Switch
    • Encoder
    • Range Finder
    • Line Tracker
    • Light
    • Potentiometer
    • PotentiometerV2
    • Motor 393
    • Servo
    • Led
    • Accel 2g
    • Accel 6g
    • Digital In
    • Digital Out

List of Features

  • "Virtual" SDCard, supports writing to files stored in data/emulatedstorage/SDCard
  • Can select/view up to 18 programs on the brain
  • You can check if running on the real brain or the emulated one by checking if any devices have the _attributes attributes, for example
    • hasattr(brain, '_attributes')
  • The attributes of all devices can be controlled from the web server
  • Emulates/Redirects functions like 'Thread' and 'wait' to their respective external libraries
  • Test Competitions can be ran using the webserver as a competition switch
  • Screenshot support s key
  • Command line from which you can automatically launch programs, disable or modify the web server, disable program scanning and possibly more in the future
  • A non-documented api (Same as the api used on the vds, check virtualdeviceserver.py to see all available routes) which can be used to run tests on the brain, or even emulate devices better by editing their attributes
    • Note the api doesn't require authentication but this isn't really a problome for a few reasons
      1. This is supposed be used in test enviorments not in production
      2. It defaults to localhost
      3. You cant (as of now) run any code you want from the api just files already on the computer



Planned ToDos

  • For the brain
    • Clean up code
    • Drivetrain w Inertial support!
    • Four motor Drivetrain
    • Maybe use physical controller on the emulated brain not sure about the practicality of this
    • Register the brain's battery as a emulated device that way the web UI can control it's attributes
    • Maybe fix the emulator dragging (stop it from snapping)
    • Try to dump assets from the offical brain that way it will look 1000x better
    • Show which ports are ocupied when a program is running
    • Maybe a ability to limit the Clock Speed of the emulator along with the max amount of memory it can use
    • Maybe make all the devices work together, like if the drivetrain is told to move, update the location were supposed to be at and tell all the other devices to update their attributes (Would probably require a fairly exstensive rewrite)

    • Interesting Possible Features
      • Try to inject code into VEX Code that will launch the emulator when the run button is clicked without a brain connected
        • Or possibly use a virtual serial device and pretend to be a real brain (not sure how hard this would be to do)


  • For the webserver
    • Make the UI look a lot nicer (pictures!!)
      • Nicer Input themeing
    • Use sliders when possible
    • Group / order devices by type
      • Controller is at top when loaded
    • Check the brain for variable changes and update them on the site without reloading
    • Possibly a mobile mode in which it only displays the controller and you can use it like a normal controller

Vex Mod

  • Vex mod is a "mod" for VEXcode V5 text (not pro!)

  • Vex mod currently overlays a yellow run button when a physical brain is not connected, it grabs the current project (must be saved in the emulator's project emulatedstorage folder) by taking a screenshot and extracting the text from it

  • Currently it must be ran seperatly from emulator.py if they are ran togehter the pygame windows get messy

  • If i find a way to use injected javascript to do the click events, project name getting and button color changing i will but i haven't found a way at this time


Some things worth mentioning

  • It is possible to create custom devices at the moment but in the future i will be providing a better system for this along with documentation
  • It is possible to run VEX projects without using the emulator but it's way harder and some functionality might not be there
  • The emulator can be used in your own projects as long as the brains main loop can be called periodically, for example
from os import listdir
from vexbrain import Brain
from virtualdeviceserver import VirtualInterface
from program import ProgramFile


brain = Brain()
vds   = VirtualInterface(('localhost', 8080), brain)

"""
Programs are stored in brain.ProgramsLoaded,
by default (in emulator.py) they are loaded from a folder like shown below
"""

for programFile in listdir('data/emulatedstorage/Internal/programs'):
    brain.ProgramsLoaded.append(ProgramFile(f'data/emulatedstorage/Internal/programs/{programFile}'))

while True:
    brain.tickmainloop()
    #Updates the screen and does all the other logic, must be called every so often
    #Unfortunately it can't be ran in it's own thread due to pygame limitations

About

A V5 brain emulator that can run most .v5python programs

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks