Shop OBEX P1 Docs P2 Docs Learn Events
Position Controller Serial communication problems... — Parallax Forums

Position Controller Serial communication problems...

BamseBamse Posts: 561
edited 2011-09-01 08:59 in Robotics
Howdy...

I'm using the wheel kit that comes with the position controllers (#29319) and some code that queries these encoders in a loop.

This loops works anything from 1 minute up to 15 minutes and then it get stuck on one of the PosCtrl.rx calls.

PosCtrl.tx(QPOS+1)
wheel_pos1.BYTE[1] := PosCtrl.rx <==== Get stuck in one for the PosCtrl.rx
wheel_pos1.BYTE[0] := PosCtrl.rx

Unfortunately the Simple serial does not seem to support any timeout functionality so I need to figure out how to "unhang" the call to PosCtrl.rx

A quick test with Full Duplex Serial as a replacement for simple serial did not work, maybe just a setup issue but does full duplex serial support communication on one pin at all ?

Is there a problem with the Position Controllers or my code ?

Any ideas ?
.
.
.
CON

' Global constants required, can be removed from here
  _clkmode = xtal1 + pll16x
  _xinfreq = 6_250_000

  MPC_Pin       = 25

  QPOS                          = $08                   'Query Position
  QSPD                          = $10                   'Query Speed
  CHFA                          = $18                   'Check for Arrival
  TRVL                          = $20                   'Travel Number of Positions
  CLRP                          = $28                   'Clear Position
  SREV                          = $30                   'Set Orientation as Reversed
  STXD                          = $38                   'Set TX Delay
  SMAX                          = $40                   'Set Speed Maximum
  SSRR                          = $48                   'Set Speed Ramp Rate

  PING_Pin1 = 0                                          ' I/O Pin For PING)))
  PING_Pin2 = 1                                          ' I/O Pin For PING)))
.
.
.
OBJ
  PosCtrl       : "simple_serial"
.
.
.

VAR

  word wheel_pos1
  word wheel_pos2
  word wheel_speed1
  word wheel_speed2

  word pingCenter1
  word pingCenter2
  word pingRight1
  word pingRight2
  word pingLeft1
  word pingLeft2

  Long SensorStack[300]
.
.
.
PUB start | x , y

  cognew(SensorsUpdate,@SensorStack)

.
.
.
PRI getWheelPosition

    PosCtrl.tx(QPOS+1)
    wheel_pos1.BYTE[1] := PosCtrl.rx
    wheel_pos1.BYTE[0] := PosCtrl.rx

    PosCtrl.tx(QPOS+2)
    wheel_pos2.BYTE[1] := PosCtrl.rx
    wheel_pos2.BYTE[0] := PosCtrl.rx


PRI getWheelSpeed

    PosCtrl.tx(QSPD+1)
    wheel_speed1.BYTE[1] := PosCtrl.rx
    wheel_speed1.BYTE[0] := PosCtrl.rx

    PosCtrl.tx(QSPD+2)
    wheel_speed2.BYTE[1] := PosCtrl.rx
    wheel_speed2.BYTE[0] := PosCtrl.rx

PRI ClearPos

      PosCtrl.tx(CLRP)
      
PRI SensorsUpdate

  PingServo.Start                 'Start Servo handler
  PingServo.Ramp  '<-OPTIONAL     'Start Background Ramping

  PingServo.set(PingServoCh1, 1500)
  PingServo.set(PingServoCh2, 1500)

  PosCtrl.init(MPC_Pin,MPC_Pin, 19200)                   ' Establish comunications to MPC
  ClearPos
  PosCtrl.tx(SREV+2)
  PosCtrl.tx(STXD)
  PosCtrl.tx(200)

  
   repeat

     readPingCenter
     getWheelSpeed
     getWheelPosition

PRI readPingCenter

    pingCenter1 := ping.Millimeters(PING_Pin1)
    pingCenter2 := ping.Millimeters(PING_Pin2)
          
PRI readPingLeft

    pingLeft1 := ping.Millimeters(PING_Pin1)
    pingLeft2 := ping.Millimeters(PING_Pin2)
          
PRI readPingRight

    pingRight1 := ping.Millimeters(PING_Pin1)
    pingRight2 := ping.Millimeters(PING_Pin2)

Comments

  • Tom CTom C Posts: 461
    edited 2011-08-29 10:05
    Bamse,
    You might want to have a look at the attached code as an example.
    Regards,
    TCIII
  • BamseBamse Posts: 561
    edited 2011-08-29 17:56
    Howdy...

    Wheel_Controller.spin does not seem to work either...
    The speed/position returned is always zero...

    Anyone used this driver ?
    OBJ
      PosControl    : "Wheel_Controller.spin"     
    .
    .
    .
    PRI getWheelPosition
    
        wheel_pos1 := PosControl.get_Wheel_Position(PosControl#LEFT_WHEEL)
        wheel_pos2 := PosControl.get_Wheel_Position(PosControl#RIGHT_WHEEL)
    
    PRI getWheelSpeed
    
        wheel_speed1 := PosControl.get_Speed(PosControl#LEFT_WHEEL)
        wheel_speed2 := PosControl.get_Speed(PosControl#RIGHT_WHEEL)
    
          
    PRI SensorsUpdate
    
      PingServo.Start                 'Start Servo handler
      PingServo.Ramp  '<-OPTIONAL     'Start Background Ramping
    
      PingServo.set(PingServoCh1, 1500)
      PingServo.set(PingServoCh2, 1500)
    
      PosControl.open(MPC_Pin)
      
       repeat
    
         ''readPingCenter
         getWheelSpeed
         getWheelPosition
    
    
  • BamseBamse Posts: 561
    edited 2011-08-31 23:14
    So it seems like the Position controllers gotten the best of me...

    Simple serial seem to sooner or later get stuck in one of the rx calls.

    Wheel_Controller.spin always return 0 for speed and position...
    If I hook the HB25 to the position controllers and try for example go_Distance, the robot goes amok and runs off.
    Actually, I just have to give one of the wheels a little bit of a turn and is starts spinning out of control, the only thing I did was to call PosControl.open(MPC_Pin).

    If I use FullDuplex I always get 204 returned (speed and pos) and it seem to always time out.

    Anyhow, I'm thinking about by-passing the micro controller on the position controller and just solder wires from the actual opto interrupter...
    Anyone done this ?
  • Tom CTom C Posts: 461
    edited 2011-09-01 04:18
    Bamse,
    Since your wheel starts to spin out of control when given a little bit of a turn, it might just be that you are driving the wheel in the opposite direction that the position controller is programmed for?
    Just a thought.
    Regards,
    TCIII
  • BamseBamse Posts: 561
    edited 2011-09-01 08:59
    Howdy...

    I'm not really interested in using the Wheel_Controller object so I dropped the idea.
    All I really want is the speed and distance from the encoders.
    I actually want to write my own Wheel Controller object that only uses the speed and distance feedback from the wheel encoders.
    If I can get this to work, I can migrate the code to another project...

    I thought of one thing yesterday, I'm using a 6.25 MHz crystal to run the propeller @ 100 MHz.
    Let me try a 5MHz crystal from one of the proto boards to see if it is more stable.

    I'll be out of town until next week though so I won't be able to test this for a while.
Sign In or Register to comment.