hamid_m wrote:Also, I have posted an example program in C which makes a pan/tilt mechanism track a red ball. I think, all the needed functions can be found there,
We need a new class(or header). From the structure, it is similar to Dynamixel.h/.c but needs some minimal changes. For example to send the capture command to the camera, or to read/write filter values.
As also Pedro pointed out, there is no more need to implement the calibration interface as is it now possible through USB.
ISR(SIG_UART0_RECV)
{
gbpRxInterruptBuffer[(gbRxBufferWritePointer++)] = RXD0_DATA;
}
ISR(SIG_UART1_RECV)
{
PCBuffer[(WritePointer++)] = RXD1_DATA;
}
unsigned long Timer=0;
ISR(SIG_OUTPUT_COMPARE1A)
{
// Place your code here
Timer++;
}
interrupt [USART0_RXC] void usart0_rx_isr(void)
{
gbpRxInterruptBuffer[(gbRxBufferWritePointer++)] = RXD0_DATA;
}
interrupt [USART1_RXC] void usart1_rx_isr(void)
{
PCBuffer[(WritePointer++)] = RXD1_DATA;
}
interrupt [TIM1_COMPA] void timer1_compa_isr(void)
{
// Place your code here
Timer++;
}
TxPacket(100, 15, 0);
for (i=0; i<160*120; i++) {
TxD8(RxD80());
}
void Image_Havimo( )
{
// Packet structure
dxl_instruction InstPacket;
dxl_status StatusPacket;
int ErrorCode;
WORD Model_Number;
InstPacket.id = 100; // ID
InstPacket.instruction = 15; // Read Register
InstPacket.address = 0; // Address of Model Number
InstPacket.parameter[0] = 0; // Number of byte to read
InstPacket.length = 3; // Length = 3(id, instruction, address) + (Number of parameter)
// Communication
//while( dxl_control( &InstPacket, &StatusPacket, true ) != ERR_CODE_SUCCESS){}
ErrorCode = dxl_control( &InstPacket, &StatusPacket, true );
// Packet structure
dxl_instruction InstPacket;
dxl_status StatusPacket;
int ErrorCode;
WORD Model_Number;
InstPacket.id = id; // ID
InstPacket.instruction = INST_PING; // Read instruction
InstPacket.address = 0; // Address of Model Number
//InstPacket.parameter[0] = 0; // Number of byte to read
InstPacket.length = 3; // Length = 3(id, instruction, address) + (Number of parameter)
void YCbCr2RGB(BYTE *buff, BYTE *red, BYTE *green, BYTE *blue)
{
int contador = 0;
BYTE Image[120*160];
for(int i=0; i<40; i++)
{
for(int j=0; j<120; j++)
{
for(int k=0; k<4; k++)
{
Image[(k+i*4)*120 + j] = buff[contador++];
}
}
}
BYTE y, cb, cr;
float calcR, calcB, calcG;
for(int i=0; i<160; i++)
{
for(int j=0; j<120; j++)
{
y = (Image[i*120+j] & 15) << 4;
//y = Image[i*120+j];
if( (j & 1) == 1)
{
cb = Image[i*120+j] & 240;
}
else
{
cr = Image[i*120+j] & 240;
}
calcR = y + 1.371 * (cr - 128);
calcG = y - 0.698 * (cr - 128) - 0.336 * (cb - 128);
calcB = y + 1.732 * (cb - 128);
if (calcR < 0)
calcR = 0;
if (calcG < 0)
calcG = 0;
if (calcB <0> 255)
calcR = 255;
if (calcG > 255)
calcG = 255;
if (calcB > 255)
calcB = 255;
red[i*120 + j] = (unsigned char)calcR;
green[i*120 + j] = (unsigned char)calcG;
blue[i*120 + j] = (unsigned char)calcB;
}
}
}
y = (Image[i*120+j] & 15) << 4;
//y = Image[i*120+j];
if( (j & 1) == 1)
{
cb = Image[i*120+j] & 240;
}
else
{
cr = Image[i*120+j] & 240;
}
void YCbCr2RGB(BYTE *buff, BYTE *red, BYTE *green, BYTE *blue)
{
int contador = 0;
BYTE Image[120*160];
for(int i=0; i<40; i++)
{
for(int j=0; j<120; j++)
{
for(int k=0; k<4; k++)
{
Image[(k+i*4)*120 + j] = buff[contador++];
}
}
}
BYTE y, cb, cr;
float calcR, calcB, calcG;
for(int j=0; j<120; j++)
{
for(int i=0; i<160; i++)
{
y = (Image[i*120+j] & 240);
//y = Image[i*120+j];
if( (i & 1) == 1)
{
cb = (Image[i*120+j] & 15) << 4;
}
else
{
cr = (Image[i*120+j] & 15) << 4;
}
calcR = y + 1.371 * (cr - 128);
calcG = y - 0.698 * (cr - 128) - 0.336 * (cb - 128);
calcB = y + 1.732 * (cb - 128);
if (calcR < 0)
calcR = 0;
if (calcG < 0)
calcG = 0;
if (calcB <0> 255)
calcR = 255;
if (calcG > 255)
calcG = 255;
if (calcB > 255)
calcB = 255;
red[i*120 + j] = (unsigned char)calcR;
green[i*120 + j] = (unsigned char)calcG;
blue[i*120 + j] = (unsigned char)calcB;
}
}
}