Links:

Lab 4

Partners:

Ryan Stack
Ena Trokic
Victoria Dea

My additional function was Indecisive. In Indecisive, my robot finds the shadowline, and moves back and forth across the shadowline.

            #include "behavior.h"
            #include 
            #include 
            #include 
            #include 
            using namespace std;
                            
            double Ambient;
            double normalize(int v)
            {
                if (v > Ambient)
                {
                    v = Ambient;
                }
                return 1.0 - v/Ambient;
            }
            void Alive()
            {
                Ambient = robot.getLight("center");
                while (timeRemaining(15))
                {
                    int L = robot.getLight("center");
                    robot.forward(normalize(L));
                }
                robot.motors(0,0);
            }
            void Coward()
            {
                Ambient = (robot.getLight("left") +
                            robot.getLight("center") +
                            robot.getLight("right")) / 3.0;
                while (timeRemaining(15))
                {
                    int L = robot.getLight("left");
                    int R = robot.getLight("right");
                    robot.motors(-normalize(R), -normalize(L));
                }
                robot.motors(0,0);
            }
            void Aggressive()
            {
                Ambient = (robot.getLight("left") +
                            robot.getLight("center") +
                            robot.getLight("right")) / 3.0;
                while (timeRemaining(15))
                {
                    int L = robot.getLight("left");
                    int R = robot.getLight("right");
                    robot.motors(-normalize(L), -normalize(R));
                }
                robot.motors(0,0);
            }
            void Indecisive()
            {
                Ambient = robot.getLight("center");
                while(timeRemaining(15))
                {
                    int L = robot.getLight("center");
                    if(L > Ambient)
                    {
                        robot.forward(L);
                    }
                    else if(L <= Ambient)
                    {
                        robot.backward(L);
                    }
                }
                                
            }
            int main(int argc, char ** argv)
                                
            {
                int num = 0;
                connect("/dev/tty.Fluke2-01C7-Fluke2");
                robot.beep(0.2,990);
                cout << "Press 1 for Aggressive Stance" << endl;
                cout << "Press 2 for Coward Stance" << endl;
                cout << "Press 3 for Alive Stance" << endl;
                cout << "Press 4 for Indecisive Stance" << endl;
                cin >> num;
                if(num == 1)
                {
                    Aggressive();
                }//num ==1
                else if(num == 2)
                {
                    Coward();
                }//num ==2
                else if(num == 3)
                {
                    Alive();
                }//num ==3
                else if(num == 4)
                {
                    Indecisive();
                }//num ==4
                else
                {
                        cout << "Not a valid input" << endl;
                }//all others
                                    
                                    
                disconnect();
                return 0;
            }
The University of Southern California does not screen or control the content on this website and thus does not guarantee the accuracy, integrity, or quality of such content. All content on this website is provided by and is the sole responsibility of the person from which such content originated, and such content does not necessarily reflect the opinions of the University administration or the Board of Trustees