I have gotten the arduino to send the lidar data points to Jonbot and for Jonbot to store and print the data to the terminal. Today's plan was to display this data.
As I was viewing the data printed by Jonbot, I saw some inaccurate values printed. I attempted to make adjustments to the arduino code, which led to more issues for data transmission, so I thought it would be best to simply restart the arduino code, now that I have a better understanding of how it should work. I decided rather than create a seperate method, I could use the printCollectedData() method as the .onRequest() method, since it already changed the data into a string, which it would print.
void printCollectedData() {
//Don't send anything if it is not in the correct state
if(currentState != STATE_REPORT_COLLECTED_DATA) {
byte dontSend[1];
dontSend[0] = -1;
Wire.write(dontSend, 1);
return;
}
int indexOfFirstSyncReading = 0;
// don't print the trailing readings from the first partial scan
while (!syncValues[indexOfFirstSyncReading]) {
indexOfFirstSyncReading++;
}
// print the readings for all the complete scans
int i = lastIndex + indexOfFirstSyncReading;
String s = String(angles[i], 3) + " " + String(distances[i]) + " " + String(signalStrengths[i]) + " ";
Serial.println(s);
//Send the data to Jonbot
char data[20];
s.toCharArray(data, 20);
Wire.write(data);
//Reset values if everything has been printed
lastIndex ++;
if(lastIndex + indexOfFirstSyncReading >= sampleCount) {
currentState = STATE_BEGIN_DATA_ACQUISITION;
scanCount = 0;
sampleCount = 0;
waitPrinted = false;
}
}
With this new code, all data which was sent was correct and sent smoothly. I also adjusted the progression of states, so that adjusting device settings and verifying would happen on start up, without any message from Jonbot. Also, I adjusted the code so that the states would loop through collection and printing continuously, unless a value of 2 was sent from Jonbot.
I downloaded Team 1418's FRC Dashboard application and edited for this project so that I could have a display of the 2 dimensional map created by the data from the lidar. I will go over the code for that in a seperate post. The data is sent from the robot to the dashboard via networktables. Originally, I sent the full array of datapoints at once to the dashboard and updated those points whenever a new full scan was sent to Jonbot. To do this, I created three table entries, distances, angles, and strengths, and when the dashboard detected a change in the distances table it would retrieve the data from the other two and add the points to the map. This worked! I was able to create an updating 2 dimensional map of the environment. I saw that the updates were very slow, so I changed the code so that as Jonbot recieved each data point it would send that point immediatley to the dashboard which would then add it to the map.
First Updating 2D Map
With the data transmission to the dashboard, I kept the three seperate table entries even though I was only sending one point, I should go back and change it so only one array of size 3, holding that point's distance, angle, and strength sends. Also, after researching SLAM (Simultaneous Localization And Mapping) for lidar maps, a seperate idea I have is to create a map of the room that gets further built as the robot travels. But to do this would require using a third party graphing tool on the dashboard to have an expanding grid, and using the robot's encoders and gyroscope. The idea I have to achieve a simple version of this map building is to keep track of the robots movement via a vector and then apply that vector to the cartesian coordinates of all collected datapoints, in order to have a map of the area with the robot's initial position as (0,0). This is just a side project though, the original plan is to create a path for the robot (I'm think walls of cardboard for right now) and have it navigate through it all on its own using the lidar.
© All Rights Reserved.