Links:

Lab 3

In this lab we took two routes to complete the Fibonacci Spiral. One technique was to approximate a spiral with hard lines while making the actual dimensions precise, while the other was to make sure that the spiral was smooth, ignoring how exactly it resembled the Fibonacci Spiral. First is the rough spiral.

        #include Myro.h
        #include math.h
        #include stdio.h
        #include iostream
        using namespace std;
        
        int fibonacciSequence(int round)
        {
        double numbers[round];
        
        numbers[0] = 0;
        numbers[1] = 1;
        
        for(int i = 2; i <= round; i++)
            {
            numbers[i] = numbers[i - 1] + numbers[i - 2];
            }
            for (int n = 1; n <= round; n++)
            {
            robot.forward(1,numbers[n]/10.0);
            robot.turnLeft(1,.733/3);
            robot.forward(1,numbers[n]/10.0);
            robot.turnLeft(1,.733/3);
            robot.forward(1,numbers[n]/10.0);
            robot.turnLeft(1,.733/3);
            }
            }
            int main(int argc, char ** argv)
            {
            int round = 0;
            connect("/dev/tty.Fluke2-01FB-Fluke2");
            cout << "enter how many numbers you want in the sequence" <> round;
            fibonacciSequence(round);
            disconnect();
            
            return 0;
            }

Second is the smooth spiral.

        #include Myro.h
        #include math.h
        #include stdio.h
        #include iostream
        
        using namespace std;
        
        int getFib(int n)
        {
        int result=0;
        if(n>=2)
        {
        result= getFib(n-2)+getFib(n-1);
        }
        else
        {
        result=n;
        }
        return result;
        }
        
        int main()
        {
        connect("/dev/rfcomm0");
        cout << "Waiting..." << endl;
            wait(2);
            
            cout << "Battery status: " << robot.getBattery() << endl;
            
            for (int i=0; i<6; i++)
            {
            
            robot.motors(getFib(i)*.1,1);
            wait(1);
            cout << getFib(i) << endl;
            }
            
            
            cout << "Waiting to disconnect..." << endl;
            wait(5);
            
            cout << "Disconnecting. Goodbye." << endl;
            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