I'm trying to control motion simulator with ooPic-R (firmware C.1.1+).
OoPic is connected to PC via rs232-serialport.
I should control two axis. When I'm sending orientation data trouhg
serialport. The 1st byte, 3th byte, 5th byte, ..., and so on tells the
orientation of the x-axis. And the 2nd byte, 4th byte, 6 th byte, ...,
means the orientation of the y-axis.
HOW I CAN MAKE THIS WORK ??
I'm testing my program by using two RC-servos.
I have tryed to save incoming serial data in obuffer2 and read the
bytes from there.
When I use the code below the first byte controls the servo "S" and
second byte controle the servo "S2", but also 3th, 4th and every
following bytes controls the servo "S2". So only the first byte
controls servo "s". I have also tryed two clear the buffer after the
both servos are posisioned but that doesn't seem to work.
**********************************************
Dim A As New oSerialPort
Dim buffer As New oBuffer2
Dim S As New oServo
Dim S2 As New oServo
Sub Main()
S.IOLine = 31
S.Operate = cvTrue
S2.IOLine = 30
S2.Operate = cvTrue
A.Baud = cv9600
A.Operate = cvTrue
Do
If A.Received = cvTrue Then
buffer.Value = A.Value/4
buffer.Location = 0
S.Value = buffer.Value
buffer.Location = 1
S2.Value = buffer.Value
End If
buffer.Clear = cvTrue
Loop
End Sub
********************************************
I know I could also use the 4 byte buffer that includes in
oSerialport, but I don't know how to read it from spesific address?
IS THERE ANY CHANCE TO MAKE THIS WORK LIKE THIS OR SHOULD I FIGURE OUT
SOMETHING COMPLITELY DIFFERENT?
thaks!

(You need to be a member of oopic -- send a blank email to oopic-subscribe@yahoogroups.com )
At 07:46 AM 3/13/2008, latepate_p wrote:
>Do
>If A.Received = cvTrue Then
>
>buffer.Value = A.Value/4
>
>buffer.Location = 0
>S.Value = buffer.Value
>
>buffer.Location = 1
>S2.Value = buffer.Value
>
>End If
>buffer.Clear = cvTrue
>
>Loop
>End Sub
As you know (by observation), that code does not send the odd bytes
to S and the even bytes to S2. The logic is all wrong.
You need something like this:
Byte flip
flip = 0
Do
..if A.Received Then
....flip = 1 - flip ' flip odd/even on each received byte
....if flip Then
......S = A ' odd: control first servo
....Else
......S2 = A ' even: control second servo
....End If
..End If
do any other required stuff here...
Loop
...Andy

(You need to be a member of oopic -- send a blank email to oopic-subscribe@yahoogroups.com )