Shop OBEX P1 Docs P2 Docs Learn Events
PPDB: SerialTtransfer of 2 ServoValues from LinuxBox to the Board — Parallax Forums

PPDB: SerialTtransfer of 2 ServoValues from LinuxBox to the Board

nomadnomad Posts: 276
edited 2009-10-01 07:34 in Propeller 1
hi
i am working with Extended_FDSerial and Servo32

i want transfer 2 different ServoValues from my linuxBox to the Board via RS232.
values: 11_500, 21_150
1n_nnn = servoPort 0
2n_nnn = servoPort 1

with the linuxBox i can transfer the values
a) as: send :11500:21500:
acknowledge from Board "5"
b) or: repeat
send 11500
send 21500
acknowledge from board "5"

My questions:
is this possible with the Spin-Prog to receive 2 different Values
in one call
or must i do this with 2 calls

please give me some help or hints for this problem.
excuse my bad english
regards nomad

Comments

  • StefanL38StefanL38 Posts: 2,292
    edited 2009-09-28 14:08
    Hello Nomad,

    Im not really sure if I understand right what you want to do.
    For checking my understanding I write how I understand you

    You have a RS232-serial device called "Linuxbox"

    You can configure the Linuxbox to send the following string: ":11500:21500:"
    all in all 13 characters (the double-points included)

    Your questions is:

    a) Can I send the string ":11500:21500:" to the propeller ?

    b) Can the propeller acknowledge the receiving of such a string by sending the character "5" ?

    answer to both questions is YES.

    If you can make the Linuxbox send a different delimiter at the end example ":11500:21500#"
    you can use the method RxStr from the Extended_FDSerial-object (ExtFDS) to receive that string

    Sending single characters and sending complete strings is one main purpose of ExtFDS.

    If you use the following mouseclicks: Mainmenu of Propellertool
    file - archive - project ...

    You can easily create a zipfile with all your code that is needed to compile your project.
    We can take a look into your code and make detailed suggestions.
  • nomadnomad Posts: 276
    edited 2009-09-29 07:17
    hi StefanL_38
    thanks for your answer

    b) yes i can make different delimetesr in the linuxBox as: $11500:21500#
    this is no problem.

    the problem is in the propeller:

    1) propeller receive the string: $11500:21500#
    2) now the problem:
    how can i assign the string into 2 variables:
    as: long variable nickservo = 11_500
    long variable turnsservo = 21_500

    now the propeller works with this 2 variables.
    if ok, propeller send the acknowledge "5"

    i hope its now clear.


    i attached the spin-source for this project
    the linux-source is about 10_000 lines, in C++ and for my linux 64bit with a IntelQuad
    t
    thanks for help
    regards nomad

    l
  • StefanL38StefanL38 Posts: 2,292
    edited 2009-09-29 19:19
    Hello nomad,

    please create an archive of your project by using

    propeller-tool main-menu file - archive - project ...

    to create a ZIP-file that contains ALL files that are nescessary to compile your project.
    For you this is two clicks away and makes it comfortable for the people that are helping you
    that they are not forced to download objects from the obex or comment them out to make
    the project compile

    anyway:

    can you reconfige your linuxbox to send two SEPERATE strings which both start with the port without the "$" or the ":" ?
    or leave out the "$" and change the ":" and the "#" to a carriage-return

    so the string looks like that "11500<13>21500<13>"

    where <13> means ASCII_code decimal 13 which is the carriage return

    the method rxDec uses the carriagereturn as the delimiter

    see code of

    PUB rxDec : Value | place, ptr, x
    {{
       Accepts and returns serial decimal values, such as "1234" as a number.
       String must end in a carriage return (ASCII 13)
       x:= Serial.rxDec     ' accept string of digits for value
    }}   
        place := 1                                           
        ptr := 0
        value :=0                                             
        dataIn[noparse][[/noparse]ptr] := RX       
        ptr++                           x---here it checks for carriagereturn
        repeat while (DataIn[noparse][[/noparse]ptr-1] <> 13) and (DataIn[noparse][[/noparse]ptr-1] <> Delimiter)                     
    
    
    



    then your construction with using

      myInput := Serial.rxDec       ' receive bigNumbers as ServoCommands
    
    



    will work this way

      myInput1 := Serial.rxDec       ' receive bigNumbers as ServoCommands
      myInput2 := Serial.rxDec       ' receive bigNumbers as ServoCommands
    
    




    If you cant change the linuxboxstring this way:
    Every string is stored in a bytearray

     bytes MyString[noparse][[/noparse]14]  '13 characters and a zero to terminate the string
    
    



    Your string has always the SAME structure.
    Let's assume you string contains "$11500:21500#"

    this means:
    MyString[noparse][[/noparse] 0 ] = "$"
    MyString[noparse][[/noparse] 1 ] = "1"
    MyString[noparse][[/noparse] 2 ] = "1"
    MyString[noparse][[/noparse] 3 ] = "5"
    MyString[noparse][[/noparse] 4 ] = "0"
    MyString[noparse][[/noparse] 5 ] = "0"
    MyString[noparse][[/noparse] 6 ] = ":"
    MyString[noparse][[/noparse] 7 ] = "2"
    MyString[noparse][[/noparse] 8 ] = "1"
    MyString[noparse][[/noparse] 9 ] = "5"
    MyString[noparse][[/noparse] 10 ] = "0"
    MyString[noparse][[/noparse] 11 ] = "0"
    MyString[noparse][[/noparse] 12 ] = "#"
    MyString[noparse][[/noparse] 13 ] = $00 'to terminate the string
    
    



    Now you can take each single byte and convert to an integer value and do with it whatever you want.

    Example:
      Servoport := (MyString[noparse][[/noparse] 1 ] - "0")
       ServoPulse := 0
       ServoPulse := ServoPulse + (MyString[noparse][[/noparse] 2 ] - "0") * 1000  'substract "0"=48 to calculate decimal value out of ASCII-Code-value
       ServoPulse := ServoPulse + (MyString[noparse][[/noparse] 3 ] - "0") * 100
       ServoPulse := ServoPulse + (MyString[noparse][[/noparse] 4 ] - "0") * 10
       ServoPulse := ServoPulse + (MyString[noparse][[/noparse] 5 ] - "0")
    
    


    in the obex there is also a string-object for string-manipulation-operations
    as extract a substring etc. and then convert the substring "11500" to an integervalue

    best regards

    Stefan

    Post Edited (StefanL38) : 9/29/2009 7:33:33 PM GMT
  • nomadnomad Posts: 276
    edited 2009-09-30 07:13
    hi StefanL38,
    OK
    thanks a lot
    but i think, its simple, when i done my original code on linux and on spin.
    your way is slower, i must this done in realTime.
    also:
    linux send (1) propBox receive (1) send acknoledge
    linux send (2) propBox receive (2) send acknowledge
    this is faster
    but thanks for your help
    regards nomad
  • StefanL38StefanL38 Posts: 2,292
    edited 2009-09-30 15:39
    Aha important information dataprocessing has to be a fast as possible.

    Then my suggestion is to increase the baudrate up to 115200 baud this is more than 10 times faster than 9600 baud.
    and then you have time for all kinds of processing the data in spin.

    At 9600 baud the bottleneck is the baudrate not the dataprocessing

    best regards

    Stefan

    Post Edited (StefanL38) : 9/30/2009 3:59:09 PM GMT
  • nomadnomad Posts: 276
    edited 2009-10-01 07:34
    hi
    i know
    thanks for your replay
    regards nomad
Sign In or Register to comment.