5

How can I program, with NXC, a Lego NXT to turn a specific angle?

I've tried using wait() but the problem isn't solved.

Can I use RotateMotor()? What parameters should I use? For example if I want it to move in a square, what kind of parameters.

2 Answers 2

1

This depends on the exact configuration of your robot, including but not limited to the distance between the wheels (if it's a differential drive robot), the diameters of the wheels, the gearing (if any is used) between the motors and the wheels.

A simple solution would be to experiment with various parameters and making corrections based on the direction and magnitude of the observed error. For example, if you send an order of RotateMotor(100) and see that your robot turns about 30°, you would try again with RotateMotor(300).

Another possible solution is to write a program that displays the values read from the motors' encoders, perform the required maneuvers by pushing the robot by hand, and noting the displayed values. In theory, those values would be the ideal parameters.

Of course, the most sound and correct solution is to whip out your geometry skills and calculate the exact angle the motors need to turn, but this approach tends to fail when reality does not behave perfectly (as in skidding, measurement errors, friction, etc.)

All in all, I'd recommend picking a starting value, trying it on your robot, observing the results, making adjustments based on the observations and starting over the loop.

For reference (if you hadn't already found it): NXC RotateMotor command

1

Control loops. The builtin RotateMotor commands are very imprecise. Have a look at this file for a nice library that makes skid steer vehicles turn very precisely:

https://www.dropbox.com/s/o31qaxx0glx4m3x/Instacode.h?dl=0

You'll need to adjust the constants at the top of the file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.