Servers by jDrones

Unable to log data from pixy camera


(Georgi C) #1

Hi,

I have received some code and am trying to view variables set up in the log file that record what the pixy camera sees. x position, y position, camera lock etc. However nothing seems to be being logged. All entries in the log for all fields is zero bar the time, which isn’t taken from the structure skydiver.pixy_etc, all entries tied to this structure are zero. I know that the camera is working because of the LED on the front of the front of the camera lights up when the taught object is in view. I am doubtful that this could be causing the problem but I am powering the pixhawk by USB connected to my computer, it is not connected to mission planner when I am doing the experiment to create the log so should just be using the computer as a power source. Nothing about this could impact the logs could it?
Another point of interest is that I linked up a LED to the camera_lock variable to see how it would be effected. The LED is off initially (as it should be) and turns on once the target enters the view, the log at this point in time still says 0 - it should be 1 due to the if statement (tracking.cpp), but the LED remains on from that point on rather than turning off when the object is taken away.

I have attached the code that I think is relevant, and have been looking on google for what the following lines of code do with no luck:
AP_IRLock_I2C pixy
pixy.update()

Log.cpp
Log.cpp (22.0 KB)
Plane.h
Plane.h (69.0 KB)
tracking.cpp - I can only attach 2 files so here is the code directly

void Plane::get_pixy_block(void){

int negative_X = 0;

int posx = 0;
int posy = 0;

// get new sensor data
pixy.update();

//Georgi Carpenter - Check pixy.num_targets() is as expected
if (pixy.num_targets()>0){
	ServoRelayEvents.do_set_servo(11,2000);
	skydiver.camera_lock = true;
} else {
	ServoRelayEvents.do_set_servo(11,0);
	skydiver.camera_lock = false;
}


//Check we have a valid target from Pixy camera
if (pixy.num_targets() > 0 && pixy.last_update_ms() != skydiver.last_pixy_meas_time_ms) {
	// Get pixel coordinates of target
	pixy.get_unit_vector_body(skydiver.pixy_pixel_position_x, skydiver.pixy_pixel_position_y, skydiver.pixy_pixel_size_x, skydiver.pixy_pixel_size_y);
	
	//Change to be +/- 160 pixels in x dimension and +/- 100 pixels in y dimension
	posx = skydiver.pixy_pixel_position_x - 160;
	posy = skydiver.pixy_pixel_position_y - 100;
	
	//Store negative value and make values positive as LUT is symmetric so only half the values are stored.
	if (posx <0){
		negative_X = 1;
		posx *= -1;
	}
    if (posy <0){
		posy *= -1;
	}
	if (posx > 158){
		posx = 158;
	}
	posy /= 2; //Divide by two due to compression of LUT
	
	//Undistort pixel positions
	posx = LUTX[posy][posx];
	
	if (negative_X){
		posx *= -1;
	}
	
	//Calculate azimuth
	skydiver.pixy_angle_x = atanf(posx/242.414)*180/M_PI;
	
	//Calculate Range
	skydiver.pixy_range = (0.2*242.414/skydiver.pixy_pixel_size_y + 0.2*163.827/skydiver.pixy_pixel_size_x)/2;
	
	skydiver.azimuth = skydiver.pixy_angle_x;
	UAV_spin = false;
    skydiver.last_pixy_meas_time_ms = pixy.last_update_ms();
}

// Data Fusion Algorithm
else if (skydiver.last_pixy_meas_time_ms<AP_HAL::millis()-200){
	if(skydiver.location_valid && skydiver.GPS_distance>3 && skydiver.last_update_ms>AP_HAL::millis()-500){
		skydiver.azimuth = skydiver.GPS_angle;
		UAV_spin = false;
	}
	else{
		UAV_spin = true;
	}
}
	

// log Pixy message
if (should_log(MASK_LOG_GPS) && !ahrs.have_ekf_logging()) {
	Log_Write_Skydiver_Pixy();
}

}