Irving wrote:I take it therefore the calculation shown in data[4] now isn't correct for the GB Controller? I doubt you'll find it documented anywhere, but if you have a dozen or so samples it should (may?) be possible to reverse engineer it..
gcebiker wrote:I am going to have a fish around today and see if i can find a BitWise online calculator of some sort.
int speed; // int (16 bit) - signed number from -32768 to 32767
int direction;
int maxSpeedVal;
unsigned char data[5];
void setup() {
Serial.begin(38400);
speed = 192 ;
direction = 191 ;
maxSpeedVal = 255 ; // full speed on the Shark Remote
}
void loop(){
data[0] = (0x60); // Packet type identifier
data[1] = (speed); // (0x80 | ((speed >> 3) & 0x7f)); // Joystick speed reading (7 MSbs)
data[2] = (direction); //0x80 | ((direction >> 3) & 0x7f); // Joystick direction reading (7 MSbs)
data[3] = (maxSpeedVal);//0x80 | ((maxSpeedVal >> 1 ) & 0x7f); // SpeedVal pot reading (7 MSbs)
data[4] = 0x80 | ((maxSpeedVal & 0x1) << 6) | ((speed & 0x7) << 3) | (direction & 0x7);
for (unsigned char i = 0; i < 5; i++)
Serial.println (data [i]);
}
void sharkOnMode() {
digitalWrite(dePin, HIGH);
Deadband = 32;
digitalWrite(dePin, HIGH);
directionPinVal = DirectionVal;
directionPinVal = constrain(directionPinVal, 1000, 2000);
directionPinVal = map(directionPinVal, 1000, 2000, 0, 1023); // Power base only recoginizes values in this range
// Woody's Deadband code
if (directionPinVal > (512 + Deadband)) //deadband defined in global veriables
direction = map(directionPinVal, (512 + Deadband), 1023, 513, 1023); // Turn Right ??
else if
(directionPinVal < (512 - Deadband))
direction = map(directionPinVal, 0, (512 - Deadband), 0, 511); //Turn Left ??
else
direction = 512; // 512 = stop
{
speedPinVal = SpeedVal;
speedPinVal = constrain(speedPinVal, 1000, 2000);
speedPinVal = map(speedPinVal, 1000, 2000, 0, 1023);
// Woody's Deadband code
if (speedPinVal > (512 + Deadband)) //deadband defined in global veriable
speed = map(speedPinVal, (512 + Deadband), 1023, 513, 1023); // Forwards ??
else if
(speedPinVal < (512 - Deadband))
speed = map(speedPinVal, 0, (512 - Deadband), 0, 511); // Reverse ??
else
speed = 512; // 512 = stop
// Code thanks to Irvings bit genius.
maxSpeedVal = 255; // full speed on the Shark Remote
data[0] = (0x60); // Packet type identifier
data[1] = 0x80 | ((speed >> 3) & 0x7f); // Joystick speed reading (7 MSbs)
data[2] = 0x80 | ((direction >> 3) & 0x7f); // Joystick direction reading (7 MSbs)
data[3] = 0x80 | ((maxSpeedVal >> 1 ) & 0x7f); // SpeedVal pot reading (7 MSbs)
data[4] = 0x80 | ((maxSpeedVal & 0x1) << 6) | ((speed & 0x7) << 3) | (direction & 0x7); //checksum for the speed/direction/maxspeed pot.
data[5] = 0x80; // 128; // default horn off 128 , horn on value is 130
data[6] = 0x84; // 132; // Value read during data capture, taken to be the 'on' value.
data[7] = 0x80; // 128; // chair mode/ drive 128, tilt/aux output 129
// Checksum calculations - thanks to Irving,Jim and Tony
byte sum = 0;
for (int i = 0; i < 8; i++)
sum += data[i] & 0x7f;
data[8] = (255 - (sum & 127));
data[9] = 0x0F; // 15; // all packets end with this identifier
for (unsigned char i = 0; i < 10; i++)
Serial.write(data[i]);
}
digitalWrite(dePin, LOW);
}
snaker wrote:Is data[4] a checksum byte? If so, its formula should use XOR operators (not OR).
Byte 3:
bit 6: Speed pot reading LSb
bits 5-3: Joystick speed reading (3 LSbs)
bits 2-0: Joystick direction reading (3 LSbs)
int speed; // int (16 bit) - signed number from -32768 to 32767
int direction;
unsigned char maxSpeedVal;
unsigned char data[5];
void setup() {
Serial.begin(38400);
speed = 512; // these are PPM Values from the RC receiver. 10bit values
direction = 512; // these are PPM Values from the RC receiver. 10bit values
maxSpeedVal = 255 ; // full speed on the Shark Remote. 8bit values
}
void loop() {
data[0] = (0x60); // Packet type identifier
data[1] = 0x80 ^ ((speed >> 3) & 0x7f); // Joystick speed reading (7 MSbs)
data[2] = 0x80 ^ ((direction >> 3) & 0x7f); // Joystick direction reading (7 MSbs)
data[3] = 0x80 ^ ((maxSpeedVal >> 1 ) & 0x7f); // SpeedVal pot reading (7 MSbs)
data[4] = 0x80 ^ ((maxSpeedVal & 0x1) << 6) ^ ((speed & 0x7) << 3) ^ (direction & 0x7);
for (unsigned char i = 0; i < 5; i++)
Serial.println (data [i]);
}
in the serial monitor96
192
192
255
192
Byte 3:
bit 6: Speed pot reading LSb
bits 5-3: Joystick speed reading (3 LSbs)
bits 2-0: Joystick direction reading (3 LSbs)
snaker wrote:The following formula gives the result 214. Try it with your other values to see if it is correct.
int checksum = (speed & 0xE0) | ((direction & 0xE0) >> 3) | ((maxSpeedVal & 0x80) >> 6);
gcebiker wrote:Byte 0: Joystick speed reading (7 MSbs)
Byte 1: Joystick direction reading (7 MSbs)
Byte 2: Speed pot reading (7 MSbs)
Byte 3:
bit 6: Speed pot reading LSb
bits 5-3: Joystick speed reading (3 LSbs)
bits 2-0: Joystick direction reading (3 LSbs)
Byte 4:
bit 6: Joystick Error (indicates joystick mirror fault or some such problem when set).
bit 5: Speed pot Error (indicates out-of range error or some such problem when set).
bit 4: Local fault (such as CPU fault) (set when there is a fault)
bit 3: Battery charger inhibit state (set when inhibit is active)
bit 2: Power switch state (all bits in this byte are 1 for active, 0 for inactive).
bit 1: Horn switch state ( set when switch is pressed)
bit 0: Lock switch state ( set when switch is pressed)
Byte 5:
bit 6: Hazard light request
bit 5: Left Indicator request
bit 4: Right Indicator request
bit 3: Remote Inhibit. When this bit is 1, the SPM shall not drive.
bit 2: Programmer Comms flow control. Set when SPM MAY send HHP packets, clear when buffer space is low.
bit 1: Joystick Calibration active ( set when JC mode is active )
bit 0 : Power down / Sleep mode confirmation. Set when Sleep or Power down has been requested and the SR is
ready to comply.
Byte 6:
bit 6: Not used
bit 5: Local non-critical fault (causes "limp" mode)
bit 4: Headlight request
bits 3-0: Operating mode, defined as
00 Drive mode
01 Actuator 1 mode
02 Actuator 2 mode
03 Actuator 1+2 mode
04-0F currently undefined
Irving wrote:I don't believe there is an issue with the calculation of data[4]. i suspect its something else, maybe the packet checksum?
The checksum calculation is correct for the majority of packets, but in the test data you provided there are 2 extended 'q' packets at lines 978 and 1003 that have extended data after the checksum and a further checksum just before the 15 terminator byte.
rollingcowboy wrote:gcebiker,
I don't mean to throw cold water on -- but you should heed BM' comments on the lack of starting torque using the GB motors.
They may not pull the boat up the ramp. Do you have a way to test the GB to see if it will pull?
Return to Everything Powerchair
Users browsing this forum: No registered users and 158 guests