Shop OBEX P1 Docs P2 Docs Learn Events
Custom robot. — Parallax Forums

Custom robot.

RJNRJN Posts: 2
edited 2009-12-08 04:42 in Robotics
Hello im using a Parallax BOE with a basic2 stamp

Im trying to get my matlab code to tell the basic procesor what to do.

The Board is hooked up to two servo motors and the matlab program is spiting out servo pulse durations (between 400-1100)

I dont know how to get multipule outputs using the fprintf comand in matlab. so i tryed to just combine the two numbers into 1 the first 4 numbers=servo1 the last 4 numbers=servo2 and use the SKIP comand to get the numbers apart but im having trouble getting this to work. i was wondering if anybody had any sugestions on how i should go about this.

hears some of my code (full code is attached)
(the project is to design a robot turret that detects movement and fires at it)
(the last bit of basic code tells the board to open the H-Gate which aplyes power to an airsoft guns dc motor)



MATLAB
=========================
x=servo1
y=servo2
yy=x*10000+y
end
%Protecting the servos string.
·x<1150
if x>450
if y<1150
if y>450
fopen(ser)
fprintf(ser,'%d\n',[noparse][[/noparse]yy]);
fclose(ser);
===============================
BASIC
======================
' {$STAMP BS2}
' {$PBASIC 2.5}
serial CON 16
baudrate CON 84
yy VAR Word
y VAR Word
x VAR Word
counter VAR Word
x = 750
main:
SERIN serial,baudrate,[noparse][[/noparse]SKIP 4, DEC yy]
FOR counter =1 TO 50
PULSOUT 13,yy
PAUSE 20
NEXT
FOR counter =1 TO 50
PULSOUT 12,x
PAUSE 20
NEXT

other junk.....
================================

Comments

  • SRLMSRLM Posts: 5,045
    edited 2009-12-04 19:02
    I have never programmed matlab before, but here is what I notice. You are outputting a number x such that 500,000 < x <1,000,000. Now, the BS2 can only hold numbers from 0 to 65,535 (2^16-1). You won't be able to do it the way that you have there. Instead, you'll need to figure out how to send multiple numbers in Matlab. My guess is that it is just another comma (,) and the second variable. Next, when you SERIN variables on the BS2 you'll need to specify WORD since the data is not byte sized (default). Finally, please properly indent your code so that it is easier to read.
  • RJNRJN Posts: 2
    edited 2009-12-08 04:42
    I figured it out i just had to add another fprint and serin comand after the first one
Sign In or Register to comment.