0 / 8 页已完成

和 LemLib 的关系Relationship with LemLib

视频讲解Video Explanation
How to Set Up LemLib + PROS Like a Pro
BennyBuildsRobots · 19 分钟min · 英文English · LemLib 完整安装配置教程Complete LemLib setup tutorial
VEX Auton Tutorial Part 5 — Writing Autonomous
EthanMik · 23 分钟min · 英文English · 用 odometry 写自动程序实战Writing autonomous programs with odometry

上面的代码是从头写的,帮助理解原理。实际比赛中,很多队伍用 LemLib 库,它帮你封装好了定位系统。The code above was written from scratch to help you understand the principles. In actual competitions, many teams use the LemLib library, which packages the tracking system for you.

LemLib 的核心逻辑和我们写的基于同一个数学模型(圆弧近似),但实现细节有差异:LemLib's core logic is based on the same math model as ours (circular arc approximation), but with implementation differences:

C++
// LemLib 的核心算法(简化版)
localX = 2 * sin(deltaHeading / 2) * (deltaX / deltaHeading + horizontalOffset);
localY = 2 * sin(deltaHeading / 2) * (deltaY / deltaHeading + verticalOffset);

// 转换到全局坐标
odomPose.x += localY * sin(avgHeading) + localX * (-cos(avgHeading));
odomPose.y += localY * cos(avgHeading) + localX * sin(avgHeading);
注意看符号差异Notice the Sign Difference:LemLib 的横轮项用了 -cos+sin,我们的代码用的是 +cos-sin。这不是谁写错了 —— 而是横轮正方向的约定不同。LemLib 定义横轮"向左为正",我们定义"向右为正",所以符号自然相反。: LemLib uses -cos and +sin for the horizontal wheel, while our code uses +cos and -sin. Neither is wrong — the positive direction convention for the horizontal wheel is different. LemLib defines "left = positive," we define "right = positive," so the signs are naturally opposite.

核心公式是一样的: 弦长 = 2R sin(Δθ/2)R = 弧长/Δθ + 偏移。区别只在坐标轴方向的约定。The core formula is the same: chord = 2R sin(Δθ/2), R = arc/Δθ + offset. The only difference is the axis direction convention.

LemLib 额外提供的功能:Additional features LemLib provides:

建议Recommendation:先用自己写的代码理解原理,比赛时再切换到 LemLib 享受它的额外功能。遇到定位不准时,你知道该查什么。: First understand the principles with your own code, then switch to LemLib for competitions to enjoy its extra features. When tracking is inaccurate, you'll know what to check.
检查点Checkpoint
我们的代码和 LemLib 的横轮符号不同,这说明?Our code and LemLib have different horizontal wheel signs. What does this mean?