/* * Program : Braitenberg Vehicles Version 2.0 * * Requirements : latest version of breve 0123 Beta and java * * Omid Mikhchi (om05@hampshire.edu), 2006 * * Description : Based on Valentino Braitenberg's book "Vehicles" this is a program that allows you to make your own vehicles with unlimited number * of sensors and stimuli attached. For now this program ends on chapter 3 of the book future versions will include newer parameters * to change the vehicle (like threshoulds). * * * Controls : * Keyboard * UP = create stationary stimulus of type 1 * DOWN = create stationary stimulus of type 2 * Mouse * click once on any stimulus and a indicator pops on it that allows you to change its position to the mouse position * move mouse after a stimulus has been clicked changes the stimulus position to that of the mouse position * click again and it releases the stimulus and removes the indicator allowing you to click on another stimulus * * *Preview : Right now two vehicles exist that are each wired to LOVE a certian stimulus that also happens to be on the opposite vehicle * I can only explain the behavior as "Mating Dance" you can judge for yourself. Experiment by adding/changing the * sensors, stimuli, or adding more vehicles go CRAZY! Once you get the hang of it its hard to stop playing with them. */ /* New Features : After a major overhaul my program can now have multiple sensors, stimuli, and vehicles (I still need to write the vehiclesystem class to allow for a dynamic list of vehicles like sensors and stimuli). SENSORS: The sensors can draw wires to indicate which wheel they are wired to. The intesity of the stimulus is shown through the brightness of the sensor stroke. The sensor read only stimulus of the same type that it was created (or changed) as. The sensor type is indicated by their stroke hue. Sensors can also show the relationship between stimulus intensity and wheel speed by a + or - sign STIMULI: Stimuli are animated to show if they are dead or not ( for now they are always on) You can specify the stimuli strength. The stimulus type is indicated by its stroke hue. VEHICLES: You can design and change any vehicle's axel length, wheel Diameter, or wheel width. Vehicles now have seperate speeds for each wheel. These are the significant operators but there are numerous other variables that can be changed look inside each tab to find them. Current Bugs : No major bugs, except I have to add a Vehicle System that allows for any number of vehicles realtime (like sensors) if you place anything on a vehicle you will notice it jitters a lot as it moves ( I think this is due to delay between the vehicle drawing and the objects being drawn) Vehicles can move off screen (not technically a bug, but I want to figure out a way to bring them back if they go off screen) Future Updates : Program chapter 4 "Values and Special Tastes" None of my program has any REAL physics which will probably be another major update Have it so that you can pause the program to change the sensor positions and wiring and see the results in realtime Have it so that you can SAVE and LOAD vehicles to files Clean up some small details to make my code cleaner and more user friendly */ // ---------------------------------------------------------------------------------------------------------------- // Global Variables SensorSystem G_totalSensors; StimulusSystem G_totalStimuli; Vehicle[] Braitenbergs = new Vehicle[4]; // Initial setup void setup() { size(1024,768); background(0); frameRate(60); smooth(); colorMode(HSB, 360, 100, 100, 100); // create sensor system G_totalSensors = new SensorSystem(0); // create stimuli system G_totalStimuli = new StimulusSystem(0); // create vehicle one Braitenbergs[0] = new Vehicle(100,300, 50, 20, 10, 0, 0); // create vehicle two Braitenbergs[1] = new Vehicle(300,100, 50, 20, 10, 0, 1); Braitenbergs[0].setrotationAngle(-90); Braitenbergs[1].setrotationAngle(180); // create two sensors of type 1 G_totalSensors.addSensor(new Sensor(110, 38, 10, -1, 32, 1, 2)); G_totalSensors.addSensor(new Sensor(110, 38, 10, 1, 32, 1, 2)); // create two sensors of type 2 G_totalSensors.addSensor(new Sensor(110, 38, 10, -1, 32, 2, 2)); G_totalSensors.addSensor(new Sensor(110, 38, 10, -1, 32, 2, 2)); // create stimulus of type 1 G_totalStimuli.addStimulus(new Stimulus(100, 100, 1, 100)); // create stimulus of type 2 G_totalStimuli.addStimulus(new Stimulus(100, 100, 2, 100)); } // ---------------------------------------------------------------------------------------------------------------- // draw void draw() { background(0); // vehicle one loves vehicle two Braitenbergs[0].setleftwheelSpeed(1/G_totalSensors.getsensorReading(0)); // the left wheel goes faster the less stimulus of type 1 it gets Braitenbergs[0].setrightwheelSpeed(1/G_totalSensors.getsensorReading(1)); // the right wheel goes faster the less stimulus of type 1 it gets // vehicle two loves vehicle one Braitenbergs[1].setleftwheelSpeed(1/G_totalSensors.getsensorReading(2)); // the left wheel goes faster the more stimulus of type 2 it gets Braitenbergs[1].setrightwheelSpeed(1/G_totalSensors.getsensorReading(3)); // the right wheel goes faster the more stimulus of type 2 it gets // update vehicles Braitenbergs[0].update(); Braitenbergs[1].update(); Braitenbergs[0].switchPivot(); Braitenbergs[1].switchPivot(); // update all stimuli G_totalStimuli.run(); // place stimulus of type 1 on vehicle two G_totalStimuli.setlocationX(0, Braitenbergs[1].placeX(25.0, 32.0)); G_totalStimuli.setlocationY(0, Braitenbergs[1].placeY(25.0, 32.0)); // place stimulus of type 2 on vehicle one G_totalStimuli.setlocationX(1, Braitenbergs[0].placeX(25.0, 32.0)); G_totalStimuli.setlocationY(1, Braitenbergs[0].placeY(25.0, 32.0)); // update all sensors G_totalSensors.run(); // place first sensor on the left side of vehicle one G_totalSensors.setlocationinX(0, Braitenbergs[0].placeX(0.0, 32.0)); G_totalSensors.setlocationinY(0, Braitenbergs[0].placeY(0.0, 32.0)); G_totalSensors.setRotation(0, -1*Braitenbergs[0].getrotationAngle()); // place second sensor on the right side of vehicle one G_totalSensors.setlocationinX(1, Braitenbergs[0].placeX(50.0, 32.0)); G_totalSensors.setlocationinY(1, Braitenbergs[0].placeY(50.0, 32.0)); G_totalSensors.setRotation(1, -1*Braitenbergs[0].getrotationAngle()); // place third sensor on the left side of vehicle two G_totalSensors.setlocationinX(2, Braitenbergs[1].placeX(0.0, 32.0)); G_totalSensors.setlocationinY(2, Braitenbergs[1].placeY(0.0, 32.0)); G_totalSensors.setRotation(2, -1*Braitenbergs[1].getrotationAngle()); // place fourth sensor on the right side of vehicle two G_totalSensors.setlocationinX(3, Braitenbergs[1].placeX(50.0, 32.0)); G_totalSensors.setlocationinY(3, Braitenbergs[1].placeY(50.0, 32.0)); G_totalSensors.setRotation(3, -1*Braitenbergs[1].getrotationAngle()); // move stimulus if clicked on if (i_itemfoundTest == -1) { G_totalStimuli.setlocationX(i_currentItem,mouseX); G_totalStimuli.setlocationY(i_currentItem,mouseY); //stroke(0, 0, 100); noStroke(); fill(0, 0, 100, 30); ellipseMode(CENTER); ellipse(mouseX, mouseY, 10, 10); } } // ----------------------------------------------------------------------------------------------------------------