Shop OBEX P1 Docs P2 Docs Learn Events
Electronic speed control — Parallax Forums

Electronic speed control

bboy8012bboy8012 Posts: 153
edited 2008-03-09 17:23 in Propeller 1
Question is it possible to have like a listener on the prop? I.E. I want to control my speed control with my joystick, I have the app developed in java that sends it to the propeller via the serial port, but how would I get it to change the speed as say i move the slider?·Would I have to use 2·cogs for it?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Hunger hurts, starvation works!

Comments

  • jazzedjazzed Posts: 11,803
    edited 2008-03-06 23:24
    Send the "value" of the slider to the prop in a mutually understood packet as the event happens ?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    jazzed·... about·living in·http://en.wikipedia.org/wiki/Silicon_Valley

    Traffic is slow at times, but Parallax orders·always get here fast 8)
  • bboy8012bboy8012 Posts: 153
    edited 2008-03-07 00:10
    mutually understood packet? wouldnt the packet just be the value?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Hunger hurts, starvation works!
  • jazzedjazzed Posts: 11,803
    edited 2008-03-07 00:14
    bboy8012 said...
    mutually understood packet? wouldnt the packet just be the value?

    If that's what you want it to be burger.gif .

    Assuming you might want to control other things with your program, you could construct
    a "packet" with command types and values for receiving prop to "consume".

    Hmm, getting·close to dinner time I guess [noparse]:)[/noparse]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    jazzed·... about·living in·http://en.wikipedia.org/wiki/Silicon_Valley

    Traffic is slow at times, but Parallax orders·always get here fast 8)
  • bboy8012bboy8012 Posts: 153
    edited 2008-03-07 00:20
    Ok thanks more researching now

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Hunger hurts, starvation works!
  • Timothy D. SwieterTimothy D. Swieter Posts: 1,613
    edited 2008-03-07 00:21
    bboy8012 -

    I am not clear on what you are attempting to do.· So, based on what you said and what I assume, let me offer some advice.· If I am off base, let me know and I will try and help you.

    You have a Java program that works on a PC and is sending serial data to the Propeller, right?· Have you proven out that interface?· Have you confirmed that a value sent from the PC is correctly received by the Prop?· For the packet, you could simple send an byte (8-bit) value for the speed or you could devise a packet of data with a header, payload and checking mechanism (CRC, etc).· The serial receive routine would be modified to only read packets with a certain header and then only move the payload to the buffer if the checking mechanism is matches, which ensures the packet arrived unharmed during transmission.

    Next, in the Prop you will have at least two cogs going, maybe more depending on your application.· One cog is a serial receiving cog.· This cog could run the Parallax serial object.· This cog has a buffer for the values it receives.· Another cog would have your speed control program running.· Every time the speed control program loops, at the top of the loop, it should check the buffer of the serial COG to see if there is a new value.· If there is a new value, then use the new value for the speed control.· If there· isn't a new value, continue using the old value.

    Is your joystick USB or some other special device that it needs to be attached to a PC?· If it is of the older style, then perhaps you could attach it directly to the Propeller.· Just a thought, but maybe not practical for your application.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Timothy D. Swieter

    www.brilldea.com·- check out the uOLED-IOC, an I/O expansion for the uOLED-96-PROP
    www.tdswieter.com
    One little spark of imagination is all it takes for an idea to explode
  • bboy8012bboy8012 Posts: 153
    edited 2008-03-07 03:15
    You hit the spot Tim. I have confirmed that my serial connection app works by just sending characters. Next my usb joystick is work because I have the values of the axes print to console in java. The problem I am having is that I havent got far enough with the prop to do advanced stuff like that. The java side I have no problem with. I have been looking for examples similar to mine, but havent found any. So I am going at it blindly.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Hunger hurts, starvation works!
  • bboy8012bboy8012 Posts: 153
    edited 2008-03-07 03:39
    {{JFly001.spin
    This application is a start in my UAV project. Phases are in the title if JFly001.
    001 is just to test the control center I have made in java and the joystick I am using. ie send the values from my
    java app to the prop.}}
    CON
       _clkmode     = xtal1 + pll16x
       _xinfreq     = 5_000_000
    VAR
      
    OBJ
      esc        : "ElectriflyESC"
    PUB start
      'cognew()
      'cognew()                     //start listener for joystick commands
      esc.initialize
      esc.delay
    PUB recieveThrottle
    

    this is what I have so far which is nothing, as you can see

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Hunger hurts, starvation works!

    Post Edited (bboy8012) : 3/7/2008 3:45:02 AM GMT
  • Timothy D. SwieterTimothy D. Swieter Posts: 1,613
    edited 2008-03-07 03:44
    bboy8012 -

    What propeller tools do you have? DO you have a demo board or a proto board or a SPIN Stamp or similar?

    It sounds like you know programming, so learning spin/asm shouldn't be too difficult. The idea of eight cogs may throw a loop in your thinking every now and again, but rest assured that the forum is here!

    So, what I would do next is to experiment with the Parallax FullDuplex serial object. See the demo program. Use your Jave program, hyper terminal, or whatever to experiment sending characters to the Propeller and back to the computer. If you have the demo board, then you can setup a VGA or TV to display the characters that are received by the Propeller.

    Once you have the serial routine getting parameters, then you are almost there, well as far as receiving data that is.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Timothy D. Swieter

    www.brilldea.com·- check out the uOLED-IOC, an I/O expansion for the uOLED-96-PROP
    www.tdswieter.com
    One little spark of imagination is all it takes for an idea to explode

    Post Edited (Timothy D. Swieter) : 3/7/2008 4:13:26 AM GMT
  • bboy8012bboy8012 Posts: 153
    edited 2008-03-07 04:07
    I have the education kit. Thanks for the guidance

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Hunger hurts, starvation works!
  • Timothy D. SwieterTimothy D. Swieter Posts: 1,613
    edited 2008-03-07 12:46
    Look in the library or object exchange for PC Debug. This object uses the serial object to share data with a PC. This should give you an idea on how to setup the serial portion.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Timothy D. Swieter

    www.brilldea.com·- check out the uOLED-IOC, an I/O expansion for the uOLED-96-PROP
    www.tdswieter.com
    One little spark of imagination is all it takes for an idea to explode
  • bboy8012bboy8012 Posts: 153
    edited 2008-03-09 03:43
    This is what I have, but I dont know why I cant get it just to go to a speed? I have the initialize part working, its just when it ask me to enter speed I enter it, and nothing happens. I looked at it, and it seems fine to me. Can another set of eyes point out my error please. Thanks ThrottleControl is the top app

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Hunger hurts, starvation works!
  • Timothy D. SwieterTimothy D. Swieter Posts: 1,613
    edited 2008-03-09 07:15
    bboy8012 -

    When posting code it best to use the file|archive feature of the Propeller Tool. When using the archive function it will create a zip file that stores all the files/objects used. Also a readme text file is created displaying the heirarchy of the objects in relation to each other. This helps to ensure you post all of your code so others can help. For instance, I don't have a "FullDuplexSerialPlus" object.

    In only looking at your "ThrottleControl.spin" I would say it is either the Serial.getDec or it is the other objects that are causing your trouble. Here is what I do.

    -Use the serial code you have now
    -add to it so that it echos back (to the PC) the speed you typed in the terminal
    -If it echos back correctly, then look at the other objects, if it doesn't echo correctly then look at your serial code

    Please post more information about ".gedDec". I am suspecious of this function. If you are using something like Hyperterminal and you type a speed "2" the getDec may work. (again I haven't seen the code). If you type a speed "100" it may not work because 2 was sent as one byte from the computer and 100 may have been sent as three bytes - a "1", a "0" and a "0". If you wrote a terminal program in Java, then perhaps the speed is sent as one byte. Again, this assumes that .getDec is only grabbing one byte.

    I hope this helps. It is kind of vague. Post an archive zip and I will look at it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Timothy D. Swieter

    www.brilldea.com·- check out the uOLED-IOC, an I/O expansion for the uOLED-96-PROP
    www.tdswieter.com
    One little spark of imagination is all it takes for an idea to explode
  • bboy8012bboy8012 Posts: 153
    edited 2008-03-09 08:06
    I checked the input on the top level class and it gave me back what I entered. Then I tried to see if I could place a debug statement on the supporting spin file, but did not recieve what I entered. So I have to start debuggin that. And all this is just done through the terminal I have even entered my java app into the mix. Thanks for the heads up on the archive I never knew aobut that.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Hunger hurts, starvation works!
  • Timothy D. SwieterTimothy D. Swieter Posts: 1,613
    edited 2008-03-09 09:51
    The first problem I see is that you are starting a FullDuplexSerialPlus in the ThrottleControl Object and in the Throttle object. Though each instance will run in its own cog, it will cause trouble on the output/input pins because they are the same pins. You can obly have one serial object using the pins, otherwise you will get garbage or no response.

    I recommend in ThrottleControl, have your prompt for input. (I see how FullDuplexSerialPlus works, nice object to retrieve a string). After you get the input, immediately respond with "your input was xxxx". Then put the value into your throttle routine as you are doing. Write a quick method in the Throttle routine to read what oldPulse is. You will have to promote oldPulse from a routine based variable to a object based variable. (place in the var section of the Throttle code). Doing hte above will help to verify that the data is getting from the PC, into the Prop and then into the correct COG. After you confirm the above, the next step would be to add in the trottle/ESC code.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Timothy D. Swieter

    www.brilldea.com·- check out the uOLED-IOC, an I/O expansion for the uOLED-96-PROP
    www.tdswieter.com
    One little spark of imagination is all it takes for an idea to explode
  • Cats92Cats92 Posts: 149
    edited 2008-03-09 15:37
    I tried something like that to send commands with a joystick and radio to my bot.

    Meeting problems with getdec (I dont know exactly why!)·I used fullD.getstr(@mystring), ·it is not nice but it works

    Command strings are like this: ·KjxAR (K to identify the robot, J for joystick, X unused, A and R letters for the C and D joystick axis).

    The values for left and right servos are captured in a loop with

    ··· arg2:=mystring[noparse][[/noparse]2] ' pour pulseleft· joystick AXIS D
    ··· arg3:=mystring[noparse][[/noparse]3]· 'pour pulseright joystick AXIS C
    ··· Nfois:=arg1
    ··· Lduree:=1274+(arg2*3)
    ··· Rduree:=1274+(arg3*3)

    Another loop in a cognew(run, @stack2) use the Lduree and Rduree values to send pulses to the servos.

    If it may help , here is my program

    Cats92
  • bboy8012bboy8012 Posts: 153
    edited 2008-03-09 17:23
    Thanks cats92 I will take a look at it. And Tim I will try what you said to varify I am getting the variable in the right cog. Thanks

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Hunger hurts, starvation works!
Sign In or Register to comment.