// // // CS 495 Evol. Robotics Fall 2004 Assignment 3 // // Tues. October 5, 2004 // // See our web page for details of what you need to do. As for code, everything // is here in this file. As for other files, all you'll need is a the model file // "sensor0.mdl", which is read in in "ACTION sensor0" below. // See the assignment details on the web page for instructions on how to actually // add this script to the world editor (WED). // // -Jeff entity* sensor; // This is the one global variable that I could not get rid of! // It is a pointer to an entity, and is solely used below when // a vehicle needs to talk to one of its sensors. Note that // because it is global, it is SHARED by the vehicle, by which // I mean that the vehicle uses it for talking to any and all of // its sensors, which means that the ptr. variable "sensor" needs // to get updated frequently. See below. // The function (action) "sensor0" is assigned to a single sensor. // This sensor is boolean; it updates its "reading" variable // to a "0" or a "1" integer, depending on whether it sees // an entity within its cone (really a pyramid) of sensitivity. // It is constantly scanning and updating, once per frame cycle. ACTION sensor0 { define reading,skill41; // Create a local variable to store // the latest sensor reading. ent_morph(my,"sensor0.mdl"); // Use the simple model in "sensor0.mdl" // Morph us into it. This way, don't // have to worry about models in WED. while (1) // Do the following forever, every frame. { temp.pan = 80; // Cone of sensitivity is 80 degrees wide, temp.tilt = 90; // and 90 degrees high temp.z = 300; // and 300 quants (approx. inches) long. scan_entity(my.x, temp); // Scan for "scannable" entities. By using // "my.x" vector for direction, the scan cone // points straight ahead of us (using our // current orientation). if(RESULT > 0) // Result of scan is stored in global RESULT. // RESULT holds distance to nearest entity in { my.reading = 1;} // cone. If there is something there, set // reading to 1. else {my.reading = 0;} // If no entity in cone. set reading to 0. wait(1); // Wait until next frame cycle to continue. // This allows engine to update everything else. } } ACTION braitenberg_v1 { // my.enable_scan = on; // make the vehicle visible to sensors my.scale_x = 2 * my.scale_x; // You can change the scale of the my.scale_y = 2 * my.scale_y; // vehicle here, rather than rely on my.scale_z = 2 * my.scale_z; // WED. define sensor_in, skill41; // create a local var for storing // latest sensor reading. skills // 10 through 100 SHOULD be available. define center_sensor, skill43; // Need a pointer to our sensor, so // that we can access it later // Now create a new entity, use model "sensor0", move it to location // "my.x" vector (that is where we, the vehicle, are right now, and // assign it the action "sensor0". Also save the returned pointer. my.center_sensor = ent_create("sensor0.mdl",my.x,sensor0); sensor = my.center_sensor; // Unfortunately, need to use a global // variable to actually access any of // the sensor entity's local variables, sensor.scale_x = my.scale_x; // like "scale_x". sensor.scale_y = my.scale_y; // Resize the sensor so that it is sensor.scale_z = my.scale_z; // right for us. while (1) // Forever loop. Do this every frame cycle. { // Update our sensor with our newest position and orientation. sensor = my.center_sensor; sensor.x = my.x; sensor.y = my.y; sensor.z = my.z+5; sensor.pan = my.pan; // Point straight ahead of vehicle wait(1); // Wait a frame cycle. This allows // sensor to get a new reading using // updated position and orientation. sensor = my.center_sensor; // Get the reading and store it my.sensor_in = sensor.reading; // locally. if (my.sensor_in == 0) // If nothing in front of us { dist.X = 0; // then sit and rotate my.PAN = my.PAN - 1.0; // right (clockwise). } else { if (my.sensor_in == 1) // If something there, in front, { dist.X = 2; // then go forward. my.PAN = my.PAN; } } dist.Y = 0; // Don't go sideways. dist.Z = 0; // Don't fly (yet!!) move_mode = ignore_passable + glide; // Ignore water, etc., and // try to glide along obstacles c_MOVE(my,dist,nullvector,IGNORE_YOU); // that you might hit. } }