Results 1 to 4 of 4

Thread: Unable to read AX12 servo position values during Interrupt Service Routine using arbotix.

  1. Unable to read AX12 servo position values during Interrupt Service Routine using arbotix.

    When I use AX12GetRegister() or GetPos() to read the servo position values during my interrupt service routine I am getting -1 as the result. If I call these functions in the main loop I get the correct value. Anyone know how to fix this?

    Code:
    ISR(PCINT1_vect){
       
      trigger = digitalRead(1);
      monitor = digitalRead(2);
      
      if (trigger == HIGH && state == 0){
       state = 1;
      
       digitalWrite(5, HIGH);
       startTime = micros();
      }
      
      if (trigger == LOW && state == 1){
       state = 2;
       endTime = micros();
       panCurrentPosition =   ax12GetRegister(1, AX_PRESENT_POSITION_L, 2);
       waitingForRead = true;
       digitalWrite(5, LOW);
       state = 0;
       pulse_width = pulseIn(2, HIGH);
        if(pulse_width != 0){ // If we get a reading that isn't zero, let's print it
          digitalWrite(5,HIGH);  
          pulse_width = pulse_width/10; // 10usec = 1 cm of distance for LIDAR-Lite
          
                 
          readPosition = true;
          
        }
      
      }
    }

  2. #2

    Re: Unable to read AX12 servo position values during Interrupt Service Routine using arbotix.

    Personally I would not try to do all of this in an Interrupt handler, as you should only do things that are quick.

    The ax12GetRegister would probably fail and timeout as the system can probably not service any of the USART interrupts that would first allow the bytes to be output, then to process the bytes coming in.

    Ditto not sure if pulsin will work...

    You might try enabling interrupts at the start of your handler to see if that works or not...

  3. #3

    Re: Unable to read AX12 servo position values during Interrupt Service Routine using arbotix.

    If you read the data sheet for the AVR microcontroller, it's pretty clear that you can't do what you want in the ISR.

    Instead, you could set a flag inside the ISR, and each time through your main loop, if this flag is set, run the read/write code you want to run.

    Separately, pulseIn() is a synchronous function that may take a long time to run. You'd probably be better off by setting up a pin change interrupt on the pin, and capturing the time when it goes high and low, and then deriving the pulse value by subtracting those times.

  4. Re: Unable to read AX12 servo position values during Interrupt Service Routine using arbotix.

    Thanks for the quick responses. I guess I will just do it in the loop() function.

    PulseIn() was just a quick hack that is working only because there are no interrupts occurring for a long time when it is called.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Question(s) Pypose is unable to read servomotors AX12 series through Arbotix-M board
    By ratatouille in forum Arbotix, Microcontrollers, Arduino
    Replies: 0
    Last Post: 03-23-2015, 01:33 AM
  2. Question(s) Reading Wrong Position Values from AX-12 (C++)
    By robotpanda in forum Software and Programming
    Replies: 4
    Last Post: 05-12-2012, 09:30 AM
  3. Help with servo read position
    By starstorms in forum Software and Programming
    Replies: 1
    Last Post: 04-21-2012, 04:36 AM
  4. Question(s) Arbotix Pypose Read failed: servo id X
    By Ron in forum Robot Computers
    Replies: 20
    Last Post: 11-10-2011, 01:36 PM
  5. Question(s) Arbotix problems with pose servo position
    By muc in forum Arbotix, Microcontrollers, Arduino
    Replies: 9
    Last Post: 02-21-2010, 06:11 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •