Shop OBEX P1 Docs P2 Docs Learn Events
Robot Arm - Trouble Controlling servos with Propeller Servo Controller — Parallax Forums

Robot Arm - Trouble Controlling servos with Propeller Servo Controller

compuwizcompuwiz Posts: 20
edited 2011-02-09 19:14 in Propeller 1
Hello, I'm Matt and I've built a robot arm for science fair. It is controlled with a scale arm with potentiometers.

The Propeller chip reads the potentiometer with the MCP3202 ADC converter, scales the value to a servo width and then tells the Propeller Servo Controller to move that servo to that position.

The trouble is the base servo works fine, as I move the potentiometer on the control arm, the base servo moves itself to the same position. But when I try to do the same thing with the next servo on the arm (J1) which is the same model servo, it twitches uncontrollably. If I run it with PSCI it functions perfectly. If I run J1 with the Base servo code, it runs perfectly. If I run the Base servo with the J1 code it twitches uncontrollably and though I can debug the position of the J1 potentiometer, the arm does not move to that location. The trouble is, about 70% of the time I turn the arm on and load code, it doesn't function at all. The servo just stays in one position. The main trouble is that the Pot positions for J1 is not being passed to the servos, even though it's being done the exact same way that the base servo is being positioned, and it can be successfully displayed with the parallax serial terminal.
In Summary
Works: Base servo, J1 running Base servo code, J1 controller with PSCI
Doesn't Work: J1 running J1 code, Base servo controller with J1 code

The power is 5v at 18 A coming from a computer power supply, it runs through a 3.3v regulator to power the propeller, a 5v regulator to power the connection between the propeller and the Propeller Servo Control Board and the raw 5v 18 A is fed into the servo power connection.

Science fair is on Friday, thus, help is extremely appreciated.

ServoControllerSerial.spinMain.spinReadPots.spin

Comments

  • compuwizcompuwiz Posts: 20
    edited 2011-02-09 09:39
    I managed to make it work now, I had to use different pins for both communication to the Propeller Serial Controller, and for the port the servo was plugged into even though, in the code, I was referencing them correctly. The problem is that instead of operating on a 900-2100 us pulse range like the values that I'm sending to the servo, it operates on approximately 1500 to above 2100 range.

    Any ideas?
  • StefanL38StefanL38 Posts: 2,292
    edited 2011-02-09 10:23
    Hi Compuwiz,

    As I don't have a MCP3202 handy I cannot build up your setup.
    I took a first look into your code and below you find my thoughts.

    Can you post your debug-output when reading in ALL pot-values?

    What I can see in your code is that setting servoposition of J1 is done with a ramp-value of zero while base is done with a ramp-value of 15

    Did you try J1 with a ramp-value of 15?
    If you set your scaling and limit-values of J1 to the same values as base
    do you really get the same pot-values from the base-pot and the J1-pot?

    The method setpos of the servo-controller-serial-object cuts the parameter value POSITION which is a long
    into two bytes
      TX(POSITION.BYTE[0])       
      TX(POSITION.BYTE[1])
    

    did you check if the value of POSITION does not exceed 2^16 - 1 = 65635?
    If it does exceed this value the transforming to byte0 and byte1 results in strange values

    To narrow down the problem you have to make almost everything constant.

    This means:
    send base a real readpot-value
    instead of sending the servocontroller-board a calculated value of J1-readPot,
    for testing and analysing send servo J1 a HARDCODED and VALID value to see if this works.

    If this works start varying this value or switching the value for and back between two values
    that are still VALID values for PSC.

    Add debug-code that reads BACK the position-value by using the GETPOS-method

    best regards

    Stefan
  • compuwizcompuwiz Posts: 20
    edited 2011-02-09 19:14
    Thank you for the advice. The GetPos returns 65,535 at any position. I have decided to start from sqaure 1 with this code:
    CON
    'SpinStamp
    '  _CLKMODE = XTAL1 + Pll8X
    '  _XINFREQ = 10_000_000
    
    'PropPlatform/Propeller
      _CLKMODE = XTAL1 + Pll16X
      _XINFREQ = 5_000_000
    OBJ
      pst : "Parallax Serial Terminal"  'debug with computer
      PSC : "ServoControllerSerial"     'Propeller servo controller
      Control : "ReadPots"              'Read the control arm
    VAR
      long ServoPosition, Base, Joint1, Joint2, Joint3, Last, POSITION
      long Version, Version1
    PUB Init
    
      pst.Start(2400)               'start debug with comp
      PSC.START(14, 0)             'start communication with servo controller
      repeat until PST.DecIn   'wait for input from the terminal
      waitcnt(1_000_000+cnt) 'wait a short amount of time
      psc.setpos(12, 0, 900)  'set the servo to the left
      PST.Clear                   'clear the screen
      waitcnt(1_000_000+cnt) 'pause again
    
      PSC.SETPOS(12, 0, 400) 'set the position of the servo
      pst.dec(psc.getpos(12)) 'output the position of the servo (this as always, reads 65,535
    
    

    The servo now moves to where I want it to, the only interesting part is that the servo is supposed to operate on a 900 us to 2100 us pulse width but instead, the low end is 350 and the highend is 1175. Whereas with PSCI, the lowend is still 900 and the highend is 2100.
Sign In or Register to comment.