Skip to content

Commit

Permalink
aravis change
Browse files Browse the repository at this point in the history
  • Loading branch information
Ez2816 committed Nov 6, 2024
1 parent e822317 commit a86b599
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
.devcontainer/
/build/
/images/
/venv/
/venv/
/external/

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@ pip install -r requirements.txt
```

## Authors

* **Richard Han** - [@rrhan0](https://github.com/rrhan0)
1 change: 0 additions & 1 deletion external/.gitignore

This file was deleted.

92 changes: 92 additions & 0 deletions src/AravisCamera.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@

//constructor
AravisCamera::AravisCamera(){
std::cout<<"connecting to camera\n";
// checking for cameras
arvcamera = arv_camera_new(NULL, &error);
if (ARV_IS_CAMERA(arvCamera) == 0){
throw std::runtime_error("No camera connected");
//error if no cameras found
}
set_default();
//set_epoch();
// apparently this is unecessary because we can get timestamp for each buffer
}

//destructor
AravisCamera::~AravisCamera(){
std::cout<<"Cleaning up\n";
g_clear_object (&arvCamera);
}

//setting pixel format
void set_pixelformat(const std::string &pixelformat){
const char* cstr = pixelformat.c_str();
arv_camera_set_pixel_format_from_string (arvCamera,cstr,error);
}

//setting exposure time
void set_exposuretime(float exposuretime){
arv_camera_set_exposure_time(arvCamera, exposuretime, error);
}

//setting gain
void set_gain(float gain) {
std::cout << "Setting gain to " << gain << "\n";
arv_camera_set_gain(arvCamera, gain, error);
}

// start stream
// ? Not sure about number of buffers

void start_stream (){
std::cout << "Starting stream\n";
stream = arv_camera_create_stream(arvCamera, NULL, NULL, error);
if (stream == NULL){
throw std::runtime_error("No stream");
}
arv_camera_start_acquisition(arvCamera, error);
}


//end acquisition and exit stream


void stop_steam(){
std::cout << "stopping stream\n";
arv_camera_stop_acquisiton(arvCamera,error);
g_clear_object (&stream);
g_clear_object (&arvBuffer);
}


//getting an image
void get_image (){
arvBuffer = arv_camera_acquisition(arvCamera, 0, error);
if (arvBuffer != NULL){
//double width = arv_buffer_get_image_width(buffer);
timeStamp = arv_buffer_get_timestamp(arvBuffer); // not sure if this one is better than the next line
timeStamp = arv_buffer_get_system_timestamp(arvBuffer);
}

//store buffer to file commands here..?
//store timestamp as well?
g_clear_object (&arvBuffer);
g_clear_object(&timeStamp);
}

void set_epoch(){

//is this still necessary if we can find timestamp of buffer?
}

//setting default values to camera
void set_default(){

//const char* string is the name of the node based on GenIcam standard naming
arv_gc_set_default_node_data (genicam, "ExposureTime");
arv_gc_set_default_node_data (genicam, "PixelFormat");
arv_gc_set_default_node_data (genicam, "Gain");

}

80 changes: 80 additions & 0 deletions src/AravisCamera.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#ifndef SRC_ARAVISCAMERA_HPP_
#define SRC_ARAVISCAMERA_HPP_

//#include "ArenaApi.h"
#include "ICamera.hpp"

class AravisCamera : public ICamera {
private:
int64_t timeStamp; /**< Epoch time for timestamping. */
//need to find member variables
ArvCamera* arvCamera;
GError *error = NULL;
ArvSteam *stream;
ArvBuffer *arvBuffer;
ArvGc *genicam;
// bool _trigger_state = false; /**< Trigger state flag. */
public:
AravisCamera(); // Constructor
~AravisCamera(); // Destructor
/**
* @brief Sets the pixel format for the camera.
* @param pixelformat A string specifying the pixel format.
*/

void set_pixelformat(const std::string &pixelformat);
/**
* @brief Turns off auto expsure and sets the exposure time for the camera.
* @param exposuretime A float of range [359.328, 151839.528] specifying the
* exposure time in microseconds.
*/
void set_exposuretime(float exposuretime);

/**
* @brief Sets the gain for the camera.
* @param gain A float of range [0.0, 27.045771199653988] specifying the gain
* value. Default gain in 0.0
*/
void set_gain(float gain);

// /**
// * @brief Enables or disables the manual trigger mode for the camera.
// * @param trigger_on A boolean where true enables and false disables it.
// */
// void set_trigger(bool trigger_on);

/**
* @brief Starts the image stream from the camera.
* @param num_buffers An integer specifying the number of buffers to use.
* Default is 10.
* Not sure about the parameters...
*/
void start_stream();

/**
* @brief Stops the image stream from the camera.
*/
void stop_stream();

/**
* @brief Retrieves an image from the camera.
* @param timestamp A pointer to a 64-bit integer to store the image
* timestamp.
* @return A boolean indicating success (true) or failure (false).
*/
std::unique_ptr<ImageData> get_image();

private:
/**
* @brief Sets default configurations for the camera.
*/
void set_default();

/**
* @brief Sets the epoch time.
* Is this still necessary if we can get the timestamp for an image?
*/
void set_epoch();
};

#endif // SRC_ARENACAMERA_HPP_

0 comments on commit a86b599

Please sign in to comment.