Shop OBEX P1 Docs P2 Docs Learn Events
Diffculties with MATLAB-BS2 Serial Interface — Parallax Forums

Diffculties with MATLAB-BS2 Serial Interface

Joe D.Joe D. Posts: 1
edited 2013-11-15 14:23 in BASIC Stamp
Hello. This is the first time that I have posted on the Parallax forum – I appreciate any feedback provided. My goal is to create an autonomous Boe-Bot that can navigate an obstacle course using a machine vision algorithm processed in Matlab. I need Matlab to send two arrays of guidance data, one containing distances and a second containing left/right turns, through a serial interface with the BS2 microcontroller. At the moment I’m trying to pass a single variable, like 100, from Matlab to the BS2 in order to test whether the servos on the Boe Bot can be controlled. After reading the SERIN instructions in the BS2 manual and reviewing the relevant posts on the Parallax forum I believe that I have the correct code. When I execute the Matlab file the lights flicker on the BS2, which I think indicates that it is receiving the data, but the servos never move. Also, I don’t receive any errors in Matlab. Here is my code:
Matlab:
xx=100;
s = serial('COM8','Baudrate',9600);
s.terminator ='CR';
fopen(s);
fprintf(s,'%d\n',xx);
fclose(s)
delete(s)
clear s

Basic Stamp:
' {$STAMP BS2}
' {$PBASIC 2.5}

serData VAR Byte
counter VAR Byte
Baud CON 84

SERIN 16, Baud, [DEC serData]

FOR counter = 1 TO serData
PULSOUT 13, 650
PAUSE 20
NEXT

END

Comments

  • Buck RogersBuck Rogers Posts: 2,187
    edited 2013-11-14 20:40
    Joe D. wrote: »
    Hello. This is the first time that I have posted on the Parallax forum – I appreciate any feedback provided. My goal is to create an autonomous Boe-Bot that can navigate an obstacle course using a machine vision algorithm processed in Matlab. I need Matlab to send two arrays of guidance data, one containing distances and a second containing left/right turns, through a serial interface with the BS2 microcontroller. At the moment I’m trying to pass a single variable, like 100, from Matlab to the BS2 in order to test whether the servos on the Boe Bot can be controlled. After reading the SERIN instructions in the BS2 manual and reviewing the relevant posts on the Parallax forum I believe that I have the correct code. When I execute the Matlab file the lights flicker on the BS2, which I think indicates that it is receiving the data, but the servos never move. Also, I don’t receive any errors in Matlab. Here is my code:
    Matlab:
    xx=100;
    s = serial('COM8','Baudrate',9600);
    s.terminator ='CR';
    fopen(s);
    fprintf(s,'%d\n',xx);
    fclose(s)
    delete(s)
    clear s

    Basic Stamp:
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    serData VAR Byte
    counter VAR Byte
    Baud CON 84

    SERIN 16, Baud, [DEC serData]

    FOR counter = 1 TO serData
    PULSOUT 13, 650
    PAUSE 20
    NEXT

    END

    Hello!
    Interesting. I have Matlab here, I originally arranged for an eval of the thing for a completely different platform. It never occurred to me to try it for the Stamp, and indeed for a BoEBot. Did you by chance try that out on just the device as connected to the servo seperately? That is away from the whole platform as such.

    I mean arrange the BoE with your servo, but not assembled as the bot, see if the servo does move. In that case if it does not, then start seeking other solutions.
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2013-11-15 07:15
    Hi, the data you send has a couple of options, the byte data can be formatted as a string of ASCII characters or the byte data can be plain and simple binary values.

    The DEC formatter of the Stamp is used for an ASCII string of characters.

    I'm a little rusty on C but it seems your Matlab code is sending a binary value ( %d ) which is fine but you need to adjust the SERIN at the Stamp.
    SERIN 16, Baud, [serData]
    

    the above will receive 256 values between 0 and 255.

    Jeff T.
  • stamptrolstamptrol Posts: 1,731
    edited 2013-11-15 09:56
    Also, you send the same PULSOUT over and over. That would tell the servo to stay in the same position.
  • GenetixGenetix Posts: 1,754
    edited 2013-11-15 14:23
    The BOE-Bot uses Continuous Rotation Servos so unless the value is 750 they will always move. That brings up a good point though, where is the PULSOUT for the other servo?
    Also, since the BOE-Bot should be autonomous it should use a wireless device to communicate with the PC rather than dragging a cable. There is an RF Transceiver, Bluetooth Module, or a ZigBee.
    Just remember that the BS2 uses integers and does not have a very large memory.
Sign In or Register to comment.