Forum Rule: Always post complete source code & details to reproduce any issue!
Page 2 of 5 FirstFirst 1 2 3 4 ... LastLast
Results 26 to 50 of 111

Thread: Arduino RC library

  1. #26
    Member
    Join Date
    Mar 2014
    Location
    Fremantle Western Australia
    Posts
    47
    adeptrc Good to see someone else getting into this library. I hope the RC in your handle means your a modeler.
    My poor old CRO is on its death bed so i ordered a new 100meg storage to play with my Teensies. Probably get them both about the same time. Bugger it is so hard waiting for a new toy

  2. #27
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,174
    I've updated the web page with basic documentation.

    http://www.pjrc.com/teensy/td_libs_PulsePosition.html

    The more time-consuming bits, like pictures & nice timing diagrams will have to wait until I have more time (and if any substantial number of people ever actually end up using this library....)

    I also added double buffering to the output object.

  3. #28
    Member
    Join Date
    Mar 2014
    Location
    Fremantle Western Australia
    Posts
    47
    Paul
    I sure hope the mail system you use doesn't take too long the wait is killing me.
    I am sure others will come as what else is suited to the RC projects, the Due but that is too big.
    When i get the mixer going there have been many people wanting the head tracker to allow more inputs from a second stream, many of those will come. I would love to port the tracker part to teensy and add a PPM input, that will move a few teensies.
    The other Teensy project that Does the Mavlink to Frsky conversion is a project that appeals to many and if I or some one can get a lcd to display it within the model that will bring a lot more. The reaction to the unit that is working has been huge on the FPVLab forum. Scale builders are always looking for the next gadget to give more realism and that will become popular if it ever becomes available. I know as soon as i saw it i had to have it and many others were the same.
    It won't all happen overnight but as people seek more features then the coders will need a better tool and what else is there given the size and price.

  4. #29
    Member
    Join Date
    Mar 2014
    Location
    Fremantle Western Australia
    Posts
    47
    Paul i spent quite a bit of time today getting to know the Arduino environment a little better. Loaded the Teensy extensions and tried to import you lib but it comes back with an error about naming conventions. I unzipped it and to my surprise it worked. Then i couldn't see the CCP or h file but realized i could drag and drop it into a sketch. That was worth the effort and i now see what u meant about a structured library. Its absolutely wonderful, i could understand how it works quite easily. I couldn't write it yet but i could understand it Only comment at this stage is you assume all streams have 16 channels. Some RC systems will have problems with that so it may have been better to bring the #define PULSEPOSITION_MAXCHANNELS 16 back to the API, is that what you call the calls from the main? Maybe PulsePositionOutput myOutput(channel count)> Sorry for the newbie question but it is called an API isn't it? I gather this is what you meant about keeping certain things out of the h and ccp files, keep the user interface at the API level.
    I am learning, slowly maybe, but at least moving forward

    Have had a few inquiries about the lib and the teensy. Seems people expect problems with ppm and need to see something that actually does it well. A few have been looking and are impressed. I will keep the advertising going

    Mike

  5. #30
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,174
    Quote Originally Posted by whimsical View Post
    Only comment at this stage is you assume all streams have 16 channels.
    I designed the code to automatically handle less. 16 is only the maximum.

    PulsePositionOutput transmits the minimum number of pulses necessary to encode all the channels you've written. If you don't write more than 6 channels, the transmitted signal will only have the 7 pulses necessary. However, after you've written 6 signals, there's no way to later reduce to fewer.

    PulsePositionInput also automatically adapts. The available() function returns the number of signals actually received. After each received frame, available() returns the number of signals encoded in that specific frame.

    Both are limited to 16 signals (unless you edit the code). PulsePositionInput will ignore the 17th and any following signals. PulsePositionOutput will ignore any attempt to write to a channel higher than 16.

    I tried to keep the API simple, partly because I believe simplicity is good, and partly because I wrote this whole thing in only 2 days, which just isn't enough time to develop and test a complex API.


    Have had a few inquiries about the lib and the teensy. Seems people expect problems with ppm and need to see something that actually does it well.
    I can see why. Most of the Arduino code I found was pretty terrible, especially for receiving PPM.

    Then again, my code may have bugs or unforeseen limitations.

    I will keep the advertising going
    When you get it running one a real RC aircraft, I'd really love to see some photos!

    Ideally, the web page could really use a couple good photos and some RC specific explanation. Any chance you'd like to contribute something for the page?

  6. #31
    Member
    Join Date
    Mar 2014
    Location
    Fremantle Western Australia
    Posts
    47
    You mean the pulse position page. Only too happy if i can. Just getting back into modeling after a long hiatus but happy to do what i can.
    That page opens for me when i click on the link in your post but if i go to any other library page then back to servo its not there.

    Obviously i haven't fully deciphered the lib yet , didn't pick up on the auto sizing, although i did for the input. I did say i was a beginner didn't i
    From what i see, a sketch to input 2 streams and combine and output will be quite a short one. It will be in the Teensy very soon after its arrival.

    Simple is good for me as well, easier to understand. All the clever bits are behind the super simple interface. If you can achieve that in 2 days what could you do in a month
    Last edited by whimsical; 03-08-2014 at 03:25 PM.

  7. #32
    Member
    Join Date
    Mar 2014
    Location
    Fremantle Western Australia
    Posts
    47
    The wait is over, my Teensy arrived today. Roughly hooked it up, powered off usb.
    Didn't work. The little prog compiles and the loader seems to complete ok. Ch1 is from a head tracker on pin 6, ch 2 is the Teensy output pin 5. The noise that is on both is not on the head tracker until it connects to the Teensy.
    No idea if the inverted input signal is the cause or not. I wouldn't think so, should trigger on the next edge The 2 signals are not synced at all.
    Probably my code is up the creek. Hopefully someone will open my eyes because it looks logical to me.

    Click image for larger version. 

Name:	tekway19_1.gif 
Views:	108 
Size:	20.5 KB 
ID:	1700


    #include <PulsePosition.h>
    // this would not be possible with out the library provided by the generous efforts of Paul Stoffregen.
    // Please visit his site and give thanks http://forum.pjrc.com/forums/5-General-Discussion 1

    // this will only run on a Teensy 3.1 Arm M4 so visit paul and buy 1, they are not expensive.
    // to compile properly Arduino needs to have the Teensyduino extensions available from the Teensy site
    // https://www.pjrc.com/teensy/index.html

    // this simply reads 2 input streams and combines them into 1
    // the second input is appended to the first
    // the length of the output stream will be the total of the number of channels from both inputs.
    // the total must be 16 channels or less or Pauls lib will die and Paul will kill me. big grin


    PulsePositionOutput stream; //combined trackers
    PulsePositionInput trackerA;
    PulsePositionInput trackerB;
    byte Acount = 0;
    byte Bcount = 0;


    void setup() {
    trackerA.begin(6);
    trackerB.begin(9);
    stream.begin(5);
    Acount = trackerA.available(); // how many incomming channels trackerA
    Bcount = trackerB.available();

    }

    void loop() {
    byte numA = Acount;
    byte numB = Bcount;
    while (numA > 0);{ // repeat for however many channels incomming
    float val = trackerA.read(numA);
    stream.write(numA, val);
    numA = numA-1;
    }
    while (numB > 0);{ // second trackers turn
    float val = trackerB.read(numB);
    stream.write(numB + Acount, val);
    numB = numB-1;
    }

    }
    Last edited by whimsical; 03-21-2014 at 01:13 PM.

  8. #33
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,174
    You probably want to use available() inside loop(), not setup. Usually it will return zero, if data isn't available yet.

    You can troubleshoot by added Serial.println() inside loop() to see what's going on. For example:

    Code:
      Serial.print(numA);
      Serial.print(", ");
      Serial.println(numB);
    Then view with the Arduino Serial Monitor.

  9. #34
    Member
    Join Date
    Mar 2014
    Location
    Fremantle Western Australia
    Posts
    47
    thanks for that . will give it a go.
    Didn't see the sense in re-reading the available all the time as once set it shouldn't change and just adds more calls to the lib. will test it there and see what happens.
    So glad it finally showed up, happy chappy.

  10. #35
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,174
    You definitely should read available() all the time. It tells you both how much data arrives, and *when* it arrives.

  11. #36
    Member
    Join Date
    Mar 2014
    Location
    Fremantle Western Australia
    Posts
    47
    I shifted that but no change.
    Must be doing something very wrong as i get no serial out either. Need to play more.
    Control panel reports com 8 9600 baud set that in serial mon and i get nothing.
    The Teensy loader reports reboot ok so i presume it has transfered the sketch. Can't find the blinky prog to reload that and see if it works ok.
    Back to basics

    Thanks for your help. I will work it out eventually

  12. #37
    Member
    Join Date
    Mar 2014
    Location
    Fremantle Western Australia
    Posts
    47
    Blinkies both work

  13. #38
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,174
    If you're not getting anything in the serial monitor, try a non-serial device, like RawHID or MIDI. Those use an emulated serial channel that's automatically detected.

  14. #39
    Member
    Join Date
    Mar 2014
    Location
    Fremantle Western Australia
    Posts
    47
    Have to research RawHID or MIDI a bit, no idea what you are talking about yet
    i think i will start with just setting values to the lib and see if i can get an output then move slowly forward

    I will try again in the morning, nearly midnight here and i feel the call of the sandman

    Thanks again for your help.

  15. #40
    Member
    Join Date
    Mar 2014
    Location
    Fremantle Western Australia
    Posts
    47
    Couldn't go to bed without trying a few fixed output values
    Works fine
    Must not be getting any input values, tomorrow
    Does the read (channel) cope with the inverted signal ok?

    Click image for larger version. 

Name:	tekway20_1.gif 
Views:	123 
Size:	15.5 KB 
ID:	1701

  16. #41
    Member
    Join Date
    Mar 2014
    Location
    Fremantle Western Australia
    Posts
    47
    Read up on serial and got it working, my pc needs a fresh win 7 install i think.
    Running this test prog i get a value back from available() of 255 so the old prog is trying to output 255 channels. That ain't gunna work



    #include <PulsePosition.h>

    PulsePositionOutput stream; //combined trackers
    PulsePositionInput trackerA;
    PulsePositionInput trackerB;
    byte Acount = 0;
    byte Bcount = 0;


    void setup() {
    stream.begin(9);
    trackerA.begin(5);
    trackerB.begin(6);
    Serial.begin(9600); // opens serial port, sets data rate to 9600 bps

    }

    void loop() {
    Acount = trackerA.available(); // how many incomming channels trackerA
    stream.write(1, 1000);
    stream.write(2, 1250);
    stream.write(3, 1500);
    stream.write(4, 1750);
    stream.write(5, 2000);
    stream.write(6, 2250);
    stream.write(7, 2500);
    Serial.println(Acount);

    }

  17. #42
    Member
    Join Date
    Mar 2014
    Location
    Fremantle Western Australia
    Posts
    47
    a bit more info.
    It seems that if there is no input stream the lib returns 255 through Acount = trackerA.available(); , B is the same.
    If a signal is present when rebooting the Teensy then it gets it correct.
    I will insert a test for 255 and ignore that channel if true.

  18. #43
    Member
    Join Date
    Mar 2014
    Location
    Fremantle Western Australia
    Posts
    47
    This gets even stranger
    if i call write with a fixed channel # and the microseconds in a variable it all works fine

    stream.write(1, val);
    Serial.print(val);
    Serial.print(", ");
    val = trackerA.read(2);
    stream.write(2, val);
    Serial.print(val);
    Serial.print(", ");
    val = trackerA.read(3);
    stream.write(3, val);
    Serial.print(val);
    Serial.print(", ");
    val = trackerB.read(1);
    stream.write(4, val);
    Serial.print(val);
    Serial.print(", ");

    If i use a variable for the channel #, as you would using a counter for the # of channels to scan and write, it gets stuck in the loop and never gets to the serial.print at the end of the loop

    cnt = 8;
    while (cnt > 0);{
    val = trackerB.read(cnt);
    stream.write(cnt + 3, val);
    cnt = cnt - 1;
    }


    Working fine with the first method
    Attachment 1707

  19. #44
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,174
    Quote Originally Posted by whimsical View Post
    If i use a variable for the channel #, as you would using a counter for the # of channels to scan and write, it gets stuck in the loop and never gets to the serial.print at the end of the loop
    Please, always post a complete program. If I can copy the whole thing into Arduino, I probably will and try to recreate the problem here. If you give only a code fragment, I end up wasting a lot of time trying to guess the rest of your program (and usually when I do try, I fail to reproduce the problem).

    Edit: this library is new, so it's quite likely you've found a bug. Please, try to think of all the information and details needed to reproduce the problem. If I can reproduce a problem, I can usually fix it quickly.
    Last edited by PaulStoffregen; 03-22-2014 at 05:33 PM.

  20. #45
    Member
    Join Date
    Mar 2014
    Location
    Fremantle Western Australia
    Posts
    47
    Sorry about that here it is



    #include <PulsePosition.h>


    PulsePositionOutput stream; //combined trackers
    PulsePositionInput trackerA;
    PulsePositionInput trackerB;
    byte Acount = 0;
    byte Bcount = 0;


    void setup() {
    stream.begin(9);
    trackerA.begin(5);
    trackerB.begin(6);
    Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
    Acount = trackerA.available(); // how many incomming channels trackerA
    Bcount = trackerB.available();
    }

    void loop() {

    Acount = trackerA.available(); // how many incomming channels trackerA
    Bcount = trackerB.available();
    byte numA = 3;
    byte cnt = 8;
    float val = trackerA.read(1);
    stream.write(1, val);
    Serial.print(val);
    Serial.print(", ");
    val = trackerA.read(2);
    stream.write(2, val);
    Serial.print(val);
    Serial.print(", ");
    val = trackerA.read(3);
    stream.write(3, val);
    Serial.print(val);
    Serial.print(", ");
    val = trackerB.read(1);
    stream.write(4, val);
    Serial.print(val);
    Serial.print(", ");
    //cnt = 8;
    //stream.write(6,1500);
    //while (cnt > 0);{ // second trackers turn
    // val = trackerB.read(cnt);
    //stream.write(cnt + 3, val);
    // cnt = cnt - 1;
    //}


    Serial.print(Acount);
    Serial.print(", ");
    Serial.print(Bcount);
    Serial.print(", ");
    Serial.println(numA);
    }

  21. #46
    Member
    Join Date
    Mar 2014
    Location
    Fremantle Western Australia
    Posts
    47
    changed the loop to a do while and it works
    2 x 8's mixed into 16 channel



    #include <PulsePosition.h>

    PulsePositionOutput stream; //combined trackers
    PulsePositionInput trackerA;
    PulsePositionInput trackerB;
    byte Acount = 0;
    byte Bcount = 0;


    void setup() {
    stream.begin(9);
    trackerA.begin(5);
    trackerB.begin(6);
    Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
    }

    void loop() {

    Acount = trackerA.available(); // how many incomming channels trackerA
    Bcount = trackerB.available();
    float val = 3;
    float valA = 3;
    byte cnt = 8;

    cnt = 8;
    do { // First trackers turn
    valA = trackerA.read(cnt);
    stream.write(cnt, valA);
    cnt = cnt - 1;
    } while (cnt > 0);
    cnt = 8;
    do { // second trackers turn
    val = trackerB.read(cnt);
    stream.write(cnt + 8, val);
    cnt = cnt - 1;
    } while (cnt > 0);

    }Click image for larger version. 

Name:	tekway23_3.gif 
Views:	110 
Size:	25.9 KB 
ID:	1708

  22. #47
    Member
    Join Date
    Mar 2014
    Location
    Fremantle Western Australia
    Posts
    47
    Ignore stupid me
    Being a newbie with Arduino i keep getting the ; wrong. Started putting them in automatically and the control structures don't use them DUH
    got it right when i did the do while but added the ; in the while.

    I wonder why an error wasn't flagged when compiling

    I tend to type something in then test compile to see if i got it right. That makes me work to find mistakes and understand the syntax.

  23. #48
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,174
    Glad you've got it working!

    Now that you're a little more familiar with Arduino and this library, do you believe there are bugs I should investigate? How about "no input stream the lib returns 255"? This library is very new and other than me, you're probably the first person to really use it. There probably are bugs. I'm happy to work on them.

    It'd save me some time if you could quickly let me know which issues are still unresolved? Usually I spend 90% of the time trying to recreate the problem and 10% actually fixing it, so any details you can give me to help quickly recreate the problem are incredibly helpful.

  24. #49
    Member
    Join Date
    Mar 2014
    Location
    Fremantle Western Australia
    Posts
    47
    I think the only things i could think of that i would do differently would be to set the default timing to 1500 uS instead of 1000. I have asked the q on a few forums if anyone knows if the 100uS pulse width could be a problem with any other equipment, or the inverted signal out, usually inverted to what you made. The pulse widths will be easy to change once i figure out how to alter the cpp
    That small bug reporting 256 doesn't seem to be a problem because if the call to available is in the loop then when something gets plugged in it all recovers, reporting 0 would be better i supose. Unplug an input stream and the lib just keeps sending the last good value. All wonderful as far as i can see.

    When others see a project that overcomes the timing problems for PPM use, they will come. I will document my project on a few sites when i have it finished. In that i extract 2 or 3 channels from each input then add a few channel controls on the Teensy board. One input is a set of 6 push buttons that latch the channel pulse width to 1 of 6 possibles for the mode control on the autopilot. I am sure when people see how little code is required to achieve what has been problematic in the past then Teensy will take over.. I have put all the bits on some prototype board and will probably have it working tomorrow. A few days for this sort of project is quite amazing i think and thats due to the library, thanks so much for that. Have to get onto the next project then, but that will be a lot harder i am sure.
    Last edited by whimsical; 03-23-2014 at 03:24 PM.

  25. #50
    Member
    Join Date
    Mar 2014
    Location
    Fremantle Western Australia
    Posts
    47
    Here is the finished sketch for my mixer with buttons.
    It works very well. I will add a few more buttons on the unused channels when i decide what i want.
    Thanks again Paul for all your help.

    #include <PulsePosition.h>

    // this would not be possible, for me, with out the pulseposition library provided by the generous efforts of Paul Stoffregen.
    // Please visit his site and give thanks http://forum.pjrc.com/forums/5-General-Discussion
    // The library takes care of all buffers so all that is needed is a write to the output or read from the input.
    // If a tracker is unpluged it will just continue to output the last valid data. plugging the tracker back in
    // it will resume as if nothing had happened.
    // The library is capable of having up to 6 input or output streams each up to 16 channels long.
    // I only need 8 for my project and not many TX's can handle 16 in by the trainer port. The next version of opeTX
    // will be able to handle 16.
    // the output pulses are extremely stable.

    // this will only run on a Teensy 3.1 Arm M4 so visit paul and buy 1, they are not expensive, $20.
    // The Teensy is slightly smaller than the Nano
    // to compile properly Arduino needs to have the Teensyduino extensions available from the Teensy site
    // https://www.pjrc.com/teensy/index.html

    // this simply reads the 3 axis from the first head tracker and 2 axis from the second head tracker for a passenger.
    // It also has a 6 push button output for Ardupilot so i don't need to remember the 2 switch
    // combinations on the TX, YUCK. The LED's indicate what mode is being sent to the Ardupilot so it
    //is easy to see what mode it is in.
    // i will add another 6 push buttons for another feature i want but that is pretty much just a copy of the section for
    // the first 6 but without LED's.



    PulsePositionOutput stream; //combined trackers and buttons
    PulsePositionInput trackerA;
    PulsePositionInput trackerB;
    byte Acount = 0;
    byte Bcount = 0;
    int valA = 0;
    int valB = 0;
    int cnt = 0; // debounce counter
    int volts = 0; // apm control button input voltage

    void setup() {
    stream.begin(9);
    trackerA.begin(5);
    trackerB.begin(6);
    pinMode(11, OUTPUT);
    pinMode(12, OUTPUT);
    pinMode(14, OUTPUT);
    pinMode(15, OUTPUT);
    pinMode(16, OUTPUT);
    pinMode(17, OUTPUT);
    Serial.begin(9600); // opens serial port, sets data rate to 9600 bps

    }

    void loop() {
    Acount = trackerA.available(); // how many incomming channels trackerA
    Bcount = trackerB.available();
    valA = trackerA.read(1); // Take 3 channels from tracker A and 2 from tracker B
    stream.write(4, valA); // I used the diy tracker and shifted the outputs to channel 1, 2 &3
    valA = trackerA.read(2); // They are assmebled into the last 5 output channels
    stream.write(5, valA);
    valA = trackerA.read(3);
    stream.write(6, valA);
    valB = trackerB.read(1);
    stream.write(7, valB);
    valB = trackerB.read(2);
    stream.write(8, valB);


    volts = analogRead(18);

    if ((volts < 940) && (cnt <4000)){ cnt = cnt+1;} // debounce code
    if ((volts < 940) && (cnt == 4000)){ // less than 940 means a button has been pressed
    cnt = 0;
    digitalWrite(11, LOW); // reset the leds
    digitalWrite(12, LOW);
    digitalWrite(14, LOW);
    digitalWrite(15, LOW);
    digitalWrite(16, LOW);
    digitalWrite(17, LOW);
    // test to see which led was pressed, turn on its led and output PPM value to channel 1
    if ((volts >= 785) && (volts < 940)){ digitalWrite(17, HIGH); stream.write(1, 1165);}
    if ((volts >= 630) && (volts < 785)){ digitalWrite(16, HIGH); stream.write(1, 1295);}
    if ((volts >= 470) && (volts < 630)){ digitalWrite(15, HIGH); stream.write(1, 1425);}
    if ((volts >= 300) && (volts < 470)){ digitalWrite(14, HIGH); stream.write(1, 1555);}
    if ((volts >= 102) && (volts < 300)){ digitalWrite(12, HIGH); stream.write(1, 1685);}
    if (volts < 102){ digitalWrite(11, HIGH); stream.write(1, 1815);}
    }


    }

Posting Permissions

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