GithubHelp home page GithubHelp logo

ufo-kit / uca-phantom Goto Github PK

View Code? Open in Web Editor NEW

This project forked from the16thpythonist/uca-phantom

0.0 2.0 0.0 6.79 MB

A libuca plugin for the phantom high speed cameras

CMake 1.29% Meson 0.20% C 95.01% Python 3.50%

uca-phantom's Introduction

uca-phantom

libuca plugin for the Vision Research Phantom high-speed cameras.

Documentation

Since this is still a private repository, the public documentation for this project is hosted on a separate Github Repository. To view the Documentation source code jump to uca-phantom-doc. Or visit the indepth documentation directly at uca-phantom Documentation!

User information

Changing the acquisition mode

The acquisition mode determines if the sensor operates in binning, standard and HS mode. This has a few implications on the operation: first we cannot determine in which mode the camera is currently operation, therefore you cannot rely on the value of the acquisition-mode property. Second, binning changes the reported maximum sensor resolution, therefore you must update the region-of-interest when changing the binning. Otherwise, you will read too much or crash by reading outside the window. You will be on the safe side, if you just set the acquisition mode and restart any libuca application. Third, changing modes takes about 15 seconds which might make the application appear to be frozen.

Transfering data with a 10GE connection

Due to the way the protocol works, make sure to set the 10Gb network interface via the network-interface property and set enable-10ge to true. Note that those values are ephemeral and will be gone once you create a new camera object. Furthermore, you must make sure that your application is able to open raw sockets. Either run it as root (not recommended) or set the cap_net_raw capability on the binary:

$ setcap cap_net_raw+ep <executable>

Testing with the mock software emulation

Go to the utils directory and start the UDP discovery and TCP communication servers by running the mock script. The phantom plugin should be able to communicate with this replacement.

Developer information

Here are some information in which this plugin differes from other camera plugins. The biggest difference is in how data transfers are handled. Unlike other cameras, this happens through a secondary channel for which we open a socket on which we listen to connection requests and incoming data. Because we still need to react on API calls this is handled in a separate thread that runs accept_img_data. This thread and the API communicate through two asynchronous message and return queues. The thread picks up a message and once done places a result object on the return queue. Messages and results carry type information, meta and real data.

uca-phantom's People

Contributors

tfarago avatar the16thpythonist avatar

Watchers

 avatar  avatar

uca-phantom's Issues

Start using `g_autoptr` and `g_autofree` in all GLib based code ? (libuca, etc)

These are some Glib macros that tell the compiler to automatically free any Heap variable before a return statement.
With this, you no longer need to call g_free() or g_object_unref().

Only caveat : You need to use GCC or CLANG (and also all your variables have to initialized before hand, but this is only natural). Maybe a deal breaker ?

Really not urgent, could simply make the codebase more modern, memory safe and readable.

Use libpcap for 10Gb data transfer ?

Libpcap offers zero-copy data transfering for raw sockets (Shared memory between kernel space and user space). This is what is currently done in the driver, but it's messy and prone to errors for in the future.
Using libpcap would clean up the code and make it nore versatile while also maintaining performances (+ it's cross platform! ).
Only downside is that it adds a dependency to download...

Handle phantom specific features

I've added the full access to all of the phantom's features, e.g:

  • auto triggers based on image events
  • frame decimation
  • image cropping
  • video output settings
  • image calibration
  • etc

But they'd need some extra support on the code side of things. For example, the communication module doesn't take cropping or frame decimation into account. Something to think about in the future, based on specific needs.

Nested error management

Error management is already solid. But it would be nice to have a nested printing mechanism where each layer of the propagated errors was preceded by a newline+tab when printed.

Automatic documentation generation

Readily available well-documented open-source documentation tools

  • Doxygen
  • Sphinx

Doxygen seems to more be widespread and have a better documetation. This could help us easily exhibit our public functions that should be used by the user and how they relate to the super class (which functions are overrided, which member variables are public, etc).
May also enable automatic UML style class-inheritance diagrams.

Work that would need to be done

Classes and their methods would need to have a commented header documenting the said-functions. A standard syntax would have to followed. Fortunately, this is already mostly done.

uca_phantom_get_variable freezes after too many immediate consecutive calls

Problem description

Behaviour is undefined when doing the following:

    GError *error = NULL;
    GValue val = G_VALUE_INIT;
    gboolean result = FALSE;

    UcaPhantomCommunicate *communicator = uca_phantom_communicate_new();
    gboolean connected = uca_phantom_communicate_attempt_connect(communicator, &error);

    if (!connected) {
        g_print ("Houston theres a problem: %s\n", error->message);
        g_error_free (error);
        g_object_unref (communicator);
        return FALSE;
    }

    struct timespec req, rem;
    req.tv_sec = 0;
    req.tv_nsec = 5e+6;

    for (int i=0; i < N_UNIT_PROPERTIES; i++) {
        result = uca_phantom_get_variable (communicator, i, &val, &error);
        if (!result && error != NULL) {
            g_print ("Houston we've got a problem: %s\n", error->message);
            g_error_free (error);
            g_object_unref (communicator);
            return FALSE;
        }
        print_gvalue (i, &val);
        g_value_unset (&val);
        // nanosleep(&req, &rem);
    }

    g_object_unref (communicator);

Indeed, after a certain and seemingly random amount of requests, the program feezes. However, by adding a blocking sleep command at the end of the loop, all requests are made and all answers are received.

Valgrind output

[...]
==45048== Process terminating with default action of signal 2 (SIGINT)
==45048==    at 0x4D01D7F: poll (poll.c:29)
==45048==    by 0x4AB12AD: g_socket_condition_timed_wait (in /usr/lib/x86_64-linux-gnu/libgio-2.0.so.0.7200.4)
==45048==    by 0x4AB161E: ??? (in /usr/lib/x86_64-linux-gnu/libgio-2.0.so.0.7200.4)
==45048==    by 0x4A8F1F6: g_input_stream_read (in /usr/lib/x86_64-linux-gnu/libgio-2.0.so.0.7200.4)
==45048==    by 0x10CDF9: uca_phantom_communicate (uca-phantom-communicate.c:517)
==45048==    by 0x10CDF9: uca_phantom_get_variable (uca-phantom-communicate.c:670)
==45048==    by 0x10B9B4: main (test_network.c:51)
==45048== 
==45048== HEAP SUMMARY:
==45048==     in use at exit: 278,549 bytes in 2,329 blocks
==45048==   total heap usage: 11,650 allocs, 9,321 frees, 9,845,914 bytes allocated
==45048== 
==45048== LEAK SUMMARY:
==45048==    definitely lost: 14 bytes in 1 blocks
==45048==    indirectly lost: 0 bytes in 0 blocks
==45048==      possibly lost: 3,216 bytes in 4 blocks
==45048==    still reachable: 250,999 bytes in 2,089 blocks
==45048==         suppressed: 0 bytes in 0 blocks
==45048== Rerun with --leak-check=full to see details of leaked memory
==45048== 
==45048== For lists of detected and suppressed errors, rerun with: -s
==45048== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

The memory leak is likely due to the communicator object not being freed after the ctl+c signal.

Envision implementing unit tests for the phantom camera

Test network com with phantom

TODO

Test Unit Structure members as per the PH16 spec sheet

See spec sheet for description of each member variable. More variables are listed out than needed. Before implementing these unit tests, one must first verify which variables need to be known for the general functionning of uca-phantom, which need to have a default value set and which are prone to be modified.

info structure

Sensor information:

  • info.sensor
  • info.snsversion
  • info.cfa
  • info.filter

Versions and identification

  • info.hwver
  • info.kernel
  • info.swver
  • info.xver
  • info.model
  • info.pver
  • info.sver
  • info.serial
  • info.name ?

Capabilities

  • info.features
  • info.imgformats
  • info.videosystems
  • info.maxcines
  • info.xmax, info.ymax
  • info.xinc, info.yinc
  • info.winx, info.winy
  • info.kernsz, info.memsz, info.cinemem
  • info.mdepths
  • info.expdead
  • info.minexp
  • info.xblock, info.yblock
  • info.pixps
  • info.rotps, info.fotps
  • info.minfrate, info.maxrate
  • info.tmodel
  • info.magtp
  • info.rtobyteps
  • info.rtopacket, info.rtopacketovhead, info.rtofrovhead
  • info.rto_channels

Color correction (non concerned)

Nothing important to check

Camera status monitoring

  • info.modes

Meta stucture

  • meta.name, meta.lens, meta.fstop, meta.flen, meta.comment, meta.xset

Cam structure

Contains global user-alterable settings that aren’t tied to a particular cine.

Camera Sync Options

  • cam.syncing
  • cam.frdelay
  • cam.rtoen
  • cam.rtotfr ?
  • cam.membpp (see acqmode )

Global camera options

  • cam.trigpol
  • cam.trigfilt
  • cam.startonacq
  • cam.tsformat
  • cam.tcmode
  • cam.master ?
  • cam.apoffdis
  • cam.longread
  • cam.cines (see partition)
  • cam.dark
  • cam.mode (see info.modes and iload)

Eth structure

This section is probably quite important as it is directly related to the network settings of the camera.

Network settings

  • eth.ip
  • eth.netmask
  • eth.broadcast
  • eth.gateway
  • eth.mtu
  • eth.xip (10GE connection ip)
  • eth.xnetmask
  • eth.xbroadcast

Video structure

General video output controls (are we concerned by this ? TODO: test these params out)

  • video.system (see spec sheet for associated values)
  • video.output
  • video.fields
  • video.widescreen
  • video.genlock
  • video.vfmode

On screen display control

definitely not concerned by this

Video scaling

  • video.uzoom
  • video.vox, video.voy
  • video.vow, video.voh,
  • video.vw, video.vh

Video image adjustments (TODO: check if is relevant)

  • video.adj.red, video.adj.green, video.adj.blue
  • video.adj.toe
  • video.adj.gamma, video.adj.rgamma, video.adj.bgamma
  • video.adj.gain
  • video.adj.offset
  • video.adj.flare
  • video.adj.hue, video.adj.sat
  • video.adj.rped, video.adj.gped, video.adj.bped
  • video.adj.chroma, video.adj.tone
  • video.adj.matrix
  • video.adj.log
    [...] other params, maybe not important

Irig structure

Structure containing the status of the camera timebase and range data acquisition unit. updated ~1Hz.

  • irig.sec, irig.yearbegin
  • irig.flags (See flags in spec sheet)
  • irig.signal
  • irig.gps
  • irig.range

Mag (Cinemag) structure (important ?)

  • mag.state
  • mag.progress
  • mag.protect
  • mag.size
  • mag.used
  • mag.takes
  • mag.version
  • mag.id
  • mag.runstop
  • mag.type

defc (default cine) structure

Variables that control the camera image capture process.

  • defc.res
  • defc.rate
  • defc.exp
  • defc.edrexp
  • defc.ptframes
  • defc.shoff
  • defc.ramp
  • defc.bcount, defc.bperiod
  • defc.hqenable
  • defc.decimation
  • defc.frcount, defc.frsize
  • defc.aexpmode, defc.aexpcomp
  • defc.meta.ox, defc.meta.oy, defc.meta.w, defc.meta.h, defc.meta.ow, defc.meta.oh, defc.meta.crop, defc.meta.?

Cf structure (storage device) (important ?)

See spec sheet for flag vals

  • cf.state
  • cf.action
  • cf.size
  • cf.used
  • cf.progress
  • cf.errrcode

Cine tables structure (important ?)

Array of cine structures -> used to store images and meta data (e.g timestamps). More todo in understanding how these structures are layed out in memory.

Status variables

  • c#.state
  • c#.frcount
  • c#.firstfr, c#.lastfr
  • c#.format
  • c#.in, c#.out

memory allocation

  • c#.start, c#.len
  • c#.frsize, c#.frspace

trigger time

  • c#.trigtime.secs, c#.trigtime.frac

acquisition parameters

  • See defc

cam/info/adj/meta substructures

These copies are done at the time the cine recording ends, and reflects the meta values.
in place at the time of recording.

  • c#.cam (see cam substructure for verification)
  • c#.info (idem)
  • c#.adj (idem)
  • c#.meta.pbrate
  • c#.meta.tcrate
  • c#.meta.uuid, c#.meta.system
  • c#.meta.system
  • c#.meta.trigtc
  • c#.meta.pax, c#.meta.pay
  • c#.meta.paox, c#.meta.paoy
  • c#.meta.ox, c#.meta.oy, c#.meta.ow, c#.meta.oh, c#.meta.w, c#.meta.h, c#.meta.crop, c#.meta.resize, c#.meta.gps ?

Usets (important ?)

Probably not important

hw (Do not touch)

Auto structure ( important ?)

  • auto.flashsave
  • auto.filesave
  • auto.videoplay
  • auto.acqrestart
  • auto.bref ?
  • auto.firstframe, auto.lastframe
  • auto.loops
  • auto.speed
  • auto.progress, auto.bref_progress
  • auto.trigger, auto.trigger.x, auto.trigger.y, auto.trigger.w, auto.trigger.h, auto.trigger.threshold, auto.trigger.area, auto.trigger.speed, auto.trigger.mode

Add timestamps

Reading the timestamps is done the same way like the frames.
Possible implementations are:

  • Reading the timestamps of a cine before the first grab and then encoding them in the frames
  • Reading the timestamps at any point an make them accessible via a function or porperty

Frame rate not settable

Currently the frame rate is not settable. frames-per-second parameter reports 1/exposure-time (defined in uca base camera).

Modernizing uca-phantom to latest GObject standards and practices

Main objectives

Not much is actually needed to be done. The task would mostly entail

  • using GObject's net macro's for better typechecking, signal handling and error propagation.
  • Use GObject's new type registration methods. Most notably the private structure ones
    These are currently not used.

important: check if updating uca-phantom to modern GObject will break compatibility with uca-camera. => I am reasonable certain that this is not an issue, but this should be sandbox-tested first.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.