Shop OBEX P1 Docs P2 Docs Learn Events
vb bs2 and psc! — Parallax Forums

vb bs2 and psc!

rounderrounder Posts: 18
edited 2005-03-01 04:19 in Robotics
Greetings all, I am having a problem with a simple little project I wonder if someone might have any thoughts on.
I am trying to send data from a vb app to my bs2, then relay this data to a psc. This is an adaptation of the simple "send data to a micon" tutorial at rentron. Here is the VB code, followed by the bs2 code.· I am using a joystick control that returns a large range, I have scaled it accordingly and have determined that servopos is a good value between 250-1250(using a label to see value realtime and by inserting a breakpoint and reading value)·this is after the mscomm output event, so I assume that the data was sent. So I guess the problem is in my bs2 code. Does anyone have any thoughts?, Thanks in advance!

edit*· I should note that in the mscomm.output event I am unable to wrap servopos with a chr$, I am not sure why but an error is raised when I do, could this be the problem, is the data the wrong "type" for the serin command on the bs2. I know that my psc is connected correctly because I can move the servos with simple bs2 code. THANKS AGAIN!

VB6.0 cod
Option Explicit
Public Sub Form_Load()
JKJoystick1.TStart
Dim Pins As Long
For Pins = 0 To 15
    cboPinNumber.AddItem CStr(Pins)
Next Pins
cboPinNumber.ListIndex = 0
optState(0).Value = True
MSComm1.CommPort = 1
MSComm1.Settings = "2400,N,8,1"
MSComm1.DTREnable = False
MSComm1.PortOpen = True
End Sub
Public Sub JKJoystick1_PosChange(NewX As Long, NewY As Long, NewThrottle As Long, NewRudder As Long)
Dim PinNumber As Long
Dim servopos As Long
servopos = ((NewX / 65.534 + 250))
PinNumber = cboPinNumber.ListIndex
MSComm1.Output = Chr$(255) & Chr$(PinNumber) & servopos
Label3.Caption = servopos
End Sub
Private Sub Form_Unload(Cancel As Integer)
MSComm1.PortOpen = False
End Sub


BS-II code
·
' {$STAMP BS2}
' {$PBASIC 2.5}
PinNumber  VAR   Byte
PinState   VAR   Word
ch VAR Byte
pw VAR Word
ra VAR Byte
sdat CON 15
baud CON 396
ra = 10
Main:
SERIN 16,16780,[noparse][[/noparse]WAIT(255),PinNumber,PinState]
SEROUT sdat, Baud+$8000,[noparse][[/noparse]"!SC", PinNumber, ra, PinState.LOWBYTE, PinState.HIGHBYTE, CR]
GOTO Main




Thanks again!

Post Edited (rounder) : 3/1/2005 3:34:16 AM GMT

Comments

  • rounderrounder Posts: 18
    edited 2005-03-01 04:19
    well after several hours, quite a few smokes and some pepsi I was able to figure it out! I added a dec formatter to the serin command for the servopos variable and all is well. Amazing what a quick look at the stampworks serin command reference will teach ya. I made some other changes and it is working perfectly with 3 servos and a sidewinder joystick Here is the corrected code. If you want to try it you will need the jk joystick ocx or some other way of generating positions for your servo like a slider control.

    VB 6.0 code
    Option Explicit
    Dim xservopos As Integer
    Dim yservopos As Integer
    Dim zservopos As Integer
    Dim xoldpos As Integer
    Dim yoldpos As Integer
    Dim zoldpos As Integer
    Dim chan As Integer
    Public Sub Form_Load()
    JKJoystick1.TStart
    MSComm1.CommPort = 1
    MSComm1.Settings = "2400,N,8,1"
    MSComm1.DTREnable = False
    MSComm1.PortOpen = True
    End Sub
    Private Sub JKJoystick1_PosChange(NewX As Long, NewY As Long, NewThrottle As Long, NewRudder As Long)
    xoldpos = xservopos
    yoldpos = yservopos
    zoldpos = zservopos
    xservopos = ((NewX / 65.534 + 250))
    yservopos = ((NewY / 65.534 + 250))
    zservopos = ((NewThrottle / 65.534 + 250))
    If xservopos <> xoldpos Then chan = 0: MSComm1.Output = Chr$(255) & Chr$(chan) & xservopos
    If yservopos <> yoldpos Then chan = 1: MSComm1.Output = Chr$(255) & Chr$(chan) & yservopos
    If zservopos <> zoldpos Then chan = 2: MSComm1.Output = Chr$(255) & Chr$(chan) & zservopos
    Label3.Caption = xservopos
    Label4.Caption = yservopos
    Label5.Caption = zservopos
    End Sub
    Private Sub Form_Unload(Cancel As Integer)
    MSComm1.PortOpen = False
    End Sub
    



    stamp code
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    pos   VAR   Word
    ra VAR Byte
    sdat CON 15
    baud CON 396
    chan VAR Byte
    ra = 0
    Main:
    SERIN 16,16780,[noparse][[/noparse]WAIT(255),  chan, DEC pos]
    SEROUT sdat, Baud+$8000,[noparse][[/noparse]"!SC", chan, ra, pos.LOWBYTE, pos.HIGHBYTE, CR]
    GOTO Main
    

    Post Edited (rounder) : 3/1/2005 7:21:06 AM GMT
Sign In or Register to comment.