First Lab Assignment: Moving the Robot This first assignment is meant to show you how to program the Nomad Robot using 'C' and the Nserver program. ------------------------------- Tasks: 1) >>>> read the User's Manual <<< There is a copy in the lab (07 Moore) which should not leave the lab! Copies are also available on-line in http://vision.caltech.edu/jweber/cns286/homework.html The other tasks are: 2) Run Nserver. 3) Write a C program to move the robot. 4) Create a wanderer program: move the robot until it hits a wall. Back off, turn 90 degrees and proceed till bored. ------------------------------- As you will read in the user's manual, the basic philosophy in programming the robot is that you connect to a server program (Nserver) which takes all robot commands and either passes them to the real robot, or simulates the response using a virtual software robot. In this way you can test programs on the virtual robot from anywhere on the net without worrying about breaking the robot. (The virtual robot can also be made to move much faster than the real one). You will need an account on one of the machines in the Mediterranean cluster. There are Sun Sparcstations and linux PC's: Sun machines 131.215.131.60 aegean 131.215.70.40 adriatic Linux machines 131.215.70.43 tacto tacto.caltech.edu 131.215.70.44 opto opto.caltech.edu 131.215.70.45 olfacto olfacto.caltech.edu 131.215.70.46 audito audito.caltech.edu 131.215.70.47 lingo lingo.caltech.edu The robot itself is a linux machine called nomad.caltech.edu. Connect to any of the machines and cd to: (on Suns) /home/weber/Nomad200/Nomad_host/host-2.6.6--sparc-sun-solaris2.4/server (on linux) /home/weber/Nomad200/Nomad_host/host-2.6.6--i486-linux1.1.18/server Execute Nserver. (If you are logged in remotely, you need to be running X windows and have the DISPLAY variable set correctly. The Sun version may complain about not finding libXm. Make sure /usr/dt/lib is in your load path via the command: setenv LD_LIBRARY_PATH /usr/openwin/lib:/usr/lib:/usr/dt/lib/. Nserve must read the license.data file in order to run. ) Nserver is the graphical server which intercepts robot commands. You can also steer the robot using the command line or joystick windows. Load the map called test1.map. This is a rough approximation to 07 Moore! Attached below is a program to get you started on programming the robot. (Copy this program, edit it to reflect which computer is running the server, and also get a copy of Nclient.h located in /home/weber/Nomad200/Nomad_host/host-2.6.6--i486-linux1.1.18/client/ in order to compile the program). The robot moves forward blindly first, then moves a given number of inches while continuously checking the bumbers for contact. Use it to write your own program to: a) Move forward until a bumper detects something. b) Back off from the obstacle a small amount. c) Rotate 90 degrees. d) goto step a) If you always rotate in the same direction, this program will explore the outer wall of any maze. Run this program using the test1.map which contains a number of things to crash into. Notice that there will appear in the graphics window a red robot and a blue one. One is the actual position of the robot, the other is where the robot thinks it is by reading the wheel position. Everytime you hit a wall, the wheels slip and thus the robot thinks it moved when it actually didn't. In time the integrated position will become worse and worse. If you can demonstrate to me that your program works, we can try it on the real robot. Note that on the real robot the bumbers are near the botton. If we hit an object (like a table) that touches only the top of the robot, the bumbers won't fire and the robot will keep moving into the obstacle. Any questions? First read the manual, then contact me. ------------------------------------------------------------------------------------ /* * This program will connect to the robot, configure locomotion, * and move the robot using various commands. * It assumes that a server is running and connects to it * * To compile: gcc -o motiontest test1.c ~weber/Nomad200/Nomad_host/host-2.6.6--i486-linux1.1. 18/client/Nclient-linux.o OR * gcc -o motiontest test1.c ~weber/Nomad200/Nomad_host/host-2.6.6--sparc-sun-sola ris2.4/client/Nclient-sparc.o -lsocket -lnsl * */ #include "Nclient.h" #define ROBOT_ID 1 /* Currently, only robot #1 allowed */ #define SIMULATION 1 int wait_for_stop_or_bumper( int axis ) { /* wait for motion to begin */ while( (State[axis] == 0) && (State[STATE_BUMPER] == 0)) gs(); if (State[STATE_BUMPER] !=0) return(0); /* wait for motion to end */ while( (State[axis] != 0) && (State[STATE_BUMPER] == 0)) gs(); if (State[STATE_BUMPER] !=0) return(0); return(1); } int main() { int dist=1; /* Connection */ SERV_TCP_PORT = 7019; /* Matches the number given in world.setup */ /* >>>>> NB! You must use the name of the machine that <<<<< */ /* >>>>> is currently running Nserver! <<<<< */ strcpy(SERVER_MACHINE_NAME, "olfacto"); /* The machine the server is running on */ if (!connect_robot(ROBOT_ID)) { printf("Connexion to robot failed\n"); return(0); } if (SIMULATION) simulated_robot(); /* Commands will be sent to simulator */ else real_robot; /* Commands will be sent to real robot (CAUTION!!) */ conf_tm(2); /* Robot will stop if no command from the server in 2 seconds */ printf(" ************************************************************\n"); printf(" * NOMADIC HOST SOFTWARE ENVIRONMENT - MOTION DEMONSTRATION *\n"); printf(" ************************************************************\n\n\n"); /* Initialize the robot */ printf("Zeroing...\n"); zr(); /* Zero the robot */ /* Initialize motion parameters */ ac(200,300,300); /* translation, steering, turret accelerations in .1in/s2, .1d eg/s2 */ sp(100,200,100); /* translation, steering, turret speeds in .1in/s, .1deg/s */ sleep(2); /* Wait (ws would do as well) */ printf("Moving forward blindly ...\n"); pr(100,0,0); /* x, y, theta */ ws(1,1,0,20); /* Wait for the motion to stop */ printf("Enter a distance in inches: \n"); scanf("%d",&dist); dist = dist*10; gs(); /* Get state according to Smask */ pr( dist, 0 , 0); if (!wait_for_stop_or_bumper( STATE_VEL_TRANS ) ) { tk("OUCH!"); /* This robot talks !! */ printf("Robot Hit a Wall!\n"); } sleep(2); /* Wait (ws would do as well) */ printf("End of demo, disconnecting ...\n"); disconnect_robot( ROBOT_ID ); }