Shop OBEX P1 Docs P2 Docs Learn Events
One of my servos goes crazy! — Parallax Forums

One of my servos goes crazy!

bulkheadbulkhead Posts: 405
edited 2005-11-05 19:00 in General Discussion
I wrote a simple program(see code below) so i could enter a 3 digit number (string) into the debug window, which corresponds to the PWM value i want for my servo. It's supposed to ask the user "Enter a 3-digit number: " and wait for 3 characters to be entered. It then prints the value entered, and moves the servo to the corresponding position, and then cycles to the while loop again (prompting for the next value), However, with this certain servo, it doesn't wait for any characters to be entered-it continues by itself. After every other second the servo goes from one extreme to another (left and right, etc), and i see the "Enter a 3-digit number: " show up each time, although i never get the chance to enter any numbers before it cycles through the while loop again.

import stamp.core.*;
public class servoValueTester
{
public static int value;
public static StringBuffer buff;
public static PWM pulse;

public static void main()
{
pulse = new PWM(CPU.pin15,173,2304);
while(true)
{
buff=new StringBuffer();
System.out.println("Enter 3 digit number: ");
buff.append(Terminal.getChar());
buff.append(Terminal.getChar());
buff.append(Terminal.getChar());
value=Integer.parseInt(buff.toString());
System.out.println("V1alue entered : " + value);
pulse.update(value,2304);
}
}
}
Here is what messages show up in the debug window with other servos:

Enter 3 digit number:
280V1alue entered : 280
Enter 3 digit number:
080V1alue entered : 80
Enter 3 digit number:
173V1alue entered : 173
Enter 3 digit number:

With this particular servo:

Enter 3 digit number:
Enter 3 digit number:
Enter 3 digit number:
Enter 3 digit number:

Is there anything that's wrong with my code? Or is my servo bad? It's a blue bird high torque servo. When i had it on a RC reciever, i noticed it was more sensitive than other servos (larger range of travel vs same input). Any input on this issue would greatly be appreciated, thanks.

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-11-05 07:54
    I think the javelin resets itself.

    Insert this line

    System.out,println("Program start\n");

    as the first statement in main()

    If this line is printed every time then you know the javelin

    resets because it is outside the while loop and

    should be printed only once.

    If the javelin resets, try running the servos from a

    seperate power supply. Connect the servo power ground

    to the javelin power ground.

    regards peter

    edit:

    I also noted you create a new stringbuffer inside the while loop.

    This will eventually run you out of memory.

    define

    static StringBuffer buff = new StringBuffer();

    and in your while loop

    buff.clear();

    The same applies to

    System.out.println("V1alue entered : " + value);

    because a temporary string is created that is used only once.

    Change it to

    System.out.print("Value entered : ");

    System.out.println(value);




    Post Edited (Peter Verkaik) : 11/5/2005 8:17:24 AM GMT
  • bulkheadbulkhead Posts: 405
    edited 2005-11-05 19:00
    Wow, you are absolutely right! I checked my battery voltage and it was low-apparently the high torque servo requires significantly more power than a regular servo, so it would reset the javelin each time it (the high torque servo) even moved. I replaced the batteries and it works fine now.

    Thanks for the tips on printing strings. I'm used to programming with no regard for use of memory, so these tips will sure help in the future.
Sign In or Register to comment.