Menu

PPMOut and Expo example

Features
Anonymous
2013-06-21
2013-08-22
  • Anonymous

    Anonymous - 2013-06-21

    Hi,

    first i would like to thank you for sharing your work!

    I am using the PPMOut with success and a eurgle 2.4 GHz transmitter module. PPM is working fine. Now i try to understand the ArduinoRCLib examples but get stuck because my programming skills are limited. I want to add to the PPMOut example some Expo to the poti connected on A0 but don't know to do this.

    I understand, that g_PPMOut.update(); takes care about new values available in the input buffer. But i don't understand how to apply the Expo value to the input buffer :(

    Unfortunately i could not find any working coding example that covers my needs. It would be very kind if you could give me a short coding example.

    thanks in advance

    Michael

     
    • dvdouden

      dvdouden - 2013-08-05

      First of all, sorry for the late reply, I was on vacation when you asked the question and didn't get to reading all of my email since I got back :)

      The Expo class works on normalized values (-256 - 256), you'll need to convert your stick input from 0 - 1024 to -256 - 256 first. Then you apply expo, and then you convert it to microseconds and pass it to PPMOut. If you look at the PPMOut example, you will have to replace the body of the input loop with the following:

          // fill input buffer, convert raw values normalized, apply expo, convert to microseconds
          int16_t norm = map(analogRead(g_pins[i]), 0, 1024, -256, 256);
          norm = g_expo.apply();
          g_input[i] = map(exp, -256, 256, 1000, 2000);
      

      As you can see, first the analog input is mapped to the range -256 to 256. Then expo is applied (with one Expo object named g_expo, you can use one object per channel if that's what you need of course). The result is still in the -256 to 256 range, that is mapped to microseconds (1000 - 2000) and put in the input buffer. A more decent way is to set up a chain of AIPin, Expo and Channel objects instead (see the TX example).

       
  • Anonymous

    Anonymous - 2013-08-17

    Hi,

    thanks for your kind help, but i am still stuck with the code :(

    the following code gives me an error: "void value not ignored as it ought to be"

    norm = g_expo.apply();
    g_input[i] = map(exp, -256, 256, 1000, 2000);

    changing it to the following gives me an other error: "invalid conversion from 'double (*)(double)' to 'long int'"

    norm = g_expo.apply(norm);
    g_input[i] = map(exp, -256, 256, 1000, 2000);

    Below is the complete code i use. It would be very kind if you could give me a helping hand by correcting the code.

    thanks in advance for your help!

    Michael

    /* ---------------------------------------------------------------------------
     ** This software is in the public domain, furnished "as is", without technical
     ** support, and with no warranty, express or implied, as to its usefulness for
     ** any purpose.
     **
     ** ppmout_example.pde
     ** Demonstrate Pulse Position Modulation Output functionality
     **
     ** Author: Daniel van den Ouden
     ** Project: ArduinoRCLib
     ** Website: http://sourceforge.net/p/arduinorclib/
     ** -------------------------------------------------------------------------*/
    
    #include <PPMOut.h>
    #include <Timer1.h>
    #include <Expo.h>
    
    #define CHANNELS 4
    
    uint8_t  g_pins[CHANNELS] = {
      A0, A1, A2, A3}; // Input pins
    uint16_t g_input[CHANNELS];                   // Input buffer in microseconds
    uint8_t  g_work[PPMOUT_WORK_SIZE(CHANNELS)];  // we need to have a work buffer for the PPMOut class
    
    // PPMOut requires two buffers:
    //     Input buffer containing input samples in microseconds
    //     Work buffer of ((channels + 1) * 2) elements for internal calculations and frame buffering
    // This setup removes any limit on the number of channels you want, and makes sure the library doesn't use more
    // memory than it really needs, since the client code supplies the buffers.
    rc::PPMOut g_PPMOut(CHANNELS, g_input, g_work, CHANNELS);
    rc::Expo g_expo;
    
    void setup()
    {
      // Initialize timer1, this is required for all features that use Timer1
      // (PPMIn/PPMOut/ServoIn/ServoOut)
      rc::Timer1::init();
    
      for (uint8_t i = 0;  i < CHANNELS; ++i)
      {
        // set up input pins
        pinMode(g_pins[i], INPUT);
    
        // fill input buffer, convert raw values to microseconds
        g_input[i] = map(analogRead(g_pins[i]), 0, 1024, 1000, 2000);
      }
    
      // initialize PPMOut with some settings
      g_PPMOut.setPulseLength(448);   // pulse length in microseconds
      g_PPMOut.setPauseLength(10448); // length of pause after last channel in microseconds
      // note: this is also called the end of frame, or start of frame, and is usually around 10ms
    
      // start PPMOut, use pin 9 (pins 9 and 10 are preferred)
      g_PPMOut.start(9);
    }
    
    void loop()
    {
      // update the input buffer
      for (uint8_t i = 0;  i < CHANNELS; ++i)
      {
        // fill input buffer, convert raw values normalized, apply expo, convert to microseconds
        int16_t norm = map(analogRead(g_pins[i]), 0, 1024, -256, 256);
        norm = g_expo.apply(norm);
       g_input[i] = map(exp, -256, 256, 1000, 2000);
      }
    
      // tell PPMOut there are new values available in the input buffer
      g_PPMOut.update();
    }
    
     
    • dvdouden

      dvdouden - 2013-08-19

      Sorry, I made a mistake in my initial response... This line:

      g_input[i] = map(exp, -256, 256, 1000, 2000);
      

      should be

      g_input[i] = map(norm, -256, 256, 1000, 2000);
      

      When I wrote my initial response I had named the variable 'norm' 'exp', I renamed it halfway through, but forgot to update that line. Normally you'd get an "Unknown identifier 'exp'" error, but 'exp' already exists as a function (double exp(double)) which explains the error (it's trying to cast a function pointer to a long int).

       
  • Anonymous

    Anonymous - 2013-08-21

    Hi,

    great, now it runs fine :) i am starting to understand step by step the concept and allready spend smore and more time to understand the code and read the documentation.

    thanks for your help!

    Michael

     

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.