[英]How could I increase the range of an HID axis? (steering wheel hits limit after a few degrees)
I have an encoder that gives 4300 increments per rev.我有一个编码器,每转可提供 4300 个增量。 And I need at least 3 turns in either direction.
我需要在任一方向上至少转 3 圈。 (for a steering wheel) However, when I turn it just a bit, it already hits the extremums.
(对于方向盘)但是,当我稍微转动它时,它已经达到了极值。 This is after a few degrees clockwise:
这是顺时针几度后:
This is my descripor:这是我的描述:
My code:我的代码:
while (1)
{
steer.direction = position - position_p;
position_p = position;
USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS, &steer, sizeof(steer));
HAL_Delay(5);
}
I have tried using an absolute value.我尝试过使用绝对值。 With 8 bits it just overflows after a few degrees and comes back to the opposite extremum.
对于 8 位,它只是在几度后溢出并返回到相反的极值。 Maybe 16 bits could solve that but I can't get it to work that way.
也许 16 位可以解决这个问题,但我无法让它以这种方式工作。
I managed to use a 16 bit absolute position.我设法使用了 16 位绝对 position。 I think it didn't work because the "send" function only took 8-bit values.
我认为它不起作用,因为“发送” function 仅采用 8 位值。 So I've split the 16 bit variable into a 2x8-bit array.
因此,我将 16 位变量拆分为 2x8 位数组。 (im using cubeIDE)
(我使用立方体IDE)
steer.direction[0] = position & 0x00FF;
steer.direction[1] = position >> 8;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.