KurtE
Senior Member+
I thought I would continue this on a new thread as to not pollute GeekGuys thread:
http://forum.pjrc.com/threads/25067-W-A-L-T-E-R-2-0-and-the-Teensy-3-1
Just thought I would give an update. I talked with Nathan at Orion Robotics and I am trying out a couple of approaches.
The easiest would be to hack on their BMSerial class which the Roboclaw library is derived from and either do minimal like he did to support Arduino Due and check for IO pins and redirect to their hardware serial code. The Bitbanging code plane wont work in it. Or as an extension of this could put the Teensy changes in SoftwareSerial into BMSerial, which is not a bad idea regardless.
Alternatively derive their class from the class Serial and pass in the actual serial object like Serial1 or a SoftwareSerial object, into the constructor. I personally like this approach as it removes the redundant code, like there is read with timeout support in the stream class. Plus if you have different hardware, like maybe one based on Atmega644p who has Serialx on different pins, no problem or maybe you have some other class derived from Stream you wish to try...
I have a version of the library that I have updated to use the stream approach that I am currently testing. So far I am testing out the query functions as this is where most of my changes are, to remove the redundant reading with timeouts. So far most of this working great. However I am having a problem with a Hang/crash when I use the variable number of arguments version of his read. Not sure if this is because I did something wrong, or the Variable number arguments code is having problems, or because for some reason this query function uses pass the argument by reference, where all of the other Query functions, do it by passing pointers...
That is, if I do:
I get the prints entering the function, but not after. I did not touch the function The function RoboClawStream::ReadMinMaxLogicVoltages
However I Did update the read_n function:
As you see, I added prints to again see what was happening. I got the prints, I expected, including the "Exit" at the end, so I am suspecting the stack is being trashed...
Still investigating. If anyone wishes to look at the stuff. I did upload both the library and the test program up to Lynxmotion forum: http://www.lynxmotion.net/viewtopic.php?f=9&p=89534#p89534
http://forum.pjrc.com/threads/25067-W-A-L-T-E-R-2-0-and-the-Teensy-3-1
Just thought I would give an update. I talked with Nathan at Orion Robotics and I am trying out a couple of approaches.
The easiest would be to hack on their BMSerial class which the Roboclaw library is derived from and either do minimal like he did to support Arduino Due and check for IO pins and redirect to their hardware serial code. The Bitbanging code plane wont work in it. Or as an extension of this could put the Teensy changes in SoftwareSerial into BMSerial, which is not a bad idea regardless.
Alternatively derive their class from the class Serial and pass in the actual serial object like Serial1 or a SoftwareSerial object, into the constructor. I personally like this approach as it removes the redundant code, like there is read with timeout support in the stream class. Plus if you have different hardware, like maybe one based on Atmega644p who has Serialx on different pins, no problem or maybe you have some other class derived from Stream you wish to try...
I have a version of the library that I have updated to use the stream approach that I am currently testing. So far I am testing out the query functions as this is where most of my changes are, to remove the redundant reading with timeouts. So far most of this working great. However I am having a problem with a Hang/crash when I use the variable number of arguments version of his read. Not sure if this is because I did something wrong, or the Variable number arguments code is having problems, or because for some reason this query function uses pass the argument by reference, where all of the other Query functions, do it by passing pointers...
That is, if I do:
Code:
Serial.println("Enter Min/Max");
fValid = RClaw.ReadMinMaxLogicVoltages(ADDRESS, uMinV, uMaxV);
Serial.print("Min/Max: ");
Serial.print(fValid, DEC);
Serial.print(" ");
Serial.print(uMinV, DEC);
Serial.print(" ");
Serial.println(uMaxV, DEC);
Code:
bool RoboClawStream::ReadMinMaxLogicVoltages(uint8_t address,uint16_t &min,uint16_t &max){
uint16_t value;
bool valid = read_n(1,address,GETMINMAXLOGICVOLTAGES,&value);
min=value>>16;
max = value&0xFFFF;
return valid;
}
Code:
bool RoboClawStream::read_n(uint8_t cnt,uint8_t address,uint8_t cmd,...)
{
uint8_t data[6];
uint8_t crc;
uint8_t cbRead;
write(address);
crc=address;
write(cmd);
crc+=cmd;
Serial.print("Enter read_n: ");
Serial.print(cnt, DEC);
//send data with crc
va_list marker;
va_start( marker, cmd ); /* Initialize variable arguments. */
for(uint8_t index=0;index<cnt;index++){
uint32_t *ptr = (uint32_t *)va_arg(marker, void *);
Serial.print(" Loop ");
cbRead = _pstream->readBytes(data, (index==(cnt-1))? 5 : 4); // hack read checksum on last read
Serial.print(cbRead, DEC);
*ptr = ((uint32_t)data[0]<<24) | ((uint32_t)data[1]<<16) | ((uint32_t)data[2]<<8) | ((uint32_t)data[3]);
crc += data[0] + data[1] + data[2] + data[3];
}
va_end( marker ); /* Reset variable arguments. */
Serial.println("Exit");
// Assuming cnt is not zero last iteration should have read in the crc value
// BugBug Could actually look to see if we read in data...
return ((crc&0x7F)==data[4]);
}
Still investigating. If anyone wishes to look at the stuff. I did upload both the library and the test program up to Lynxmotion forum: http://www.lynxmotion.net/viewtopic.php?f=9&p=89534#p89534