Before you all say post on ROS forum, let me tell you I believe the issue is somewhere on the coding becuas eit is somehow reading serial data but not updating frequently.
Hello Everyone, This is my first time working with ROS and integrating with Teensy3.6. I am working on receiving GPS data (longitude and latitude) from minipc saved from a drone flight. I need to read the data through minipc and store it in the SD-card of teensy. The need is to receive GPS data during flight and save it in the SD card of teensy along with other parameters from 3 more sensors.
Now while I am new with ROS interface to teensy and looking at different examples and tutorial, i have made a basic script but I am facing issues related to data storing and I have no idea is the problem related to coding maybe serial comm. setup or some other. I have pasted my script of my program and if anyone faces the same issue or someone can point out in right direction will be very helpful.
When program run at first, it generates around 5-10 and sometimes even more empty files and after that it starts writing in the files. The data once written is still not right because many files have same data and is not updating for most part of the time. I tried sending data from minipc at 1Hz, 10 Hz and 100 Hz but no success and baud rate is 9600. I dont know why its making problem. Serial monitor also does not update the data coordinates although for most part of time, serial data is seen garbaged and jumpled but not right data.
The data is written right in the files how I want to its just dont update every times the loop runs. Hope someone can help me because im working on serial comm. along while and got hands on minipc yesterday for actual what i want to do. Thank you.
Hello Everyone, This is my first time working with ROS and integrating with Teensy3.6. I am working on receiving GPS data (longitude and latitude) from minipc saved from a drone flight. I need to read the data through minipc and store it in the SD-card of teensy. The need is to receive GPS data during flight and save it in the SD card of teensy along with other parameters from 3 more sensors.
Now while I am new with ROS interface to teensy and looking at different examples and tutorial, i have made a basic script but I am facing issues related to data storing and I have no idea is the problem related to coding maybe serial comm. setup or some other. I have pasted my script of my program and if anyone faces the same issue or someone can point out in right direction will be very helpful.
When program run at first, it generates around 5-10 and sometimes even more empty files and after that it starts writing in the files. The data once written is still not right because many files have same data and is not updating for most part of the time. I tried sending data from minipc at 1Hz, 10 Hz and 100 Hz but no success and baud rate is 9600. I dont know why its making problem. Serial monitor also does not update the data coordinates although for most part of time, serial data is seen garbaged and jumpled but not right data.
The data is written right in the files how I want to its just dont update every times the loop runs. Hope someone can help me because im working on serial comm. along while and got hands on minipc yesterday for actual what i want to do. Thank you.
Code:
#include <ros.h>
#include <sensor_msgs/NavSatFix.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SD_t3.h>
File logfile;
ros::NodeHandle nh;
float lat;
float lon;
char buf1[15];
char buf2[15];
String x, y;
void messageCb(const sensor_msgs::NavSatFix& msg) {
lat = msg.latitude;
lon = msg.longitude;
dtostrf(lon, 13, 9, buf1);
dtostrf(lat, 13, 10, buf2);
x = buf1;
y = buf2;
digitalWrite(13, HIGH - digitalRead(13)); // blink the led
}
ros::Subscriber<sensor_msgs::NavSatFix> sub("/dji_sdk/gps_position", messageCb);
void setup()
{
nh.initNode();
nh.subscribe(sub);
Serial.begin(9600);
//Serial.println("Initializing SD card...");
if (!SD.begin(chipSelect)) {
//Serial.println("Card failed, or not present");
return;
}
//Serial.println("card initialized.");
pinMode(ledpin, OUTPUT);
pinMode(13, OUTPUT);
//Serial.println("Setup Completed !!");
while(!nh.connected()) nh.spinOnce();
}
void loop()
{
String dataString = "";
logfile.flush();
char filename[] = "Log000.txt";
for (uint16_t i = 0; i < 1000; i++)
{
filename[3] = i / 100 + '0';
int Hun = i / 100;
filename[4] = (i - (Hun * 100)) / 10 + '0';
filename[5] = i % 10 + '0';
if (!SD.exists(filename))
{
logfile = SD.open(filename, FILE_WRITE);
break;
}
}
if (!logfile)
{
//Serial.println("Error: Logfile could not be created !!");
}
if (logfile)
{
logfile.println("No.\tLongitude\t\tLattitude");
for (int k = 1; k < 5; k++) {
String num = k;
String dataline = (num + "\t" + x + "\t" + y);
logfile.println(dataline);
//delay(1000);
}
logfile.close();
}
Serial.print(x);
Serial.print(" ");
Serial.println(y);
nh.spinOnce();
delay(50);
}