Hello
i am using pixy2.3 camera connected to Arduino H7 lite, and i am driving two 12bit 333hz servos on Arduino H7 lite, for tracking an object. Please can you check my code if its good or not: PositionXmotor=MinServo+float(double((pixy.ccc.blocks[0].m_x)/pixy.frameWidth*(MaxServo - MinServo)); PositionYmotor=MinServo+float(double(pixy.ccc.blocks[0].m_y)/pixy.frameHeight*(MaxServo - MinServo));
i asked the GPT4 and he told me to use this better code with mapping:PositionXmotor = map(pixy.ccc.blocks[0].m_x, 0, pixy.frameWidth, MinServo, MaxServo); PositionYmotor = map(pixy.ccc.blocks[0].m_y, 0, pixy.frameHeight, MinServo, MaxServo);GPT4: If you want to use the Arduino H7 Lite to control your servos, you donβt need to cast the result of the calculation to float or double. so what do you Think ![]()
to get better 12bit resolution output do i need to add (int32_t) for the code like this: PositionXmotor=MinServo+float(double((int32_t)pixy.ccc.blocks[0].m_x)/(int32_t)pixy.frameWidth*(MaxServo - MinServo)); PositionYmotor=MinServo+float(double((int32_t)pixy.ccc.blocks[0].m_y)/(int32_t)pixy.frameHeight*(MaxServo - MinServo));
i got the idea from this code: panOffset = (int32_t)pixy.frameWidth/2 - (int32_t)pixy.ccc.blocks[0].m_x; tiltOffset = (int32_t)pixy.ccc.blocks[0].m_y - (int32_t)pixy.frameHeight/2;
please let me know! Thanks