Robot.turn() not driving motors properly

Hi,

When I tried to use the Runaway Robot sketch with the Arduino Robot, but modified to work with the PING ultrasonic distance sensor, I noticed that everything worked fine except one function in the sketch. The issue occurred when the Robot.turn() function was called as the motors didn’t appear to be receiving enough power.

I searched for this problem but couldn’t seem to find anything in forums.

I managed to use Robot.write() instead to get the robot to turn using one motor forward and the other motor backward, then delay() and finally calling Robot.motorsStop(). These three functions when called pretty much imitate Robot.turn() but are much simpler as they do not include the use of the on-board compass on the robot.

Hope this helps anyone else who seems to have 'weak motors' when using Robot.turn(). Also, does anyone know if there is a way to get that function to give more power to the motors?

Chelsea

The advantage of Robot.turn() is that it uses the compass to determine the current heading and use the compass to control the turn. Are there any magnets on your robot that might interfere with the compass?

Yeah, I inderstand that advantage. There are no motors on the robot to my knowledge and none in the surrounding area to it either, so I couldn't justify putting this problem down to magnetic interference.

The issue doesn't seem to be with the compass though, it appears to be the amount of power supplies to the motors during Robot.turn() . Do you know of any way which the code can be hacked to change the speed of the motors when this function is called?

No magnets on the robot*

cmsb:
The issue doesn't seem to be with the compass though, it appears to be the amount of power supplies to the motors during Robot.turn() . Do you know of any way which the code can be hacked to change the speed of the motors when this function is called?

Go to the Robot_Control library and change this line in Motors.cpp:

	uint8_t speed=80;

If you want to get fancy you can replace the fixed-speed code with a PID loop to get to a more exact heading much faster.

Thank You for the suggestion, however does this mean there is a bug or flaw in the library because presumably everyone who tries to run this sketch on the robot will have the same issue?

See here for a workaround ! Arduino Robot Turn Problem - #12 by system - Project Guidance - Arduino Forum

There is an error in Motors.cpp in Arduino Robot Control Library, I proposed a code change in GitHub but you can correct it by yourself this way:

  1. Open Motors.cpp file located in Robot_Control/src folder from where Arduino IDE Libraries are installed (for mac users open Arduino.app its in Contents/Java/Libraries/robot_Control/src/)

  2. In Motors.cpp line 32 replace if(direction>0) by if(direction<0) and Voilà !

  3. Recompile your project