Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement and bugfix. #2

Open
serkansmg opened this issue Oct 20, 2024 · 0 comments
Open

enhancement and bugfix. #2

serkansmg opened this issue Oct 20, 2024 · 0 comments

Comments

@serkansmg
Copy link

serkansmg commented Oct 20, 2024

this part was buggy..
`

/* Extract target 2 data from the frame */
sensorData = extractData(TARGET_2, position);
if (sensorData.x != 0)
{
m_callback(TARGET_2, sensorData);// it was TARGET_3
}

`

and i add 2 feature to sensorData

`

Ld2450::SensorData Ld2450::extractData(SensorTarget target,
DataPosition position)
{
SensorData sensorData;

int offset = (target * 8); // each target 8 bytes
sensorData.x =
    ((int16_t)position.start[offset + 1] << 8) | position.start[offset + 0];
if (position.start[offset + 1] & 0x80)
  sensorData.x = -sensorData.x + 0x8000;
sensorData.y = (position.start[offset + 3] << 8 | position.start[offset + 2]);
if (sensorData.y != 0)
  sensorData.y -= 0x8000;
sensorData.speed =
    position.start[offset + 5] << 8 | position.start[offset + 4];
if (position.start[offset + 5] & 0x80)
  sensorData.speed = -sensorData.speed + 0x8000;
sensorData.resolution =
    position.start[offset + 7] << 8 | position.start[offset + 6];
    //calculate distance
     sensorData.distance = sqrt(sensorData.x * sensorData.x + sensorData.y * sensorData.y);
     sensorData.angle = atan2(sensorData.y, sensorData.x) * 180.0 / M_PI;
    

return sensorData;

}`

and sensor data is now:
`

struct SensorData
{
int x;
int y;
int speed;
int resolution;
double distance;
double angle;
};
`

also added:
`
/**
* @brief Get the current tracking mode
*
* @returns 0 - single target, 1 - multi target
*/
bool getTargetTrackingMode(uint8_t &mode); //to .h file

//to .cpp
bool Ld2450::getTargetTrackingMode(uint8_t &mode)
{

sendCommand(Ld2450Commands::GET_TARGET, nullptr, 0);
return getAckFrame(DELAY_MS, [&](const DataPosition &pos)
                   {
                     if ((pos.end - pos.start) < 8)
                     {
                       return; // sainty check
                     }
                    ESP_LOGI(TAG, "getTargetTrackingMode Target tracking mode: %d", pos.start[6]);
                     //set mode
                      mode = pos.start[6]; });

}

`

i can create a pull request or you may add these.. or i can fork .. its up to you..
cheers..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant