Page 1 of 16 1 2 3 11 ... LastLast
Results 1 to 10 of 151

Thread: Help Please: PICAXE and Robot Boat

  1. #1
    Senior Member
    Join Date
    Aug 2009
    Location
    Sunninghill UK
    Posts
    263

    Default Help Please: PICAXE and Robot Boat

    Hi Folks. I'm new to the PICAXE stuff, and hope
    that someone can save me some time on getting
    RS232 input to work on a AXE024 servo controller.

    Many Thanks in advance for any help and advice.
    Thanks also to my friend Roy who recently
    introduced me to PICAXE and got me started.

    I'm hoping to make an RS232 servo controller,
    to replace a Pololu SCCII, based on the AXE024.
    This is part of a robot boat project described on
    www.gpss.co.uk/autop.htm
    You may enjoy the "Snoopy Sails!" video :-)

    The robot boat is navigated by an iPAQ Pocket PC
    with RS232 for GPS input and output to the servo controller.
    For the past year we've used a standard Pololu SSCII
    servo controller, plus a small card from friend Klaus
    in Germany, because of the simple protocol we use on RS232.
    We wish to do everything on one PICAXE card,
    even if this restricts the number of servos to 2 or 3.

    Please remember that I'm a newbie to PICAXE stuff,
    and cannot afford to spend a lot of time on this
    particular part of what is for me a hobby project.
    I'm an old man of 62 who cut his teeth on computers
    in the 1960s: details on www.gpss.co.uk/history.htm
    So please be gentle with me :-)

    I'm having problems with RS232 input: details below.

    Can the AXE024 handle RS232 input AND control three servos ?

    The RS232 input is a very simple protocol:
    a three byte servo command: 127=sync, 0,1 or 2 for servo number,
    0 to 126 servo position (translated by my SC1 program on the AXE024).

    I've tried quite a few other things already,
    including putting the RS232 input onto a servo pin,
    but what I have is now is using 08M pin 4 (signal 3).

    My PC COM1 port has a test program, AUTOP,
    already proven for testing the Pololu Servo Controller.
    Clicking on a button sends the three required bytes out
    via RS232 into the PICAXE AXE024 servo controller with 08M.

    The RS232 is wired into pin 4 (signal 3) on the AXE024
    (have tried with and without 10k pullup resistor)
    and three servos are plugged in to the servo positions.

    My SC1.BAS (code below) application runs OK, using SERVO to
    do the correct test pattern of wagging all three servos twice,
    before waiting on a byte from serial input with
    SERIN 3,N4800_8,b1

    It does as it should, waiting, until I send the 3 bytes from PC.
    It SHOULD waggle just one servo and then wait.
    There is a twitch on one servo, and then the program restarts.
    Presumably due to an error condition.
    Same symptoms both with and without the 10k pull up resistor.

    I thought the error condition might be due to the next two bytes
    coming in before the SERIN were issed, but this latest version of
    SC1 program just does the SERINs. i.e. not waiting on sync byte.
    No delays yet added between the three bytes from the AUTOP on PC.

    Extra notes: wires from 9 way D on PC COM1: pin 5 = 0V, pin 3 signal.
    Not using SERVOPOS due to unreliabity. Can return to this later.
    But SERVO seems to work reliably enough while I work on this RS232 input.
    Document for AXE024 servo controller: http://www.rev-ed.co.uk/docs/axe024.pdf
    Document for programming: http://www.rev-ed.co.uk/docs/picaxe_manual2.pdf

    Robin
    www.gpss.co.uk/autop.htm


    'SC1.BAS servo controller for robot boat
    'input is RS232 group of 3 bytes:
    '127=sync, 0,1 or 2=servo number, 0 to 126 servo position

    verytop:
    b5=100 'limits of servo travel
    b6=191 '100 to 191 gives 360 degrees

    'first a simple test pattern
    'wag servos 1,2,4, twice.
    SERVO 1,b5 'initiate 3 servos
    SERVO 2,b5
    SERVO 4,b5
    PAUSE 3000 'pause 3 secs
    for b7=1 to 2
    SERVO 1, b6 'drive servo 1
    PAUSE 1000 'pause 1 secs
    SERVO 2, b6 'drive servo 2
    PAUSE 1000 'pause 1 secs
    SERVO 4, b6 'drive servo 4
    PAUSE 1000 'pause 3 secs
    SERVO 1, b5 'all back
    SERVO 2, b5
    SERVO 4, b5
    PAUSE 3000 'pause 3 secs
    next b7

    'then wait for bytes on serial port to control servos
    sync: SERIN 3,N4800_8,b1 'read byte from RS232 input on 3
    'IF b1<>127 then goto sync 'wait for the sync byte of 127

    SERIN 3, N4800_8,b2 'read servo number 0 to 2.
    SERIN 3, N4800_8,b3 'read servo position 0 to 126

    'this for test only - wag just servo 1
    SERVO 1,b6 'drive servo to upper limit
    PAUSE 3000 'pause 3 secs
    SERVO 1,b5 'drive servo to lower limit
    PAUSE 3000 'pause 3 secs
    SERVO 1,b6 'drive servo to position based on 3rd byte
    PAUSE 3000 'pause 3 secs
    GOTO sync

    '(logic here will be different if and when RS232 is working)

  2. #2
    Technical Support
    Join Date
    Jan 1970
    Location
    UK
    Posts
    20,058

    Default

    Welcome to the PICAXE forum.

    The AXE024 is an 08M board with connectors for three servos with Leg 4 ( Input Pin 3, not used ). You can connect serial input to leg 4 - use a 22K in series and a diode pull-up between Leg 4 ( cathode, pointy-end ) and +V ( anode ). Use SERIN to read the incoming serial.

    However ... the 08M will stop controlling servos while waiting for SERIN so you need to use a protocol which allows it to work. Prefixing messages with a pulse ( send $00 ) allows Pin 3 to be monitored by polling and jumping to a routine which will read the subsequent serial data. Other similar schemes using interrupts can be used.
    Last edited by hippy; 03-08-2009 at 11:22. Reason: Leg 4 is Input Pin 3

  3. #3
    Technical Support
    Join Date
    Jan 1970
    Location
    UK
    Posts
    20,058

    Default

    Code:
    #Picaxe 08M
    Do
      If pin3 = 1 Then
        Serin 3, N2400, ( $0A ), b1, b2, b4
        Servo 1, b1
        Servo 2, b2
        Servo 4, b4
      End If
    Loop
    You'd send a packet of $00 $FF $0A $aa $bb $cc

    Code:
    #Picaxe 08M
    Do
      If pin3 = 1 Then
        Serin 3, N2400, ( $0A ), b0, b1
        Select Case b0
          Case 1 : Servo 1, b1
          case 2 : Servo 2, b1
          case 3 : Servo 4, b1
        End Select
      End If
    Loop
    You'd send a packet of $00 $FF $0A $0n $ss ( n=1,2,3 )
    Last edited by hippy; 03-08-2009 at 10:32.

  4. #4
    Senior Member
    Join Date
    Aug 2009
    Location
    Sunninghill UK
    Posts
    263

    Default

    Many Thanks for such a quick reply Hippy.

    So I guess the answer to my question:
    "Can the AXE024 handle RS232 input AND control three servos ?"
    is Yes ? Is this based on others using the AXE024 ?

    First I had better make sure I've made the required hardware changes.
    You say "leg 3". Is that the same pin as I describe in my first posting ?
    I think that was hardware pin 4 (signal 3 for SERIN).

    Is what you describe anywhere in the PDF documentation ?
    I thought I had followed this correctly, with a pull down 10k resistor
    between the pin and oV. You describe something very different
    with a diode and resistor. I don't want to blow anything up :-)

    Robin
    www.gpss.co.uk/autop.htm

  5. #5
    Technical Support
    Join Date
    Jan 1970
    Location
    UK
    Posts
    20,058

    Default

    Quote Originally Posted by Robin Lovelock View Post
    So I guess the answer to my question:
    "Can the AXE024 handle RS232 input AND control three servos ?"
    is Yes ? Is this based on others using the AXE024 ?
    The answer is, "yes". Based on others using serial to control servos though I do not know if any have used AXE024 with serial. There is a lot of discussion on servo control which will be found via the forum's Search.

    Quote Originally Posted by Robin Lovelock View Post
    You say "leg 3". Is that the same pin as I describe in my first posting ? I think that was hardware pin 4 (signal 3 for SERIN).
    That was my mistake/typo; Leg 4 is Input Pin 3 ( I'll correct my original post ). We have a de-facto standard to use "Leg" to describe the physical pins of the chip and "Pin" to describe the signals used by the software to avoid confusion.

    Quote Originally Posted by Robin Lovelock View Post
    Is what you describe anywhere in the PDF documentation ?
    I thought I had followed this correctly, with a pull down 10k resistor
    between the pin and oV. You describe something very different
    with a diode and resistor. I don't want to blow anything up :-)
    Serial interfacing is described in PICAXE Manual 3 - Electrical Interfacing.

    The 22K is used to limit the current for a +/-12V RS232 signal. That may be / need to be reduced / removed depending on what your serial voltage levels are. The 10K pull-down is placed at the end of the 22K furthest from the PICAXE but isn't a necessity if the system is permanently connected to the serial data line. It does no harm to add it even if that is the case. The diode is a necessity for the 08M if serial voltages are above +V voltage for the PICAXE.
    Last edited by hippy; 03-08-2009 at 11:28.

  6. #6
    Technical Support
    Join Date
    Jan 1970
    Location
    UK
    Posts
    20,058

    Default

    Very interesting site.

    they will need to wire the output of the computer's RS232 serial port to an SSCII servo controller, via a protocol convertor such as that seen here from Klaus. This is a "hardware workaround" to the Microsoft OS not allowing more than 7 data bits to be sent to the SSCII
    If using a PICAXE you should be able to do away with the Klaus converter and have the PICAXE handling the iPAQ protocol directly. You can also have more than three servos if you need them, either using multiple AXE024 or building your own PCB/vero-board and using a larger PICAXE.

  7. #7
    Senior Member
    Join Date
    Aug 2009
    Location
    Sunninghill UK
    Posts
    263

    Default

    Many Thanks again Hippy.
    I'm making some progress - thanks to you :-)

    Adding a 22k resistor in series with the serial
    signal from my PC COM1 port was important.
    Now I do not get a program restart due to
    what I guess was an error condition caused
    by the PC RS232 levels being higher than the 5v supply.

    So now my test program could wait on the sync
    byte, still using SERIN. Then use the SERVO command.
    Now, clicking on my PC test program,
    to cause the 3 bytes to be sent out,
    correctly causes just the one servo to twitch
    - but not move to the required position.

    So now I'm thinking your words about SERIN
    stopping SERVO to work means I should use
    your solution such as
    If pin3 = 1 Then
    Serin 3, N2400, ( $0A ), b1
    etc

    However, I need to use N4800 because
    the PC (or rather the iPAQ on my robot boat)
    will be reading GPS data that must be at 4800.

    So I thought I could just try
    Serin 3, N4800, ( $0A ), b1

    - but this was quickly rejected by the program editor software.

    I looked at Manual3 on interfacing,
    and followed your suggestion on your 22k resistor in series.
    I removed the 10k resistor.
    I saw no mention of a diode in the manual,
    so have not added one.
    It looks as if this 22k has solved the hardware problem.

    From your earlier posting it seems you do not know
    of anyone using the AXE024 with servos AND serial input.
    This is obviously the neat solution - if it works. I got a couple
    of AXE024 in addition to several AXE021 experimental boards
    which were my original choice.
    Then I saw the AXE024 and it includes that
    neat set of servo pins - avoiding extra work :-)

    Any suggestions on what I might try next ?
    Seems as if we might be close.
    Just need to work around SERIN mucking up SERVO.

    Robin
    www.gpss.co.uk/autop.htm

  8. #8
    Technical Support
    Join Date
    Jan 1970
    Location
    UK
    Posts
    20,058

    Default

    The diode on Leg 4 / Pin 3 of the PICAXE-08M is essential when serial is over +V. That's actually described in PICAXE Manual 2 under the SERIN command.

    You can use N4800_8 to get 4800 baud but also have to add "SETFREQ M8" at the start of your program. That will likely mess up servo operation as the servo timing loop halves.

    The PICAXE SERIN has to match whatever protocol you are feeding into it while for the Pin 3 polling to work you need the protocol to provide for that. Alternatively you can use another PICAXE to do the conversion from iPAQ to the AXE024, or use a different PICAXE member to handle the serial and drive the servos.

    There are two approaches to take with what you currently have; make the iPAQ work with the PICAXE or make the PICAXE work with the iPAQ, and in this case the specific AXE024. Both have their constraints within which you have to work with. Getting the iPAQ to send what the PICAXE would like ( using 2400 baud, slight change to what is sent ) would seem the easiest approach though I don't know the iPAQ capabilities. Once you have that setup working you can then move on

    The ideal start would be to write a test program for the iPAQ ( or the PC AUTOP program ) to send out serial data, the PICAXE to read that and report to the PC what it is receiving, then the protocol and serial can be tweaked for reliable operation if needs be, then servos added.
    Last edited by hippy; 03-08-2009 at 14:40.

  9. #9
    Senior Member
    Join Date
    Aug 2009
    Location
    Sunninghill UK
    Posts
    263

    Default

    Thanks yet again Hippy. Now I think the picaxe restrictions and
    "undocumented features" are being brought to the surface :-)

    This is why your feedback on this Forum is so valuable.
    It looks as if the AXE024 servo controller may not be
    suitable for this job. It may not have been used in
    this RS232-controlled servo control with success.

    But with your help I am happy to see if we can program around it.

    Thanks the info on adding the diode: this is now added.
    I can see that it was mentioned in the documentation text.

    First the spec: it is to receive the 3 bytes at 4800 baud.
    I'd rather not start changing the iPAQ system to program
    around limitations of the PICAXE.

    I can confirm that use of SETFREQ M8 in order
    to try and get SERIN to work, does in fact screw up SERVO.

    I've tried quite a few variations on your code, but with no good result.
    e.g. SERIN, N4800_8, (127), b2, b3
    - thought this might look for the sync byte of 127 followed by two bytes.

    Some of the symptoms I'm getting make me think that there could
    be other restrictions in the picaxe system - such as missing bytes
    that appear too quickly. AUTOP on the PC sends out the 3 bytes
    withoiut delays between them - limited only by the 4800 baud.
    Of course, there are usually big delays of several seconds between
    each 3 byte group that represents a particular servo command.

    I greatly appreciate your quick responses and knowledge
    of what the picaxe systems may and may not be capable of doing.

    Robin
    www.gpss.co.uk/autop.htm


    >>>>>>>>>>


    Quote Originally Posted by hippy View Post
    The diode on Leg 4 / Pin 3 of the PICAXE-08M is essential when serial is over +V. That's actually described in PICAXE Manual 2 under the SERIN command.

    You can use N4800_8 to get 4800 baud but also have to add "SETFREQ M8" at the start of your program. That will likely mess up servo operation as the servo timing loop halves.

    The PICAXE SERIN has to match whatever protocol you are feeding into it while for the Pin 3 polling to work you need the protocol to provide for that. Alternatively you can use another PICAXE to do the conversion from iPAQ to the AXE024, or use a different PICAXE member to handle the serial and drive the servos.

    There are two approaches to take with what you currently have; make the iPAQ work with the PICAXE or make the PICAXE work with the iPAQ, and in this case the specific AXE024. Both have their constraints within which you have to work with. Getting the iPAQ to send what the PICAXE would like ( using 2400 baud, slight change to what is sent ) would seem the easiest approach though I don't know the iPAQ capabilities. Once you have that setup working you can then move on

    The ideal start would be to write a test program for the iPAQ ( or the PC AUTOP program ) to send out serial data, the PICAXE to read that and report to the PC what it is receiving, then the protocol and serial can be tweaked for reliable operation if needs be, then servos added.

  10. #10
    Technical Support
    Join Date
    Jan 1970
    Location
    UK
    Posts
    20,058

    Default

    If we're working with the protocol the iPAQ / AUTOP puts out, that's "127 nn ss" and the PICAXE should catch them at 4800 baud, if it can determine there's a data transmission occuring when it polls Pin 3. I'd have thought there's a good chance it would poll something high, then wait and read the next data. You may lose some data but it should work.

    You can try the following to see if anything is getting received by the PICAXE ...

    Code:
    #Picaxe 08M
    #Terminal 9600
    SetFreq M8
    Do
      If pin3 = 1 Then
        SerTxd( "pin3=1", CR, LF )  
      End If 
    Loop
    Then try ...

    Code:
    #Picaxe 08M
    #Terminal 9600
    SetFreq M8
    Do
      If pin3 = 1 Then
        SerIn 3, N4800_8, (127), b0, b1
        SerTxd( "b0=", #b0, " b1=", #b1, CR, LF )  
      End If 
    Loop

Bookmarks

Posting Permissions

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