Shop OBEX P1 Docs P2 Docs Learn Events
Using Keyboard.spin for keyboard control for robot arm — Parallax Forums

Using Keyboard.spin for keyboard control for robot arm

stevetronikstevetronik Posts: 15
edited 2010-01-12 02:36 in Propeller 1
Hi all, I'm new to using Propeller and new to the spin language.

I'm trying to program the board to accept keyboard command to control my robotic arm.

the keyboard demo .spin uses tv to display the Hex of the key pressed. I'm trying to achieve not displaying but rather a conditional keypress in C it would be something like this

pseudo code:
if kpress = $C1{ ;$C1 is left ... i think
robot arm will move left
}

because i have tried many method to detect the keypress value, the one in the demo uses "term.hex(keyboard.getkey)" is there other way to get the hex value rather than going through the TV/VGA (i'm using VGA) object.

Thank you and regards.

Note: i'm using AX-12 Smart Arm

Comments

  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2010-01-03 02:46
    You might do something like this...

    CON
    
       _clkmode  = xtal1 + pll16x
       _xinfreq  = 5_000_000
       
       keyboard  = 26    
    
    OBJ
         key   : "comboKeyboard"             ' Keyboard Driver
    
    PUB Main
    
      key.start(keyboard)
    
      keyboard
      
    PUB keyboard | keystroke
       keystroke:=0
       repeat
         keystroke := key.key
    
          if keystroke == 107  'l
             'move robotic arm left
    
          if keystroke == 114  'r
             'move robotic arm right
       
    
    




    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    New to the Propeller?

    Visit the: The Propeller Pages @ Warranty Void.
  • stevetronikstevetronik Posts: 15
    edited 2010-01-03 02:56
    i'll try it on monday, the board is in the lab. but i seem to understand what you meant. rather than keyget, i get it from key

    Thank you
  • rjo_rjo_ Posts: 1,825
    edited 2010-01-03 06:36
    Steve,

    There are all kinds of questions like this that will pop up along the way. Probably the best place to go to get templates for all kinds of functions is Mike Green's femtobasic and Oldbit's PropDos.

    Rich
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2010-01-03 06:44
    I'll second rjo's suggestion to examine FemtoBASIC. Most of the good stuff that you find in PropDOS was gleaned from Mike's FemtoBASIC code. It's a good "learn-by-example" way of getting into Spin.

    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    New to the Propeller?

    Visit the: The Propeller Pages @ Warranty Void.
  • stevetronikstevetronik Posts: 15
    edited 2010-01-04 03:20
    Hi Oldbitcollector

    I just realised that you are using combokeyboard.spin as your driver,

    "comboKeyboard" ' Keyboard Driver

    i tested using keyboard.spin, there was no reaction from it.

    where can i get a copy combokeyboard.spin (edit, i have found the driver for combokeyboard.spin by michael green)

    edit: with combokeyboard i am still unable to detect the keystroke, will post my source soon

    also, how do i open propdos 1.6 or 1.7b, not the usual extention i am familiar with

    Regards

    Steve,

    P.S in the meantime i'll venture into femtobasic codes. thanks for the recommendation

    Post Edited (stevetronik) : 1/4/2010 3:51:56 AM GMT
  • AribaAriba Posts: 2,690
    edited 2010-01-04 04:04
    stevetronik said...
    ...the keyboard demo .spin uses tv to display the Hex of the key pressed. I'm trying to achieve not displaying but rather a conditional keypress in C it would be something like this

    pseudo code:
    if kpress = $C1{ ;$C1 is left ... i think
    robot arm will move left
    }
    You can use the keystate methode of keyboard.spin:
    if kb.keystate($C0) == TRUE
    { robot arm will move left }
    elseif kb.keystate($C1) == TRUE
    { robot arm will move right }
    ...
    stevetronik said...
    because i have tried many method to detect the keypress value, the one in the demo uses "term.hex(keyboard.getkey)" is there other way to get the hex value rather than going through the TV/VGA (i'm using VGA) object
    You find a list of all the hex values at the end of the Keyboard.spin file. If you open Keyboard,spin in a Tab and click on "Documentation" under the Tabs, you get a description of all the methods and hex values.

    You need this codes only for the special Keys (Cursor, FunctionKeys..), for the 'normal' Keys, you can use "x" in Spin to get the ASCII value of x:

    if kb.keystate("A") == TRUE
    ' do something
    elseif kb.keystate("Z") == TRUE
    ' do something

    And finally: combokeyboard.spin has the same functions as keyboard.spin, but works also with a Hydra Board.

    Andy
  • stevetronikstevetronik Posts: 15
    edited 2010-01-04 04:42
    Thank you Andy

    It worked.

    Edit: rather than posting another notice for this small question i have.

    is there anyway to split and combine hexadecimal value


    example
    $03 and $FF into $03FF

    and

    $01FF into $01 and $FF

    Post Edited (stevetronik) : 1/4/2010 5:31:17 AM GMT
  • Mike GMike G Posts: 2,702
    edited 2010-01-04 11:10
    Sure,

    ($03 * $100) + $FF = $03FF

    or you could shift $03 to the left 8 times then add $FF

    To split the bytes you can use logical AND

    low byte = $10FF AND $FF = $FF
    high byte = ($10FF AND $FF00) / $100 = $03
  • AribaAriba Posts: 2,690
    edited 2010-01-04 15:41
    And the same in Spin syntax:
    var1 := $03
    var2 := $FF
    var3 := var1<<8 + var2  '=$03FF
    
    var3 := $01FF
    var1 := var3>>8 & $FF   '=$01
    var2 := var3 & $FF      '=$FF
    
    
    



    Andy
  • stevetronikstevetronik Posts: 15
    edited 2010-01-05 02:57
    Thank you Mike G and Andy, both of yer a life saver [noparse]:D[/noparse]

    Steve
  • ratronicratronic Posts: 1,451
    edited 2010-01-05 16:51
    @stevetronik , I have played around with the ax12 servo's a bit· and the propeller·(I am no expert!). I have used them with a joystick, a keyboard, and a mouse. Mine isn't the ax12 smart arm - just built from the basic kit with four ax12 servos. If you need some help you can p.m. me. I attached a video of my simple arm (with no gripper) using the joystick.

    http://www.youtube.com/watch?v=-xU8IUJ8SD4

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ···································Fix it, if ain't broke!


    D Rat

    Dave Ratcliff N6YEE
  • ratronicratronic Posts: 1,451
    edited 2010-01-08 15:19
    @stevetronik here is the code I mentioned in the p.m. - I will look at looking to get the keyboard operation it a bit smoother. Do you have code that's not in C?


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ···································Fix it, if ain't broke!


    D Rat

    Dave Ratcliff N6YEE
  • stevetronikstevetronik Posts: 15
    edited 2010-01-12 02:36
    attached below is the code i mentioned in the pm, its somewhat simple and crude, any advice to improve it would be much appreciated [noparse]:D[/noparse].

    another issue i forget to mentioned about in the pm was, that keyboard control isn't the final objective, keyboard control was just something i'm trying to make the board to regconise simple inputs to do 'set task' , the actual thing would be that the board would recieve instruction from another microcontroller or pc (i've being thinking of using hyper terminal to send and recieve instruction)
    thought it would be related to the idynabus mike gebhard wrote although it writte to use with BS2 code and a Board of Education BOE board. (planning to use PC and the hyper terminal apps in windows to simulate BOE)
    have you used idynabus.spin?
Sign In or Register to comment.