I am new to Create2 and I hope someone can help me.
I have a problem with reading the sensor data or the data I get.
I have setup a nodeJS application running on a Raspberry PI 3B+. Sending data (e.g: drive commands) is no problem - the robot makes what I want.
At program start I send the optcodes 128 (start) and 132 (full mode). After that I send optcode 148 with the packageIds to start streaming. This works also very fine. I have defined the sensors I need in an array:
this.readCommands = [
{
packetId: 21, //Charging state
len: 1,
name: 'Charging state',
signed: false,
value: 0
},
{
packetId: 25, //Battery charge
len: 2,
name: 'Battery charge',
signed: false,
value: 0
},
{
packetId: 26, //Battery capacity
len: 2,
name: 'Battery capacity',
signed: false,
value: 0
},
{
packetId: 28, //Cliff left Signal
len: 2,
name: 'Cliff left Signal',
signed: false,
value: 0
},
{
packetId: 29, //Cliff front left Signal
len: 2,
name: 'Cliff font left Signal',
signed: false,
value: 0
},
{
packetId: 30, //Cliff front right Signal
len: 2,
name: 'Cliff front right Signal',
signed: false,
value: 0
},
{
packetId: 31, //Cliff right Signal
len: 2,
name: 'Cliff right Signal',
signed: false,
value: 0
},
{
packetId: 46, //Light Bump Left Signal
len: 2,
name: 'Light Bump Left Signal',
signed: false,
value: 0
},
{
packetId: 47, //Light Bump Front Left Signal
len: 2,
name: 'Light Bump Front Left Signal',
signed: false,
value: 0
},
{
packetId: 48, //Light Bump Center Left Signal
len: 2,
name: 'Light Bump Center Left Signal',
signed: false,
value: 0
},
{
packetId: 49, //Light Bump Center Right Signal
len: 2,
name: 'Light Bump Center Right Signal',
signed: false,
value: 0
},
{
packetId: 50, //Light Bump Front Right Signal
len: 2,
name: 'Light Bump Front Right Signal',
signed: false,
value: 0
},
{
packetId: 51, //Light Bump Right Signal
len: 2,
name: 'Light Bump Right Signal',
signed: false,
value: 0
}
];
To fill the 148-data:
const tempArr = [148, this.readCommands.length];
this.readCommands.forEach(c => tempArr.push(c.packetId));
this.writeToPort(Uint8Array.from(tempArr)).subscribe(() => {
});
When data arrives I collect the data and when I have a full package I try to interpret the data.
The packets I get seem to be ok (also the checksum is fine)
Here one as UINT8s:
19, 38, 21, 0, 25, 9, 253, 26, 10, 137, 28, 10, 46, 29, 10, 77, 30, 10, 86, 31, 10, 83, 46, 0, 31, 47, 0, 65, 48, 0, 59, 49, 0, 22, 50, 0, 24, 51, 0, 6, 50
But when I take these values I have data, e.g. for cliff-signals, that are much more greater than 4095 as described in the OI spec.
Also I get a battery capacity of 35082 while battery charge is greater than 60000.
Here's my code for reading the packet:
if (!this._checkData(data))
return;
let index = 2;
while (index < data.length-1) {
const id = data.readUInt8(index);
const cmd = this.readCommands.find(c => c.packetId === id);
if (!cmd) {
index++;
continue;
}
switch (cmd.len) {
case 1:
cmd.value = cmd.signed? data.readInt8(index +1) : data.readUInt8(index+1);
index+=2;
break;
case 2:
cmd.value = cmd.signed ? data.readInt16LE(i+1) : data.readUInt16LE(i+1);
index+=3;
break;
}
}
What am I doing wrong?
When I reset the robot I get the message:
Soft reset!
Roomba by iRobot!
stm32 2016-06-13-1127-L
battery-current-zero
254
b
box vars restored!
languages: english (0)
Is the firmware too old?
Can someone help me with that problem?
Daniel