mixing joy stick


Closed Thread
Results 1 to 18 of 18

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Never had a Tank before. But it sounded like an interesting way to spend the evening.

    It might do it all. Or it might blow a loogie.
    Code:
    DeadBandX  CON 10      ; center mechanical Dead Area
    DeadBandY  CON 5
    JoyX       VAR BYTE    ; A/D values from joystick
    JoyY       VAR BYTE
    TrimX      VAR BYTE
    TrimY      VAR BYTE
    Xcorr      VAR WORD    ; corrected values (x-128)
    Ycorr      VAR WORD    ;   puts center at 0,0
    Left       VAR WORD    ; Left Tread
    Right      VAR WORD    ; Right Tread
    LeftDir    VAR BIT     ; Tread directions  1 = backwards
    RightDir   VAR BIT
    
    Main:
        ADCIN 0, JoyX                            ; get Joystick values
        ADCIN 1, JoyY
        ADCIN 2, TrimX                           ; Joystick Center trims
        ADCIN 3, TrimY                           ;  set to 128 if not used
        
        Xcorr = JoyX - 128 + (TrimX >> 3) - 16   ; adjust center position to 0
        Ycorr = JoyY - 128 + (TrimY >> 3) - 16
        IF ABS(Xcorr) < DeadBandX THEN Xcorr = 0 ; center deadband
        IF ABS(Ycorr) < DeadBandY THEN Ycorr = 0
    
        Left  = Ycorr + Xcorr                    ; Mix Tread speeds 
        Right = Ycorr - Xcorr
         
        LeftDir = Left.15                        ; Tread Direction
        RightDir = Right.15                      ;  1 = backwards
        
        Left = ABS(Left)                         ; make values positive
        Right = ABS(Right)
        
        if Left > 127 then Left = 127            ; Clamp max outputs 
        if Right > 127 then Right = 127
        
        ; Drive motors here
        ; LeftDir indicates the direction of the Left tread
        ; Left is the Speed of the motor 0 - 127
        ; Same for Right Track
    GOTO Main
    DT

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    Never had a Tank before. But it sounded like an interesting way to spend the evening.
    It might do it all. Or it might blow a loogie.
    What!?! You live in CA. and never had a tank?
    Slick bit of code...not nearly enough colons in there, but slick nonetheless... I'm hanging on to it for future use.

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Here ya go ski. Is this better ...
    Code:
    ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    :DeadBandX  CON 10      ; center mechanical Dead Area                      :
    :DeadBandY  CON 5                                                          :
    :JoyX       VAR BYTE    ; A/D values from joystick                         :
    :JoyY       VAR BYTE                                                       :
    :TrimX      VAR BYTE                                                       :
    :TrimY      VAR BYTE                                                       :
    :Xcorr      VAR WORD    ; corrected values (x-128)                         :
    :Ycorr      VAR WORD    ;   puts center at 0,0                             :
    :Left       VAR WORD    ; Left Track                                       :
    :Right      VAR WORD    ; Right Track                                      :
    :LeftDir    VAR BIT     ; Tread directions  1 = backwards                  :
    :RightDir   VAR BIT                                                        :
    :                                                                          :
    ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    :Main:                                                                     :
    :    ADCIN 0, JoyX                            ; get Joystick values        :
    :    ADCIN 1, JoyY                                                         :
    :    ADCIN 2, TrimX                           ; Joystick Center trims      :
    :    ADCIN 3, TrimY                           ;  set to 128 if not used    :
    :                                                                          :
    :    Xcorr = JoyX - 128 + (TrimX >> 3) - 16   ; adjust center position to 0:
    :    Ycorr = JoyY - 128 + (TrimY >> 3) - 16                                :
    :    IF ABS(Xcorr) < DeadBandX THEN Xcorr = 0 ; center deadband            :
    :    IF ABS(Ycorr) < DeadBandY THEN Ycorr = 0 ;                            : 
    :                                                                          :
    :    Left  = Ycorr + Xcorr                    ; Mix Tread speeds           :
    :    Right = Ycorr - Xcorr                                                 :
    :                                                                          :
    :    LeftDir = Left.15                        ; Tread Direction            :
    :    RightDir = Right.15                      ;  1 = backwards             :
    :                                                                          :
    :    Left = ABS(Left)                         ; make values positive       :
    :    Right = ABS(Right)                                                    :
    :                                                                          :
    :    if Left > 127 then Left = 127            ; Clamp max outputs          :
    :    if Right > 127 then Right = 127          ;                            : 
    :                                                                          :
    :    ; Drive motors here                                                   :
    :    ; LeftDir indicates the direction of the Left tread                   :
    :    ; Left is the Speed of the motor 0 - 127                              :
    :    ; Same for Right Track                                                :
    :GOTO Main                                                                 :
    ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    Still compiles.
    DT

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    dx con 10:dy con 5:jx var byte:jy var byte:tx var byte:ty var byte:xc var word:yc var word:lt var word:rt var word:ld var bit:rd var bit
    main: adcin 0,jx:adcin 1,jy:adcin 2,tx:adcin 3,ty:xcr=jx-128+(tx>>3)-16:yc=jy-128+(ty>>3)-16:IF ABS(Xc) < dx THEN Xc = 0
    IF ABS(Ycorr) < dy THEN Ycorr = 0
    lt=yc+xc:rt=yc-xc:ld=lt.15:rd=rt.15:lt=abs(lt):rt=abs(rt):if Lt > 127 then Lt = 127
    if Rt > 127 then Rt = 127
    GOTO Main
    That's what I'm talkin' 'bout...

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Eeeeuuuwww ...

    Cleanup on Isle #2

    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=2403" />
    DT

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    Eeeeuuuwww ...
    Cleanup on Isle #2
    To quote somebody else...
    Maybe you want a:

    Cleaup on Aisle #2

  7. #7
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    No, I think you have your own little Island there.

    The Colon Isle.

    Population 1.
    DT

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    No, I think you have your own little Island there.
    The Colon Isle.
    Population 1.
    This Isle has been Colon-ized!
    Oh, and population 2.5 (got one that's just over half-way done cookin' in the oven)

  9. #9
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    This Isle has been Colon-ized!
    Good one!

    Oh, and population 2.5 (got one that's just over half-way done cookin' in the oven)
    That makes it a "semi-colon" ...
    So it's commented out.
    -0.5
    DT

  10. #10
    Join Date
    Apr 2007
    Posts
    53


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    Eeeeuuuwww ...

    Cleanup on Isle #2

    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=2403" />
    Is this anything like colon cleansing???.......

Similar Threads

  1. Parallax Memory Stick Datalogger using SPI
    By djmachine in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 26th March 2009, 03:04
  2. Mixing basic and assembly
    By ManInMotion in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 23rd September 2008, 09:48
  3. Displaying messages with only 7 (or 4) LEDs on a stick...
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 20th May 2007, 08:35
  4. PBP and assembler mixing - weird goings-on?
    By Giulio in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 13th November 2006, 21:17
  5. USB memory stick
    By Demon in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 12th July 2005, 20:57

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts