BS2p + Matlab + Servo (communication & control)
Amit
Posts: 27
I was wondering if there is any way to have the stamp do two things at once.· Right now I have the stamp connected to MATLAB via a·RS-232 connection and to a servo.· I have the communication between MATLAB and the·BS2p working adequately (although if anyone has any suggestions on doing this it would be appreciated).· The problem is that while I am communicating with MATLAB to get the updated control parameters, I need the servo to either hold its current position or execute a particular movement.· Currently, as soon as the stamp finishes sending the pulse train and is waiting for the next input, the servo goes limp since there is no control signal.· I am trying to use only one STAMP.·
I need my code to loop as fast as possible.· As of now the BS2p takes spends most of its time waiting for the "ZZ" flag (refer to code below) and then receiving the updated pulse.· I realize that right now I have a very simple control law that could be easily implemented right on the stamp but the goal is to implement a control law that is much more advanced and highly nonlinear (which would be difficult to do onboard).· Is there any way to reduce the downtime involved with the communication?· I have reviewed the MATLAB interface example http://www.parallax.com/dl/docs/article/BS2MatlabPaper.pdf·but that did not address timing or handshaking issues.· Does anyone have any suggestions on how to streamline this?· I have attached a simplified version of my MATLAB code and BS2 code for reference.
************************************************************
start:
· LOW 5························ 'turn off status LEDs
· LOW 6
· LOW 7
· LOW 8
· SERIN 9, 240, [noparse][[/noparse]WAIT("ZZ")]··· 'flag to sync with MATLAB
· PAUSE 50
· HIGH 5······························· 'indicate flag received
· SERIN 9, 240, [noparse][[/noparse]DEC pulse]····· 'input updated pulse width
· GOSUB servo······················· 'move servo
· HIGH 6······························· 'turn on LED 6 to indicate pulse received
· GOSUB ReadStrain······················· 'read strain gage
· SEROUT 10, 240, [noparse][[/noparse]DEC Strain, CR]·· 'output strain measurement to MATLAB
· HIGH 7
· GOSUB servo······························ 'hold servo position
· GOSUB ReadPot·························· ·'read potentiometer
· SEROUT 10, 240, [noparse][[/noparse]DEC Pot, CR]······ 'output potentiometer measurement to MATLAB
· HIGH 8······································· 'indicator LED
· GOSUB servo······························· 'hold servo position
GOTO start
*****************************************************
Thanks in advance!
-Amit
I need my code to loop as fast as possible.· As of now the BS2p takes spends most of its time waiting for the "ZZ" flag (refer to code below) and then receiving the updated pulse.· I realize that right now I have a very simple control law that could be easily implemented right on the stamp but the goal is to implement a control law that is much more advanced and highly nonlinear (which would be difficult to do onboard).· Is there any way to reduce the downtime involved with the communication?· I have reviewed the MATLAB interface example http://www.parallax.com/dl/docs/article/BS2MatlabPaper.pdf·but that did not address timing or handshaking issues.· Does anyone have any suggestions on how to streamline this?· I have attached a simplified version of my MATLAB code and BS2 code for reference.
************************************************************
start:
· LOW 5························ 'turn off status LEDs
· LOW 6
· LOW 7
· LOW 8
· SERIN 9, 240, [noparse][[/noparse]WAIT("ZZ")]··· 'flag to sync with MATLAB
· PAUSE 50
· HIGH 5······························· 'indicate flag received
· SERIN 9, 240, [noparse][[/noparse]DEC pulse]····· 'input updated pulse width
· GOSUB servo······················· 'move servo
· HIGH 6······························· 'turn on LED 6 to indicate pulse received
· GOSUB ReadStrain······················· 'read strain gage
· SEROUT 10, 240, [noparse][[/noparse]DEC Strain, CR]·· 'output strain measurement to MATLAB
· HIGH 7
· GOSUB servo······························ 'hold servo position
· GOSUB ReadPot·························· ·'read potentiometer
· SEROUT 10, 240, [noparse][[/noparse]DEC Pot, CR]······ 'output potentiometer measurement to MATLAB
· HIGH 8······································· 'indicator LED
· GOSUB servo······························· 'hold servo position
GOTO start
*****************************************************
Thanks in advance!
-Amit
Comments