Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Attaching hobby servos stops AX-12A from working

  1. #1

    Question Attaching hobby servos stops AX-12A from working

    I'm trying to attach a micro servo to my PhantomX robot arm and am having issues attaching the hobby servos. Prior to attaching the servos to a pin (12-15), dynamixel calls work ok (e.g. dxlGetPosition() and dxlServoReport()). However, after a servo.attach(MICRO_SERVO_PIN) call is made, those dynamixel calls fail to find any servos.

    I am powering the microservo from the 5V pinouts of the digital IO pins. I know it's not recommended but it's just 2 TowerPro SG92R servos that don't expect to carry much load at all and at this stage, there is no call to even move the servos.

    Any suggestions or working examples available?



    Here's my sample code (not working):

    Code:
    #include <ax12.h> //import ax12 library to send DYNAMIXEL commands
    #include <BioloidController.h>
    #include <Servo.h>
    
    
    Servo microServo;
    
    
    // Dynamixel servo assignments
    const int SLAVE_BASE = 1;
    const int SLAVE_SHOULDER = 3;
    const int SLAVE_SHOULDER_2 = 2;
    const int SLAVE_ELBOW = 5;
    const int SLAVE_ELBOW_2 = 4;
    const int SLAVE_ARM = 6;
    const int SLAVE_WRIST = 7;
    
    
    const int MASTER_COUNT = 5;
    const int MASTER_BASE = 11;
    const int MASTER_SHOULDER = 12;
    const int MASTER_ELBOW = 15;
    const int MASTER_ARM = 16;
    
    
    const int ANALOG0_IN_PIN = 0;
    
    
    const int BUTTON1_PIN = 5;
    const int BUTTON2_PIN = 2;
    
    
    const int MICRO_SERVO_PIN = 12;
    
    
    
    
    
    
    void setup() {
      
      // Initialize
      dxlInit(1000000);
    
    
      Serial.begin(38400);
      Serial.println("#################################");    
      Serial.println("Serial Communication Established.");    
      
      pinMode(BUTTON1_PIN, INPUT_PULLUP);
      pinMode(BUTTON2_PIN, INPUT_PULLUP);
    
    
      delay(100);
      dxlServoReport(7);
    
    
      // When this is uncommented, Dynamixel Servos no longer work
      Serial.println("Servo Attach called");
      microServo.attach(MICRO_SERVO_PIN);
      
      Serial.println("###############");    
      Serial.println("Setup Complete");    
      Serial.println("###############");    
    }
    
    
    void loop() {
      // put your main code here, to run repeatedly:
    
    
      checkPositions();
    
    
      dxlServoReport(7);
      
      // check inputs (wrist pot);
      checkInputs();
      delay(1000);
    }
    
    
    void checkPositions()
    {  
      // Read all inputs
      int slaveShoulderPos = dxlGetPosition(SLAVE_SHOULDER);
      int slaveShoulder2Pos = dxlGetPosition(SLAVE_SHOULDER_2);
      int slaveElbowPos = dxlGetPosition(SLAVE_ELBOW_2);
      int slaveElbow2Pos = dxlGetPosition(SLAVE_ARM);
    
    
      Serial.print("Check Positions - Shoulder: ");
      Serial.print(slaveShoulderPos, DEC);
      Serial.print(" ");
      Serial.print(slaveShoulder2Pos, DEC);
      Serial.print(", Elbow: ");
      Serial.print(slaveElbowPos, DEC);
      Serial.print(" ");
      Serial.println(slaveElbow2Pos, DEC);
      
    }
    
    
    
    
    void checkInputs()
    {
      
        int analog0In = analogRead(ANALOG0_IN_PIN);
        Serial.print("Analog 0 In: ");
        Serial.println(analog0In, DEC);
        
        int button1 = digitalRead(BUTTON1_PIN);
        Serial.print("Button1 In: ");
        Serial.println(button1, DEC);
    
    
        int button2 = digitalRead(BUTTON2_PIN);
        Serial.print("Button2 In: ");
        Serial.println(button2, DEC);
    
    
    }
    Output
    Code:
    #################################
    Serial Communication Established.
    ######################################################
    Starting Servo Scanning Test.
    ######################################################
    ###########################
    Cannot connect to servo #1, retrying
    Servo ID: 1
    Servo Positions: 566
              No Errors Found
    Servo ID: 2
    Servo Positions: 538
              No Errors Found
    Servo ID: 3
    Servo Positions: 477
              No Errors Found
    Servo ID: 4
    Servo Positions: 418
              No Errors Found
    Servo ID: 5
    Servo Positions: 592
              No Errors Found
    Servo ID: 6
    Servo Positions: 325
              No Errors Found
    Servo ID: 7
    Servo Positions: 13
              No Errors Found
    All servo IDs present.
    ######################################################
    Servo Attach called
    ###############
    Setup Complete
    ###############
    Check Positions - Shoulder: -1 -1, Elbow: -1 -1
    ######################################################
    Starting Servo Scanning Test.
    ######################################################
    ###########################
    Cannot connect to servo #1, retrying
    ERROR! Servo ID: 1 not found. Please check connection and verify correct ID is set.
    ###########################
    ###########################
    Cannot connect to servo #2, retrying
    ERROR! Servo ID: 2 not found. Please check connection and verify correct ID is set.
    ###########################
    ###########################
    Cannot connect to servo #3, retrying
    ERROR! Servo ID: 3 not found. Please check connection and verify correct ID is set.
    ###########################
    ###########################
    Cannot connect to servo #4, retrying
    ERROR! Servo ID: 4 not found. Please check connection and verify correct ID is set.
    ###########################
    ###########################
    Cannot connect to servo #5, retrying
    ERROR! Servo ID: 5 not found. Please check connection and verify correct ID is set.
    ###########################
    ###########################
    Cannot connect to servo #6, retrying
    ERROR! Servo ID: 6 not found. Please check connection and verify correct ID is set.
    ###########################
    ###########################
    Cannot connect to servo #7, retrying
    ERROR! Servo ID: 7 not found. Please check connection and verify correct ID is set.
    ###########################
    ###########################
    ERROR! 7 servos ID(s) are missing from Scan. Please check connection and verify correct ID is set.
    ###########################
    ######################################################
    Analog 0 In: 466
    Button1 In: 1
    Button2 In: 1
    Check Positions - Shoulder: -1 538, Elbow: -1 -1
    And working:

    Code:
    #include <ax12.h> //import ax12 library to send DYNAMIXEL commands
    #include <BioloidController.h>
    #include <Servo.h>
    
    
    Servo microServo;
    
    
    // Dynamixel servo assignments
    const int SLAVE_BASE = 1;
    const int SLAVE_SHOULDER = 3;
    const int SLAVE_SHOULDER_2 = 2;
    const int SLAVE_ELBOW = 5;
    const int SLAVE_ELBOW_2 = 4;
    const int SLAVE_ARM = 6;
    const int SLAVE_WRIST = 7;
    
    
    const int MASTER_COUNT = 5;
    const int MASTER_BASE = 11;
    const int MASTER_SHOULDER = 12;
    const int MASTER_ELBOW = 15;
    const int MASTER_ARM = 16;
    
    
    const int ANALOG0_IN_PIN = 0;
    
    
    const int BUTTON1_PIN = 5;
    const int BUTTON2_PIN = 2;
    
    
    const int MICRO_SERVO_PIN = 12;
    
    
    
    
    
    
    void setup() {
      
      // Initialize
      dxlInit(1000000);
    
    
      Serial.begin(38400);
      Serial.println("#################################");    
      Serial.println("Serial Communication Established.");    
      
      pinMode(BUTTON1_PIN, INPUT_PULLUP);
      pinMode(BUTTON2_PIN, INPUT_PULLUP);
    
    
      Serial.println("###############");    
      Serial.println("Setup Complete");    
      Serial.println("###############");    
      delay(100);
      dxlServoReport(7);
    
    
      // When this is uncommented, Dynamixel Servos no longer work
      //microServo.attach(MICRO_SERVO_PIN);
      
    }
    
    
    void loop() {
      // put your main code here, to run repeatedly:
    
    
      checkPositions();
    
    
      dxlServoReport(7);
      
      // check inputs (wrist pot);
      checkInputs();
      delay(1000);
    }
    
    
    void checkPositions()
    {  
      // Read all inputs
      int slaveShoulderPos = dxlGetPosition(SLAVE_SHOULDER);
      int slaveShoulder2Pos = dxlGetPosition(SLAVE_SHOULDER_2);
      int slaveElbowPos = dxlGetPosition(SLAVE_ELBOW_2);
      int slaveElbow2Pos = dxlGetPosition(SLAVE_ARM);
    
    
      Serial.print("Check Positions - Shoulder: ");
      Serial.print(slaveShoulderPos, DEC);
      Serial.print(" ");
      Serial.print(slaveShoulder2Pos, DEC);
      Serial.print(", Elbow: ");
      Serial.print(slaveElbowPos, DEC);
      Serial.print(" ");
      Serial.println(slaveElbow2Pos, DEC);
      
    }
    
    
    
    
    void checkInputs()
    {
      
        int analog0In = analogRead(ANALOG0_IN_PIN);
        Serial.print("Analog 0 In: ");
        Serial.println(analog0In, DEC);
        
        int button1 = digitalRead(BUTTON1_PIN);
        Serial.print("Button1 In: ");
        Serial.println(button1, DEC);
    
    
        int button2 = digitalRead(BUTTON2_PIN);
        Serial.print("Button2 In: ");
        Serial.println(button2, DEC);
    
    
    }
    And here's the output:
    Code:
    #################################
    Serial Communication Established.
    ######################################################
    Starting Servo Scanning Test.
    ######################################################
    Servo ID: 1
    Servo Positions: 566
              No Errors Found
    Servo ID: 2
    Servo Positions: 538
              No Errors Found
    Servo ID: 3
    Servo Positions: 477
              No Errors Found
    Servo ID: 4
    Servo Positions: 418
              No Errors Found
    Servo ID: 5
    Servo Positions: 592
              No Errors Found
    Servo ID: 6
    Servo Positions: 325
              No Errors Found
    Servo ID: 7
    Servo Positions: 13
              No Errors Found
    All servo IDs present.
    ######################################################
    ###############
    Setup Complete
    ###############
    Check Positions - Shoulder: 477 538, Elbow: 418 325
    ######################################################
    Starting Servo Scanning Test.
    ######################################################
    Servo ID: 1
    Servo Positions: 566
              No Errors Found
    Servo ID: 2
    Servo Positions: 538
              No Errors Found
    Servo ID: 3
    Servo Positions: 477
              No Errors Found
    Servo ID: 4
    Servo Positions: 418
              No Errors Found
    Servo ID: 5
    Servo Positions: 592
              No Errors Found
    Servo ID: 6
    Servo Positions: 325
              No Errors Found
    Servo ID: 7
    Servo Positions: 13
              No Errors Found
    All servo IDs present.
    Last edited by gmui; 02-08-2017 at 11:05 AM.

  2. #2

    Re: Attaching hobby servos stops AX-12A from working

    Might help to know a few additional things like:
    a) What is this running on? Arbotix-m? What version of Arduino IDE?

    b) Does it work when the servos are plugged in but that Servo library is not called. Does it work when the Servo library is called but the servos are not plugged in? More to figure out if it is the hadware (i.e. power usage) or the software?

  3. #3

    Re: Attaching hobby servos stops AX-12A from working

    Thanks for your reply and help Kurt.

    Yes - Arbotix-M and Arduino 1.6.10

    It works (i.e. AX12A servos can be called without error when the servo is plugged in but the servo attach function is not called.

    It does not work when the hobby servo is unplugged but the attach function is called.

    So regardless of whether the hobby servo is plugged in or not, if the function is called, subsequent dynamixel calls fail.

  4. #4

    Re: Attaching hobby servos stops AX-12A from working

    So it doesn't appear to be software related. I used another Arbotix-M and just plugged in the dynamixel serial cable and the servo (along with the 5V jumper) and it can read all the AX12A servos even after the attach call. I'm not sure if it's the board or if I have some other wiring issue going on but at least with a new, unused Arbotix-M the code works as is.

    If I figure out what was wrong with my other setup I'll post what I find.

    Thanks!

  5. #5

    Re: Attaching hobby servos stops AX-12A from working

    Do you think there might be a capacity problem of having 7 AX12As driven in a slave arm, 9 pushbuttons, 1 toggle, 1 potentiometer and 4 AX12As as a master arm be too much for the Arbotix-M?

  6. #6

    Re: Attaching hobby servos stops AX-12A from working

    Hard to say,

    I hacked up a version of your code. Note my libraries don't match the trossen ones right now. Kyle changed the names of several of the functions and the like and add some other support ones. So had to translate from ax12... to dxl...

    It has been a long time since I used Arbotix-m and also long time since I pulled the Arm down off of a shelf. But the code is still finding 6 out of 7 of the servos. WIll have to remember which servo number my arm was setup for...

    Found my Servo 7 cable was bad, now have servos 7 and 8 talking...

    As for Arbotix-m... These days I don't typically use. I mostly use Teensy or Linux/USB2AX (or Teensy)

    Right now setup is Arbotix-M, with PhantomX Arm 5amp wall wart. I am using an FTDI cable to serial port, programming using ISP. The only other things on my board are, cable setup for resistor divider to get what the voltage is on VIN and small speaker hooked up to a pin so can get simple beeps...

  7. #7

    Re: Attaching hobby servos stops AX-12A from working

    It seems like it's my Arbotix-M. As I said it worked on another board when I only had the AX12As and servos installed. I thought it may have been all the wiring on the first board that was causing the problem. But after pulling all the wiring for the buttons and potentiometer for the original board, the same code fails as before. Anytime after the servo.attach() call is made, the dynamixels can't be consistently read (mostly all -1 positions).

    This is actually my 2nd Arbotix-M that was sent as a replacement for my first one that went bad. I guess I'll have to switch to my 3rd to get this project done but then it leaves me with no spares.

  8. #8

    Re: Attaching hobby servos stops AX-12A from working

    When you use an RC servo with the Servo library, It will allocate a 16 bit timer to use.

    Again I have never used one on the Arbotix boards. So not sure if it works. That is does the version of servo library you are using have the non standard processor type (Atmega644p) called out for that the arbotix boards use? I need to check to see what mine has.

    Note: on the Arbotix 1.6x release set of files: https://github.com/Interbotix/arbotix/tree/arduino-1-6
    They don't include servo library but they do include HServo library... Which looks like some real old version of stuff which may only support two servos on pins 12 and 13 or the like... Again I have never used nor will I likely ever use it...

    But what servo library does, is to use a 16 bit timer (maybe only 1 available on this board?) to control up to N servos I believe the default is 12 per timer. It then sets up a set of timer interrupts to generate the pulses. Your intial call I believe configures the servo for mid point (1500us). So I believe 50 times per second, it will setup a set of timer interrupts (Again it has been awhile since I looked at servo library for AVR boards, but I believe it will setup the interrupt for your first servo, set the pin level high, set the timer interrupt to interrupt again a the end of the pulse, where it sets the pin low and then sets up interrupt to begin the next pulse ..

    The problem may be that while the processor is servicing a timer interrupt, the hardware serial port interrupt is not being serviced. So suppose that at the same time, the processor received a byte back on the hardware serial port AND a timer interrupt is triggered. Now suppose the timer interrupt is serviced first. The problem is that maybe by the time the timer interrupt code completes and the system can then service the Serial port interrupt, another byte was received. This can cause data to be lost.... And as such the packet corrupted.

    How to fix? Hard to say. One could change the Arbotix code that we disable interrupts and do our own polling of the hardware serial ports for data and then enable the interrupts again. This has a bad effect of screwing up a lot of other things. Like most non digital RC servos will not hold their positions when the signals stop. Likewise the servo pulses can easily be screwed up during that time which causes them to have their pulse widths not to be correct...

    So it is hard for me to suggest what to do next. With Teensy I know we have a few options for RC servos. There is the standard Servo library that does like the above, although different type of timer used and Serial1 and Serial2 have a 16 byte hardware queue and ... ) There is also the ability to control RC servos using another library PWMServo, which the the hardware timer takes care of the pulses. Maybe the HServo library works same?

    Sorry this is probably not much of a help.

  9. #9

    Re: Attaching hobby servos stops AX-12A from working

    It may be better to drive the hobby servos using a polled timer and disable interrupts while you do so.
    The idea being that you get to decide when the CPU goes away for 2 milliseconds, which is much better than the interrupts of the servo library randomly taking it away from you.

    A typical "drive the servos" loop might look like this:

    Code:
    unsigned long lastServoTime;
    unsigned short servoPosition[NUM_SERVOS] = { 1500, 1500, 1500 }; // one 1500 per servo
    unsigned char servoPin[NUM_SERVOS] = { 13, 14, 16 }; // or whatever your pins are
    
    void loop() {
        unsigned long now = millis();
        if (now - lastServoTime > 20) { // or whatever frequency you want
            lastServoTime = now;
            cli();
            bool servoHigh[NUM_SERVOS];
            for (int i = 0; i != NUM_SERVOS; ++i) {
                digitalWrite(servoPin[i], HIGH);
                servoHigh[i] = true;
            }
            unsigned long startUs = microseconds();
            bool gotHigh = true;
            while (gotHigh) {
                unsigned long nowUs = microseconds() - startUs;
                if (nowUs > 2500) {
                    break; // failsafe
                }
                gotHigh = false
                for (int i = 0; i != NUM_SERVOS; ++i) {
                    if (servoHigh[i]) {
                        gotHigh = true;
                        if (nowUs >= servoPosition[i]) {
                            servoHigh[i] = false;
                            digitalWrite(servoPin[i], LOW);
                        }
                    }
                }
            }
            sei();
        }
    
        //  .. other code goes here ..
    }

  10. #10

    Re: Attaching hobby servos stops AX-12A from working

    I agree with Jwatte, although I would probably first try the HServo library, which I believe is simply the old Servo library before arduino build 0023...

    It uses Timer/PWM to control without needing to service interrupts. Others have made copies of the old stuff as well:
    example: http://arduiniana.org/libraries/pwmservo/

    When looking around the pwmservo, think of the Arbotix-m as being a Sanguino.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Servos not working
    By Harper in forum HR-OS1 Development and Discussion
    Replies: 3
    Last Post: 06-09-2015, 09:53 AM
  2. 6 external hobby servos in ArbotiX Analog inputs
    By dburongarcia in forum Arbotix, Microcontrollers, Arduino
    Replies: 3
    Last Post: 03-23-2013, 05:00 PM
  3. Hobby Servos: Disappointment strikes
    By jwatte in forum DYNAMIXEL & Robot Actuators
    Replies: 1
    Last Post: 10-20-2012, 01:24 AM
  4. hobby servos
    By mblackwolf in forum Mech Warfare
    Replies: 5
    Last Post: 10-19-2011, 07:52 PM
  5. How to deal with unexpected stops.
    By Resilient in forum Software and Programming
    Replies: 2
    Last Post: 04-01-2009, 08:27 AM

Posting Permissions

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