SovGVD/nodetello

Question: stick position

Closed this issue · 5 comments

Hi @SovGVD

I've been combing through your repo trying to get something in JS to use the low-level packet API.

I had a question about this bit in your code:

// TODO... this string manipulation is soooo slow!
var tmp_roll     = "00000000000"+(parseInt(1024 + 660 * this.stickData.roll) & 0x07ff).toString(2); tmp_roll=tmp_roll.substr(-11);
var tmp_pitch    = "00000000000"+(parseInt(1024 + 660 * this.stickData.pitch) & 0x07ff).toString(2); tmp_pitch=tmp_pitch.substr(-11);
var tmp_throttle = "00000000000"+(parseInt(1024 + 660 * this.stickData.throttle) & 0x07ff).toString(2); tmp_throttle=tmp_throttle.substr(-11);
var tmp_yaw      = "00000000000"+(parseInt(1024 + 660 * this.stickData.yaw) & 0x07ff).toString(2); tmp_yaw=tmp_yaw.substr(-11);
//var tmp_boost    = "00000000000"+(parseInt(1024 + 660 * 0)).toString(2);

Why are you adding 11 0's and then substr'ing them right off immediately after?

I realise this is code ported from go & python and whatever else is out there, but I'm a bit confused about the stick position packets and that's the bit I need to get working :)

Cheers

Hi. If I remember it right, stick values is 11 (or 12) bits, so we need to have 11 values all the time to contact it correctly later, that is why we need to have leading zero bites at least the same size as value length. I'm not happy with that strings solution, but final value should be really long and JS INT can't handle it.

That makes sense; working with large numbers in base-2 strings is never fun (and slow).

I'm not sure what platform you were targeting but node 10.4+ has support for BigInt. I'm trying to write some code for a Tessel 2, which is stuck at node 8.x.

That was another issue about it #1

@SovGVD I commented on that issue, but I was able to replicate the logic using BigInt and the code more or less copied straight over from TelloLib. I hope this helps a bit.

Thank you @ruswerner ! I will try to check that code with my drone and hopefully merge it.