How can I get the GPS time from the pixhawk, on a "companion computer" - dronekit-python

My project will have two "companion computers" on-board a quadcopter. One will speak to APMCopter autopilot running on a pixhawk, using dronekit python, and the other will communicate with it's peer over ethernet.
I'd like both computers to have closely synchronized time, and I'd like them both to be synchronized to the GPS time from the GPS connected to the pixhawk.
The documentation for mavlink indicates that there is a "system time" message which includes the GPS time in uSec. How do I obtain this data on the companion computer, using DroneKit?

#vehicle.on_message('SYSTEM_TIME')
def listener(self, name, message):
print message.time_unix_usec
ArduCopter will send the system time about 4 times per second. This method will run every time.

Related

How to get time information on XBee S2C?

On my project, I'm using XBeeS2C+Digispark and connect each other as Serial communication(UART). I'm using SoftSerial on Digispark to set XBee. I have 1 coordinator and 3 routers in the same network.
Now I'm trying to tell routers the coordinator time. I don't now well how can I get time information(year, month, day, hour etc..) using XBee. Is it possible to get time information from Coordinator?
Or should I use RTC?
XBee hardware does not keep track of date/time. You could have a single device on your network use an RTC or some other connection (maybe a gateway with Ethernet/Wi-Fi connectivity to the Internet?) to track time and broadcast that information to the other devices periodically.

Delay measurement and synchronisation between raspberry pi

I am doing a project with 2 raspberry pi which work as servers and a laptop which is the client.
I have attached to each raspberry and usb microphone and using the Portaudio Library im capturing audio streaming
and send it back to the laptop through a tcp/ip connection.
The scope of this project is to locate sound sources and it works like this. I run a .c file on each raspberry which are
connected on the same LAN as with the PC laptop. When this program is running on both raspberryies i have a message
"Waiting connection for a client". The next thing to do is just to run the matlab file which will start the both raspberries
and record. I have managed to synchronize the raspberries to start in the same time through a simple condition like
do
{
sleep(0.01);
j = read(newsockfd, &start,1 );
} while (j==0);
so right before both raspberries have to start recording i pause them in order to finish the initialization commands and so on
and then i just send a character "start = 'k'" through my matlab program
t1,t2 are tcp connections
start = 'k';
fwrite (t1, k);
fwrite (t2, k);
from this point both raspberries open the PortAudio stream and call recordCallBack function.
When I run the application and clap, i still get a delay of 0.2s between them which causes
an error of 60 meters. I have also checked the execution time of the fwrite function but that might
save me about 0.05 seconds which will still lead to results far from reality.
This project is based on TDOA measurement and it is desired to have a delay under 0.01 seconds to get accuracy <1m.
I have heard that linux has some very accurate timers, and i was thinking that maybe i could use that to
clock the time inside the functions in the .c file. Anyway if you have any ideas of how i can measure the delay from
the point i send the character 'k' from matlab until the point where the audio stream is opened in microphone, or any
way how i could synchronize the 2 linux servers please help.
ps: both are raspberry 2 pi and connected through UTP cables so the processing and transmission rates should be the same
It looks like an interesting project but I think you underestimate the problem a little bit. The first issue is that you need to synchonize the two sensors. Given the speed of sound and if you want an accuracy of about 1m you need to synchronize them with about 1ms accuracy. You could try with the Network Time Protocol but I'm not sure you can reach this accuracy even with a master on the local network. Better synchronization can be achieved with PTP (over ethernet) or GPS if you can receive a GPS signal.
Then if you manage to achieve this, a first step could be to record a few hand claps on both raspberry pi, save the timestamp when you start recording on both and see if you actually obtain something significant. Maybe you will also need to use a microcontroller and a real-time operating system instead!
There are many ways to synchronise clocks. It could be in a system level or in application level.
System level tend to be easier because there are already tools to do the job. I don't recommend you doing PTP at this stage, as mentioned by Emilien, since it is quite complicated to make it work. Instead I would recommend you to use normal setup via the same NTP network on all machines.
Example of NTP setup:
Query the server with # ntpdate -q 0.rhel.pool.ntp.org
If it is running, setup your local clock with # ntpdate 0.rhel.pool.ntp.org 1.rhel.pool.ntp.org
OBS: # means root user (which most likely means that you will need to run the command with sudo), whilst $ means normal user.
Check all machines times with $ date +%k:%M:%S.%N which will return the clock down to a nanosecond resolution.
If that doesn't acheive the desired result then try the PTP aproach, or just synchronise all your devices when they connect to the master, where your master can normalise each independant clock. I will not go into details here.
Then you can send your audio data via TCP/IP (or perhaps UDP/IP to lower latency) like you mentioned before, but always send the timestamp of your slave machine associated to a audio frame using clock_gettime() function with CLOCK_REALTIME as the clk_id argument.

Does USB mass-storage class requires re-enumeration after timeout?

this might be a stupid question,
I was debugging a USB storage device on an ARM-CortexM4 platform (STM32F4 series) which runs embedded Linux. The ARM is working as USB host, and tries to communicate with a thumb drive in USB full speed (12Mb/s).
Now here is the problem. After successful enumeration and several SCSI commands thru BULK transfers, the capacity and everything can be read correctly. However, after about 15 seconds when I try to send these SCSI commands again (under same condition), the USB host controller just returns 'Transaction Error', which looks like the device is not responding to BULK transfers anymore (not ACKing) and the host controller times out. The question is, is there any timeout mechanism for USB mass-storage class or SCSI system such that, after a timeout the system must be re-enumerated or re-probed, otherwise it won't respond anymore?
I understand this might be due to a stupid error in my program, or due to some limitations on the specific hardware. However when I used usbmon module in Linux on a PC to capture the transfers on the very same thumb drive, I can see the operating system actually sends a sequence probing command (Read-max-Lun followed by Test-unit-ready) every 5 sec, which could be the reason why the thumb drive doesn't fail on my PC.
Thanks! I'm looking forward to any replies.
I think you're on the right track with the Test Unit Ready commands.. I am in the middle of writing a mass storage device driver for an embedded device and When testing on OS X, after the initial SCSI queries, my device receives Test Unit Ready command about once every second when no other activity is occurring. Since your post is quite old, I recommend you post your own solution if you've since solved your problem.
Otherwise try adding periodic test unit ready commands from the host side when there is no other activity.. You could set and activate a timer whenever USB activity is occurring. If the timer fires, u can send a Test unit ready command.. Rinse repeat.

Using NTP without a server, just for the Control System

edit:
I am essentially attempting to utilize the NTP code from section 5 of RFC 1129 from the command-line. Simply setting the clock, or even making an adjtime call is insufficient. I'd like to utilize the pre-existing NTP code for properly synchronizing clocks, but without the network part.
I have a system that cannot reach the internet, but has access to a high-precision clock. I would like to periodically poll that high precision clock for the time, and utilize the control system in NTP to synchronize the system clock.
Does anyone know how to feed input to NTP without faking an NTP server?
Ideally, I would be able to feed it the current time on the command-line, and have it use that as another point for synchronizing the clock.
bash ~ $ something 1416899507
Looking into refclock_nmea.c it appears as though a simple mechanism would be to feed ntpd time values from GPS NMEA sentences. Alternatively, it doesn't appear to be that difficult to just implement a custom refclock driver. David Mills has a tutorial available: http://www.eecis.udel.edu/~mills/ntp/html/howto.html

Send a message to a machine that is powered off

I would like to send a message, or something can be an advise from a pc to an another pc (only one, or at the most 2), the latter is powered off.
The pc which should send the message is a windows server 2003 os, instead the pc which should receive the message is a windows xp os.
The two machines are in the same domain and they work together through an ingres database.
The message will be sent at night, because there is an ingres database back up procedure that runs at night when my pc will be powered off, but when in the morning i will be at work I would like to read this message as a net send message, or something like
Unfortunately the net send command is disabled in our network, so I can't use it, but i'm looking a way for sending this message.
Have you any suggestion? thank you
Use age-old simple file based messaging.
Store a message in a specific file in the server and write a simple application which runs on startup on your machine to read it and display it.
And this is apart from rerun's great suggestion :)
There is breaking new technology available called email.
Is the machine powered off or in standby?
If if is in standby, then I will defer to someone who may have a better idea of how to get wake the machine to wake up programatically(sp?).
If it is powered off then read on...
If you have access to the machines bios settings, then I would suggest scheduling a power on event in the range of the time before the backup normally completes.
Then it is a matter of receiving the message and optionally shutting back down afterward?
If you are unable to change the bios settings, then does the machine "power on after power loss?" If so, get a programmable timer from the nearest retail store and power off before leaving at night and have the timer set to power on before the time the backup could reasonably be completed.
This is not really a software solution per se, but your problem does seem to be mostly hardware related (with the power off requirement and all...)

Resources