Replies

  • Just in case it might be useful to someone trying to get OF to work, here's a copy of my notes on getting OpticalFlow working with Copter v3.3.

    I have it kinda/sorta working (with some intermittent issues), and I'm not 100% sure if everything is setup correctly and I'm sure I've missed something, so any feedback will be greatly appreciated.

    Thanks!

    Download PX4FLOW Firmware

    Download the APM's version of PX4FLOW Firmware from: http://ardupilot.com/downloads/?did=118
    (The expanded firmware should be px4flow-klt-06Dec2014.px4)

    Flash PX4FLOW firmware

    • Connect PX4Flow to PC via USB
    • Make sure I2C cable between PX4FLOW and Pixhawk is disconnected.
    • Use QGroundControl to load the binary firmware downloaded in the previous section.

    NOTE: Some versions of QGroundControl are missing the menu to upload custom firmware from local filesystem. Use the latest version (v2.8.0) in order to upload the custome firmware to PX4FLOW. v2.8.0 also has PX4FLOW specific settings menu with auto-video streaming. If you want to run an older version of QGroundControl, use v2.5.2 or earlier in order to be able to load custom firmware to PX4FLOW.

    All release versions of QGroundControl can be found here

    Adjust PX4FLOW

    • Connect PX4FLOW to QGroundControl via USB.
    • With the latest version of QGroundControl, video is automatically streamed and displayed in the PX4FLOW specific settings menu.
    • From the parameters menu, set VIDEO_ONLY=1 in order to view high-resolution video for adjusting lens focus.
    • While view the video stream via USB, twist the focus ring on the PX4FLOW lens so that the image is focused and edges are sharp at around 3 meters (or your average hovering height, which is 1m in my case).
    • Tighten the focus ring screw once focus has been adjusted.
    • Disable high-resolution video streaming mode by setting VIDEO_ONLY parameter to 0.

    Connect PX4FLOW to Pixhawk/PXF

    • Use DF13 4 pos connector to connect I2C port of PX4FLOW to I2C port of Pixhawk/PXF.
    • If you want to use the sonar on-board PX4FLOW, use analog pins and connect it to ADC input of Pixhawk (details to be filled).

    Update Copter Firmware

    Configure OpticalFlow

    Via APM Planner 2.0 / Mission Planner

    • Initial Setup -> Optional Setup -> Optical Flow -> Check the "Enable" checkbox
    • Cofig/Tuning -> Full Parameter List

    Change the following parameters:

    EKF_GPS_TYPE -> 3
    FLOW_ENABLE -> 1
    FLOW_FXSCALER -> 0
    FLOW_FYSCALER -> 0
    FLOW_ORIENT_YAW -> 0 if you've mounted PX4FLOW's x axis facing forward (xyz axis marker is printed on the backside of PX4FLOW PCB board). If x is not facing forward, adjust this. Value Must be between -18000 and 18000 centidegrees.

    # Disable GPS pre-arm check
    GPS_HDOP_GOOD -> 9999
    # Enable Pre-ARM Logging (All + FastATT, including pre-arm logging)
    LOG_BITMASK -> 131071

    # If you want to use built-in barometer instead of external range finder (NOT recommended).
    EKF_ALT_SOURCE -> 0 # Set this to 1 if you have external range finder (LiDAR, etc.)
    RNGFND_GNDCLEAR -> set this according to your rangefinder's spec.

    Testing

    Check mount orientation and tweak the scaler parameters according to the instructions in the wiki

    Check dataflash logs (NOT telemetry logs) and make sure:

    • OF.flowX, OF.flowY, OF.bodyX, OF.bodyY are responding to aircraft movements.
    • EKF5.meaRng is not flat-lined and responding to height changes.
    • EKF5.FIX and EKF5.FIY are not flat-lined (flat-line indicates OF readings are not used in EKF).
    • EKF4.SS bit 7 is false (inidicates constant position mode when true)
    • EKF4.SS bit 3 is true (indicates relative position mode when true)

    NOTE: OF.flowX and OF.flowY don't get updated in the telemetry log, so make sure to check the dataflash logs.
    NOTE: Don't use OF_LOITER mode as they've been removed a long time ago from the firmware. APM Planner 2.0 still has this mode in the drop-down menu, presumably in order to support older versions.

    Issues

    • If you don't take off immediately after arming and bring your copter to at least about 1 meter, EKF will stop using OF data and you'll be flying manually.
    • Sometimes OF drops out suddenly mid-flight when readings are off, but there's no warning or indication. Only way to know is to look at the dataflash logs.
    • When flying with OF, the aircraft starts to drift off as time goes by. It appears EKF5.FIX and EKF5.FIY gets too large over time.
    • Loiter mode feels a little "sluggish" compared to stabilize, etc., and it's easy to get confused and panic as it seems like the copter is not responding to your RC input at all.
    • If you are getting nothing in the logs (make sure you are looking at the dataflash logs and not the telemetry logs), fire up NSH, and issue px4flow status command to see if the PX4FLOW module is detected on I2C and the driver is loaded. You should see a bunch of readouts if it's functioning correctly and error message otherwise.
    • At least one of the PX4FLOW clones (one without the on-board sonar module, bought from China) did not work when connected via I2C. It can be very confusing as it appears to be working just fine when connected directly to the PC via USB. PX4FLOW with sonar (bought direct from 3DR) doesn't have this problem.

    Questions

    Misc. Notes

    • The PX4FLOW firmware binary APM Recommended Version above is apparently built from the source code here, but the resulting binary built from the soure does not work with APM:Copter.
    • The latest upstream version, when built from the source does not seem to work with APM:Copter. OPTICAL_FLOW.flow_comp_m_x etc. in both telemetry and dataflash logs didn't look right.
    • In both cases, the values reported by the Copter didn't look right (values were too small, biased towards one direction only, less frequently updated, etc.). Although they look OK if you connect to PX4FLOW and look at the mavlink data directly.

    References

    • Can the image built from px4flow source code work with APM:Copter 3.3.1 that downloaded by MissionPlanner?

      • Developer

        Yes, I think it should work.  I'd recommend using Copter-3.3.2 though because it allows arming without a GPS.

        • I have just tried the V3.3.2 copter for pixhawk, and get below result

          1.opt_flow enabled, EKF_GPS_TYPE=3.

          2.opt_m_x, opt_m_y,opt_qua is not zero in flying data->status

          3.EKF5.meaRng is between (0,3), EKF5.FIX goes up step by step from 0 to 20, EIF5.FIY keeps zero

          4. tried several time ,loiter is not working

          attachement is part of my log

    • Thanks a lot Goro,

      I've followed wiki and yours above but I'm totally under trouble with Optical Flow. 

      I got OF flashed and lens focused by QgroundControl but I couldn't get OF.bodyX, OF.FlowX, IMU.GyroX matched like wiki.

      And also during flying test, even with EKF_GPS_Type = 3, my copter just said "3D Fix needed" in Loiter mode when I tried arm it.

      Attached my log and copter.

      Very appreciated if you can give me any clue ^^;

      2015-11-25 15-05-40.log

      OF.jpg

      https://storage.ning.com/topology/rest/1.0/file/get/3702604943?profile=original
      • Hi Kyomo,

        I see you are using vanilla v3.3.1, which will not let you arm in Loiter without 3D Fix. You'll need to patch the source code and build the firmware yourself, or use v3.3.2-rc2.

        As far as I know,  http://ardupilot.com/downloads/?did=118 is the only version that will work with APM firmware, and when I tried other versions of PX4FLOW firmware, I couldn't get bodyX, etc. to match up either.

        Hope it helps,

        • Thanks Goro, I'll try again and let you shared on the result ^^;

          • Hi,

            You probably couldn't get it to match because the formula for scaling is as follows:

            float flowScaleFactorX = 1.0f + 0.001f * flowScaler.x

            float flowScaleFactorY = 1.0f + 0.001f * flowScaler.y

            You are setting flowScaler.x and flowScaler.y and they get divided by 1000 and added by one.

            So if you see in the log reviewer that they differ by a factor of 2 to 3 (which was for me the case), you need to fill in 1000 to 2000.

            I had to fill in 2500 for my setup (1.5m above ground). Now they match better. But it is still difficult to tune as the way you roll the copter influences the data a lot. Try to tilt it like an inverted pendulum so the focal point on the ground doesn't move. Not just rotating copter around its own axis.

            Hope this helps.

            Cheers,

            Jon

    • Wow, to Philip and Goro, thank you!

      That is some of the best and most complete diagnostic and set up information that I have seen on the PX4flow to date!

      Thank you again!
      • A big thank you goes out to Randy MackayPaul Riseborough, and other APM developers. They are the ones who've worked tirelessly to make this whole thing work and they've also been helping us troubleshoot in various forums. I've just summarized what they've posted in different places.

This reply was deleted.

Activity

Neville Rodrigues liked Neville Rodrigues's profile
Jun 30
Santiago Perez liked Santiago Perez's profile
Jun 21
More…