Shop OBEX P1 Docs P2 Docs Learn Events
PWM "Stopping" SRF04 Range finder — Parallax Forums

PWM "Stopping" SRF04 Range finder

Jon KeinathJon Keinath Posts: 146
edited 2005-04-19 13:17 in General Discussion
I have come across a rather odd problem.

I recently tried to add control of a servo (with the PWM object) to control the direction the range finder is facing, but when I add the line
static PWM sonic = new PWM(CPU.pin13,173,2304); to my code the RangeFinder will quit working (it returns "Out of Range") if I comment out the line like in the code I have posted, the range finder works properly.

I know a way around it, (I can just add the servo to the PSC instead of using PWM which is what I'm going to do eventualy anyway),
I'm just wondering (for future reference) why this would happen and if it should happen.

import stamp.core.*;
public class ServoTestNav
  {
  final static char CLR_SCR = '\u0010';
  static PSC psc1 = new PSC(CPU.pin12);                                        // Drive & Steer Servos
  static Steer RRS = new Steer(727,1,8,psc1,480,317,true);
  static Steer RLS = new Steer(784,15,8,psc1,975,1187,true);
  static Steer FRS = new Steer(739,0,8,psc1,1015,1173,true);
  static Steer FLS = new Steer(756,14,8,psc1,480,334,true);
  static Drive RRD = new Drive(752,3,5,psc1,true);

  static Drive RLD = new Drive(751,13,5,psc1,true);
  static Drive FRD = new Drive(751,2,5,psc1,true);
  static Drive FLD = new Drive(752,12,5,psc1,true);
  //static PWM sonic = new PWM(CPU.pin13,173,2304);       // RangeFinder Servo  << this is the line in question
  static Robo bot = new Robo(FRS,FLS,RRS,RLS,FRD,FLD,RRD,RLD);
  public static void main()
    {
    SetBaud.set(CPU.pin12);                                        // Sets BaudRate of Servo Controler
    SRF04 range = new SRF04(CPU.pin0, CPU.pin1);
    IRDecode IRa = new IRDecode(CPU.pin8);
    StringBuffer msg = new StringBuffer();
    int distance;
    while (true)
      {
      // create and display measurement message
      msg.clear();
      msg.append(CLR_SCR);
      msg.append("SRF04 Demo\n\n");

      // display whole inches
      distance = range.getIn();
      msg.append("In   = ");
      if (distance > 0)
        msg.append(distance);
      else
        msg.append("Out of Range");
      msg.append("\n");

      System.out.print(msg.toString());

      // wait 0.5 seconds between readings
      CPU.delay(5000);
      }
    }
  }

Comments

  • corkcork Posts: 1
    edited 2005-04-19 13:02
    I am not sure if this is the same problem, but it seems to be similar.

    Consider the following simple program:

    import stamp.core.*;
    public class PinsProblem
    {
    static int foo = CPU.pins[noparse][[/noparse]0];
    public static void main() {}
    }

    This compiles, but generates an error in the JVM when run.

    If I change "CPU.pins[noparse][[/noparse]0]" to "CPU.pin0", it runs fine (does nothing).

    If I remove the "static" from the same line, it also runs fine, even with
    the original "CPU.pins[noparse][[/noparse]0]".

    I think this is a bug in the Javelin JVM, and it may be related to your problem.

    How should I report this?
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-04-19 13:17
    Try this

    import stamp.core.*;

    public class PinsProblem {

    · static int foo;

    · public static void main() {
    ··· foo = CPU.pins[noparse][[/noparse]0];
    · }

    }

    and then there is no error. I think the CPU.pins[noparse]/noparse is not initialized until main is called.

    That may be so for all static arrays (CPU.pins[noparse]/noparse is a static array)

    regards peter
Sign In or Register to comment.