安卓权限添加

This commit is contained in:
2026-10-20 16:45:51 +08:00
parent 68984aa7d2
commit 178cd2533c
9 changed files with 340 additions and 54 deletions

View File

@@ -1,36 +1,28 @@
/// 差速转向算法:摇杆坐标 -> 线速度/角速度(物理量)
///
/// 协议变更(2026-10):0x00 指令不再下发左右轮速(int16),
/// 改为下发线速度(m/s)、角速度(rad/s) 的 double 值,
/// 速度到轮速的运动学换算改由机器端完成。
class DiffSteerUseCase {
static const int polarityHigh = 0;
static const int polarityLow = 1;
/// 线速度满量程(m/s),以后按车型配置
static const double maxLinearSpeed = 1.0;
double _turnSpeedScale = 1500 / 100;
double _forwardSpeedScale = 3000 / 100;
int _speedAmplLimit = 3000;
/// 角速度满量程(rad/s),以后按车型配置
static const double maxAngularSpeed = 2.0;
int _leftWheelDir = polarityHigh;
int _rightWheelDir = polarityHigh;
int _xDir = polarityHigh;
int _yDir = polarityHigh;
/// 摇杆满格值(CCJoystick 输出范围 ±100)
static const int stickFullScale = 100;
Map<String, int> calculate(int x, int y) {
int turnSpeed = _signOperator((x * _turnSpeedScale).toInt(), _xDir);
int forwardSpeed = _signOperator((y * _forwardSpeedScale).toInt(), _yDir);
/// 摇杆坐标 (x, y) -> {'linear': 线速度 m/s, 'angular': 角速度 rad/s}
Map<String, double> calculate(int x, int y) {
// 摇杆原始值先归一化为 0~1 比例,再乘满量程物理量
double linear = (y / stickFullScale) * maxLinearSpeed;
double angular = (x / stickFullScale) * maxAngularSpeed;
// 倒车补偿
int adjustedTurn = (forwardSpeed >= 0 ? turnSpeed : -turnSpeed);
// 倒车补偿:倒车时转向反向,保持与旧轮速版一致的操作手感
// (若联调确认机器端已做该补偿,删除本行)
if (linear < 0) angular = -angular;
int left = _signOperator(forwardSpeed + adjustedTurn, _leftWheelDir);
int right = _signOperator(forwardSpeed - adjustedTurn, _rightWheelDir);
return {
'left': left.clamp(-_speedAmplLimit, _speedAmplLimit),
'right': right.clamp(-_speedAmplLimit, _speedAmplLimit),
};
return {'linear': linear, 'angular': angular};
}
int _signOperator(int num, int polarity) =>
polarity != polarityHigh ? -num : num;
}