मुख्य कंटेंट तक स्किप करें

एक साथ लक्ष्य साधना और दूरी समायोजन

यह उदाहरण लक्ष्य साधना और दूरी समायोजन को एक ही विधि में संयोजित करता है। https://thumbs.gfycat.com/UncommonIncomparableDassierat-size_restricted.gif यह उदाहरण लक्ष्य साधना और दूरी समायोजन के उदाहरणों से कोड का उपयोग करता है और सब कुछ एक सरल फ़ंक्शन में एक साथ रखता है। इसका उपयोग करके, आप अपने रोबोट को "करीब" ला सकते हैं और फिर स्वचालित रूप से लक्ष्य साधने और सही दूरी तक चलाने के लिए कोड का उपयोग कर सकते हैं।

float KpAim = -0.1f;
float KpDistance = -0.1f;
float min_aim_command = 0.05f;

std::shared_ptr<NetworkTable> table = NetworkTable::GetTable("limelight");
float tx = table->GetNumber("tx");
float ty = table->GetNumber("ty");

if (joystick->GetRawButton(9))
{
float heading_error = -tx;
float distance_error = -ty;
float steering_adjust = 0.0f;

if (tx > 1.0)
{
steering_adjust = KpAim*heading_error - min_aim_command;
}
else if (tx < -1.0)
{
steering_adjust = KpAim*heading_error + min_aim_command;
}

float distance_adjust = KpDistance * distance_error;

left_command += steering_adjust + distance_adjust;
right_command -= steering_adjust + distance_adjust;
}