Shop OBEX P1 Docs P2 Docs Learn Events
Connecting Position Controller (Item code 27971) with aduino uno. Please help... — Parallax Forums

Connecting Position Controller (Item code 27971) with aduino uno. Please help...

VovikVovik Posts: 4
edited 2012-06-15 10:03 in General Discussion
I have difficulty to connect the Motor Mount and Wheel Kit with Position Controller ( http://www.parallax.com/StoreSearchResults/tabid/768/txtSearch/hb-25/List/0/SortField/4/ProductID/507/Default.aspx ) with arduino.
As well I have the position controller connected to HB-25 Motor Controller (http://www.parallax.com/Store/Accessories/MotorServos/tabid/163/txtSearch/hb-25/List/0/SortField/4/ProductID/64/Default.aspx) but this part works fine as I tested it by just sending PWM directly to HB-25 and it behave as expected.


Here it is how I wired it:
=================
Position Arduino
Controller

DATA
> Digital pin 3
+5
> +5
GND
> GND




Here it is my arduino test code:
======================

#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); // RX, TX

void setup()
{
// set the data rate for the SoftwareSerial port
mySerial.begin(19200);

}

void loop() // run over and over
{
mySerial.write(0x28);
delay(1000); // Wait for 1 seconds
delay(1000); // Wait for 1 seconds
delay(1000); // Wait for 1 seconds
delay(1000); // Wait for 1 seconds

mySerial.write(0x20);
delay(50); // do not know if i need this delay?
mySerial.write(0x01);
delay(50); // do not know if i need this delay?
mySerial.write(0x01);
delay(1000); // Wait for 1 seconds
delay(1000); // Wait for 1 seconds
delay(1000); // Wait for 1 seconds
delay(1000); // Wait for 1 seconds
mySerial.write(0x28);
delay(1000); // Wait for 1 seconds
delay(1000); // Wait for 1 seconds
delay(1000); // Wait for 1 seconds
delay(1000); // Wait for 1 seconds

}


What I expected when I power or reset arduino is wheels to stay steel for a 4 second then rotates for no more then 4 seconds then stop for 4+4 seconds.... But what I observe is the wheel rotates continously for around 6-8 seconds and then starts and stops sporadically...
Even worse when i power the whole thing down and up it does not repeat the pattern of behavior... does not act consistent.

Couls somebody please advice me how to connect the position controller to arduino onu?

Thanks.

VG.

Comments

  • FranklinFranklin Posts: 4,747
    edited 2012-06-14 23:26
    '------------------------------------------------------------------------'
    ' Position Controller Test Interface (v1_2).bs2                          '
    ' Parallax Inc.  2009.05.20          Code Version 1.2                    '
    '                                                                        '
    ' < Description >                                                        '
    ' This code is a simple test interface for a two-wheel robot design.     '
    ' It sends a command to travel forward 350 positions and continually     '
    ' queries the current position of each wheel to display to the           '
    ' debug (serial) terminal.                                               '
    '                                                                        '
    ' < Harware Configuration >                                              '
    ' For proper operation with this example code, connect the yellow lead   '
    ' of each motor to "M1" and the blue lead of each motor to "M2" on       '
    ' each respective HB-25 motor driver.                                    '
    '                                                                        '
    ' Left or right can be determined by the "L" or "R" marking on the       '
    ' motor casing.  On the right-side Position Controller, install both     '
    ' ID jumpers for an ID value = 1.  On the left-side Position             '
    ' Controller, set the ID jumpers for an ID value = 2.  During            '
    ' initialization, the SREV command is sent to the right-side Position    '
    ' Controller to reverse the orientation of the sensor in software.       '
    '                                                                        '
    ' If either wheel does not operate as expected, check all connections    '
    ' and ensure that each step above was performed correctly.               '
    '                                                                        '
    ' For additional information, refer to the (27971) product documentation '
    ' available online at [URL="http://www.parallax.com"]www.parallax.com[/URL].                                  '
    '                                                                        '
    '------------------------------------------------------------------------'
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    '--- Command Value Constants ---
    QPOS         CON      $08            'Query Position
    QSPD         CON      $10            'Query Speed
    CHFA         CON      $18            'Check for Arrival
    TRVL         CON      $20            'Travel Number of Positions
    CLRP         CON      $28            'Clear Position
    SREV         CON      $30            'Set Orientation as Reversed
    STXD         CON      $38            'Set TX Delay
    SMAX         CON      $40            'Set Speed Maximum
    SSRR         CON      $48            'Set Speed Ramp Rate
    '--- User Constants & Variables ---
    AllWheels    CON      0
    RightWheel   CON      1              'ID of the right side Position Controller
    LeftWheel    CON      2              'ID of the left side Position Controller
    CommPin      CON      12             'communication bus pin
    BaudValue    CON      32             'for 19.2kbps
    Wheel        VAR      Byte           'Specifies which wheel to command for subroutines
    Distance     VAR      Word           'Used to set the travel distance
    RxData       VAR      Word           'Used to receive data
    '--- Initialization ---
    PAUSE 1000
    SEROUT CommPin, BaudValue, [SREV + RightWheel]  'Reverses the sensor on the right
    SEROUT CommPin, BaudValue, [CLRP]               'Clears any prior position info
    'Go forward 350 positions
    Wheel = AllWheels
    Distance = 350
    GOSUB GoDistance
    'Continually check the position of each wheel
    CheckLoop:
      Wheel = LeftWheel
      DEBUG "L= "
      GOSUB DisplayPosition
      Wheel = RightWheel
      DEBUG "  R= "
      GOSUB DisplayPosition
      DEBUG CR
      GOTO  CheckLoop
      END
    '--- Subroutines ---
    GoDistance:
      SEROUT CommPin, BaudValue, [TRVL + Wheel]
      SEROUT CommPin, BaudValue, [Distance.HIGHBYTE, Distance.LOWBYTE]
    RETURN
    DisplayPosition:
      SEROUT CommPin, BaudValue, [QPOS + Wheel]
      SERIN  CommPin, BaudValue, [RxData.HIGHBYTE, RxData.LOWBYTE]
      DEBUG SDEC RxData
    RETURN
    
    This is the stamp code. You may be able to decipher the commands to send from this. It looks like at the least you need to take out the pauses between the low and high bytes.I'm not sure what the + sign does in the serout though.
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2012-06-15 10:03
    What you describe sounds like a mis-match between the direction setting of the motor direction (SREV). Start by playing around with this statement. The code Franklin posted for the BS2 shows how the right motor is reversed. If this is not done, that motor will "hunt."

    As for connecting, what you have will work for simplex communication, and is sufficient for getting started. If you want 2-way communication, you'll need to "steer" the 1-wire UART as shown in post #4 here:

    http://forums.parallax.com/showthread.php?120828-help-colorpal-sensor&p=890024#post890024

    Forget that the labels show some other Atmel chip and the ColorPal -- the general idea is the same for interfacing the Arduino to any of Parallax's 1-wire UART products.

    -- Gordon
Sign In or Register to comment.