This is my first time working with a gyro sensor, and I was asked to make the robot go straight and to realign itself with that straight path in case it is set off-course. I will not post the entire code for it is too long and has a lot of things outside of the gyro code, so I will paste only the gyro-related parts.
Gyro*gyro; // Setting a variable for the Gyro MyRobotDrive *myRobot; // Setting myRobot variable as the drive system gyro = new Gyro (1); // Assigning the gyro as Analog Port 1 myRobot = new MyRobotDrive (1, 4, 0.5); //myRobot will use the motors in ports 1 and 4 /****** In Autonomous********/ gyro->Reset(); // Resetting the gyro gyro->SetSensitivity(.005) //Setting its sensitivity in volts per second float angle = gyro->GetAngle(); //Gyro gets its heading myRobot-> Drive (-1.0, -angle/30); //Supposed to go forward and correct itself Wait (4.0); //Do that for 4 seconds myRobot->Drive (0.0, 0.0); //Stop Wait (1.0);
When the code was tested on the Robot, not only did it not go straight, but it made a crazy spin. Later, i changed the
myRobot-> Drive (-1.0, -angle/30);part to
myRobot-> Drive (-1.0, -angle);and the robot did go straight, but did not correct itself after its path was changed.
I know for a fact that the drive system itself is working fine and that the gyro is wired correctly. So, programming must be to blame, and I do not have any experience with gyros, so I do not know how to go about programming them.
I am using Wind River Workbench.
Any help would be appreciated! Thank you!