btsimonh / hoverboard-firmware-hack

New Hoverboard Firmware Hack. Now written from scratch and generally much better.
GNU General Public License v3.0
22 stars 4 forks source link

Position control #9

Closed EmerickH closed 5 years ago

EmerickH commented 5 years ago

Follows issue #5

I'm now able to communicate with board, but I have some little bug with control.

My complete test flow

Simple control

I tried sending:

var len = 4;
var test = new Buffer(len);

test[0] = "W".charCodeAt(0);
test[1] = 3; // Speed
test[2] = 10;
test[3] = 10;
...

but it's working only for 1 motor (right I think), the other one is harder to move but not moving.

Postion control

To get position control working, I need to set speed first then go to position control with a code I added to protocol_process_message:

        case PROTOCOL_CMD_POSITION_CONTROL:
            control_type = CONTROL_TYPE_POSITION;
            break;

and finally send pos message:

var len = 4;
var test = new Buffer(len);

test[0] = "W".charCodeAt(0);
test[1] = 5; // Pos control
test[2] = 1; // ~6mm
test[3] = 1; // ~6mm
...

But, same problem I have only one motor turning, maybe because of simple control bug.

Fix?

@btsimonh what did you mean by

0x01 0x00 0x00 0x00 - x increment =1 (by ~6mm) 0x01 0x00 0x00 0x00 - y increment =1 (by ~6mm)

I also tried:

var len = 10;
var test = new Buffer(len);

test[0] = "W".charCodeAt(0);
test[1] = 5; // Pos control
test[2] = 1; // ~mm
test[3] = 0;
test[4] = 0;
test[5] = 0;
test[6] = 1; // ~6mm
test[7] = 0;
test[8] = 0;
test[9] = 0;

But it's not working at all...

btsimonh commented 5 years ago

each hall 'tick' is about 6mm - but i think my comment above was wrong, because the code runs: void PostWrite_incrementposition(){ PosnData.wanted_posn_mm[0] += PositionIncr.Left; PosnData.wanted_posn_mm[1] += PositionIncr.Right; }

which indicates it's incrementing in mm.... so you'd probably have to increment by at least 10 to have it move at all :). if 10 fails, try 50....

so try: test[0] = "W".charCodeAt(0); test[1] = 5; // Pos control test[2] = 10; // 10mm test[3] = 0; test[4] = 0; test[5] = 0; test[6] = 10; // 10mm test[7] = 0; test[8] = 0; test[9] = 0;

(the 1, 0, 0, 0 is a little-endian 32 bit integer, so you could test.writeInt32(2, leftIncr); test.writeInt32(6, rightIncr) to set it more easily? - check the exact function spelling!).

question: Once you have turned on posn control, both your wheels should try to return to their starting posn if you move them. If both are not active then you have a different issue. If neither are active, you've not got into position mode....?

btsimonh commented 5 years ago

(oh, and same for speed, you need 2 32 bit numbers :) ) s

EmerickH commented 5 years ago

I just tried:

function writeInt32(buf, int, offset) {
    offset = offset || 0;
    buf[offset] = int >> 24;
    buf[offset + 1] = int >> 16;
    buf[offset + 2] = int >> 8;
    buf[offset + 3] = int;
}

var len = 10;
var test = new Buffer(len);

test[0] = "W".charCodeAt(0);
test[1] = 3; // Speed
writeInt32(test, 10, 2);
writeInt32(test, 10, 6);

Or the manual method:

test[2] = 10; // 10mm
test[3] = 0;
test[4] = 0;
test[5] = 0;
test[6] = 10; // 10mm
test[7] = 0;
test[8] = 0;
test[9] = 0;

for both speed and position inc but it's not working at all...

btsimonh commented 5 years ago

you can use https://nodejs.org/api/buffer.html#buffer_buf_writeint32le_value_offset like test.writeInt32LE(10, 2); test.writeInt32LE(10, 6); (your function is the BigEndian version). I'll go crack out the HB :). earned my brownie points this weekend by building a kitchen!

btsimonh commented 5 years ago

enable is not set? maybe. just trying again now.

btsimonh commented 5 years ago

ok, i think I've found the issue, definately a bug; let me test first.... :)

btsimonh commented 5 years ago

ok, pushed.

features: set enable: ///////////////////////////////// var len = 2+1; var test = new Buffer(len); test[0] = "W".charCodeAt(0); test[1] = 9; test[2] = msg.payload; msg.payload = test; return msg;

Send posn increment (try 100) //////////////////////////////////// var len = 2+4+4; var test = new Buffer(len); test[0] = "W".charCodeAt(0); test[1] = 5; test.writeInt32LE(msg.payload, 2); test.writeInt32LE(msg.payload, 6); msg.payload = test; return msg;

Set Speed (try 100) /////////////////////////////////// var len = 2+4+4; var test = new Buffer(len); test[0] = "W".charCodeAt(0); test[1] = 3; test.writeInt32LE(msg.payload, 2); test.writeInt32LE(msg.payload, 6); msg.payload = test; return msg;

I've also added (not tested) disablepoweroff and dbeug_out, so these can be set from the protocol. Let me know how you get on.

There is something strange about setting enable from 0->1 - something to do with PID initialisation?

btsimonh commented 5 years ago

just pushed Deadreckoner :) read with:

var len = 2; var test = new Buffer(len); test[0] = "R".charCodeAt(0); test[1] = 0x0c; msg.payload = test; return msg;

sends back three int32s, X, Y and degrees.

EmerickH commented 5 years ago

Hi @btsimonh I just tried to compile last version of your repository but I have everywhere:

"DEADRECKONER" is undefined
and
"INTEGER_XYT_POSN" is undefined

And effectively there's not any declaration for theses objects Also you included everywhere

#include "DeadReckoner.h"
or
#include "deadreckoner.h"

That doesn't exist, maybe you forgot to add this file to your commit ? If it just doesn't exist tell me I will create it with a DEADRECKONER struct.

I also have a problem on protocol.c:

int paramcount = sizeof(params)/sizeof(params[0]);
-> expression must have a constant value

(this is normal but this variable seems not to be used anywhere, so I just commented it)

btsimonh commented 5 years ago

sorry; yes missed the file. try again now... I think the paramcount error will go away when deadreckoner.h is there.... s