James Hagerty
Created February 1, 2020

HoverGames Accelerant Arrester

Firefighters can use UAVs to give advanced warning and assistance when accelerants are present.

BeginnerShowcase (no instructions)Over 2 days26

Things used in this project

Hardware components

Pixy2Cam
×1
KIT-HGDRONEK66
NXP KIT-HGDRONEK66
×1
RDDRONE-FMUK66
NXP RDDRONE-FMUK66
×1

Story

Read more

Code

Pixy2 Clockrate

C/C++
#ifndef _PIXY2_H
#define _PIXY2_H

#include "TPixy2.h"
//#include "SPI.h"
#include <drivers/device/spi.h>

#define PIXY_SPI_CLOCKRATE       2000000

class Link2SPI
{
public:
  int8_t open(uint32_t arg)
  {

 //   SPI.begin();
//    SPI.beginTransaction(SPISettings(PIXY_SPI_CLOCKRATE, MSBFIRST, SPI_MODE3));
	return 0;
  }
	
  void close()
  {
    // SPI.endTransaction();
  }
    
  int16_t recv(uint8_t *buf, uint8_t len, uint16_t *cs=NULL)
  {
    // uint8_t i;
    // if (cs)
    //   *cs = 0;
    // for (i=0; i<len; i++)
    // {
    //   buf[i] = SPI.transfer(0x00);
    //   if (cs)
    //     *cs += buf[i];
    // }
    return len;
  }
    
  int16_t send(uint8_t *buf, uint8_t len)
  {
    // uint8_t i;
    // for (i=0; i<len; i++)
    //   SPI.transfer(buf[i]);
    return len;
  }
};


typedef TPixy2<Link2SPI> Pixy2;

#endif

Pixy2 I2C Driver

C/C++
The documentation for Pixy2 states that I2C will be protocol with the faster transfer rate. We started with this, but we were unsuccessful in getting the camera to talk through the FMUK66 to the QGroundControl PX4.
//
// begin license header
//
// This file is part of Pixy CMUcam5 or "Pixy" for short
//
// All Pixy source code is provided under the terms of the
// GNU General Public License v2 (http://www.gnu.org/licenses/gpl-2.0.html).
// Those wishing to use Pixy source code, software and/or
// technologies under different licensing terms should contact us at
// cmucam@cs.cmu.edu. Such licensing terms are available for
// all portions of the Pixy codebase presented here.
//
// end license header
//
// Arduino ICSP SPI link class

#ifndef _PIXY2_H
#define _PIXY2_H

#include "TPixy2.h"
#include <drivers/device/i2c.h>
#include "board_config.h"

#define IRLOCK_I2C_BUS			PX4_I2C_BUS_EXPANSION
#define IRLOCK_I2C_ADDRESS		0x54 /** 7-bit address (non shifted) **/

#define IRLOCK0_DEVICE_PATH		"/dev/Pixy2"

class PIXY2_I2C: public device::I2C
{
public:
	PIXY2_I2C();
	virtual ~PIXY2_I2C() = default;

	bool is_external();
	int init();

	int8_t open(uint32_t arg)
	{
		return I2C::init();;
	}

	void close()
	{
		;
	}

	int16_t recv(uint8_t *buf, uint8_t len, uint16_t *cs = NULL)
	{
		uint8_t i;

		if (cs) {
			*cs = 0;
		}

		transfer(nullptr, 0, &buf[0], len);

		for (i = 0; i < len; i++) {

			if (cs) {
				*cs += buf[i];
			}
		}

		return len;
	}

	int16_t send(uint8_t *buf, uint8_t len)
	{

		transfer(&buf[0], len, nullptr, 0);
		//int ret_tran = transfer(&buf[0], len, nullptr, 0);
		//printf("ret_tran = %i\n", ret_tran);

		return len;
	}

private:
	bool _external;
};

PIXY2_I2C::PIXY2_I2C() :
	I2C("PIXY2_I2C", IRLOCK0_DEVICE_PATH, PX4_I2C_BUS_EXPANSION, IRLOCK_I2C_ADDRESS, 400000)
{
	_external = true;
}

bool PIXY2_I2C::is_external()
{
	return _external;
};

int PIXY2_I2C::init()
{
	return I2C::init();
};


typedef TPixy2<PIXY2_I2C> Pixy2;

#endif

Credits

James Hagerty

James Hagerty

1 project • 0 followers

Comments