Gyro and servo

Me and my parent dont know how to get the gyro to coraspoed with the servo motor. We would like to write a code that if tge gyro spinds 5 dergress then the servo spindes back 5 gergess

Assuming you want this always running and not interfering with other stuff, you’ll want to run a separate task for this. In that task you can take an original gyro reading, and you should theoretically know your servo setting. Now repeatedly take new gyro readings. Then roughly do this, the specifics of reading the gyro and setting the motor depending on what language you’re using:

robotRotation = newGyroReading - originalGyroReading;
servoMotorValue = originalMotorValue - robotRotation;

so if i move the gyro to the left 5 degrees that will in turn move my servo to the right said amount

Just for a heads up, I believe that a servo value is one values per degree, and for a gyro it’s 10 values per degree (EDIT//: For ROBOTC). If you’d like to make the servo be in tandem with the gyro, you can follow something similar to this:


Hopefully this helps :smiley:

  • [TVA] Connor

thank you that helps alot

That depends upon what language you’re using, and that wasn’t specified in the OP. For example, gyroGet in PROS returns a value in degrees. Without knowing what language is being used, we don’t know. That’s why I wrote the bits as I wrote them above, making a statement about the language being used. Depending on the specifics, newGyroReading could be set equal to what you get from the gyro, what you get /10, etc.

Thank’s for the notice ;). I edited the post.