User avatar
Davespice
Forum Moderator
Forum Moderator
Posts: 1661
Joined: Fri Oct 14, 2011 8:06 pm
Location: London, United Kingdom
Contact: Website Twitter

How to trigger the camera based on ISS location

Wed Jan 17, 2018 3:20 pm

Hi folks, I recently had a team ask how to do this so I knocked up some code to show the concept;
https://gist.github.com/davidhoness/b0e ... 5a9fed68c0

You use two-line element telemetry to calculate ISS position (refresh from http://www.celestrak.com/NORAD/elements/stations.txt) and then the haversine function to calculate geodesic distance to the target location that you want to photograph. The ground sampling distance of the V1 camera is 161 meters per pixel (assuming 400km ISS altitude) so 2592 x 161 = about 417 km. Then you just check if the calculated distance to target is less than half of 417 = 208 (distance from center of the image to the edge) and if so start taking pictures.

Remember that your code will run for 3 hours, which is two orbits - and it's possible that the ISS will not fly over a single target. So you should improve my code so that it can look for multiple targets for contingency.

Good luck folks!

Edit: Correction for image range.

D O Sullivan
Posts: 5
Joined: Mon Nov 27, 2017 9:45 am

Re: How to trigger the camera based on ISS location

Tue Jan 23, 2018 8:57 am

Hi Dave.

Thank you for the assistance with the code. My students were very impressed with it and have been able to modify the code for multiple targets.
However one problem that they haven't solved is for the Sense hat LED to simultaneously display a message when the target is in range (or the camera has been triggered). They have been working on it for a number of days without success
.
They have created code that will display a message if the target is in range without using the camera but they can't get both the camera and LED display to work simultaneously if the target location is in range.

Any help would be greatly appreciated.

Thanks

Darren

User avatar
Davespice
Forum Moderator
Forum Moderator
Posts: 1661
Joined: Fri Oct 14, 2011 8:06 pm
Location: London, United Kingdom
Contact: Website Twitter

Re: How to trigger the camera based on ISS location

Tue Jan 23, 2018 9:49 am

Ah, that may be because the show message function is a blocking call. What that means is that if you call

Code: Select all

sense.show_message("a really long string of text")
the whole message has to scroll on the LED matrix before the next line of code gets run.

What I would suggest to do is just show an icon or a symbol on the LED matrix, which returns instantly, just before you start the camera preview in your code.

D O Sullivan
Posts: 5
Joined: Mon Nov 27, 2017 9:45 am

Re: How to trigger the camera based on ISS location

Tue Jan 23, 2018 11:21 am

Hi Dave

Thanks for the reply.
In the meantime the students solved the problem on how to display a message simultaneously with the camera taking a picture whilst the target is in range. The solution was to indent the block of 'If' code for the LED message further than the 'If' block to trigger the camera.

Darren

User avatar
Davespice
Forum Moderator
Forum Moderator
Posts: 1661
Joined: Fri Oct 14, 2011 8:06 pm
Location: London, United Kingdom
Contact: Website Twitter

Re: How to trigger the camera based on ISS location

Tue Jan 23, 2018 2:49 pm

I'm not sure I follow but I'll take your word for it. It will still be a blocking call unless you use something like multi-threading.

User avatar
Davespice
Forum Moderator
Forum Moderator
Posts: 1661
Joined: Fri Oct 14, 2011 8:06 pm
Location: London, United Kingdom
Contact: Website Twitter

Re: How to trigger the camera based on ISS location

Tue Jan 23, 2018 5:13 pm

I've just realised a bug in my code. 417 km is the horizontal width of the image, from the left side to the right. We want to check for distance from the center to the edge, so you should use 208 as the image_range value. I've updated the code example on GitHub.

D O Sullivan
Posts: 5
Joined: Mon Nov 27, 2017 9:45 am

Re: How to trigger the camera based on ISS location

Sun Feb 04, 2018 9:42 pm

Thanks for all your help so far Dave.

One of my student groups are using the Pi NOIR camera to identify peatlands. They wish to code for some target areas without peatland to act as a comparison. Rather than code for 50 separate control targets is it possible to code the camera to take a photo whilst crossing a specified line of longitude whilst the latitude value is between -51.6 to + 51.6 ?
e.g -50 < latitude < 50, longitude = -100

User avatar
Davespice
Forum Moderator
Forum Moderator
Posts: 1661
Joined: Fri Oct 14, 2011 8:06 pm
Location: London, United Kingdom
Contact: Website Twitter

Re: How to trigger the camera based on ISS location

Mon Feb 05, 2018 9:45 am

Yes of course. Just make an if statement that tests the sublat and sublong properties of the iss ephem object.
Just replace A, B, X and Y with the numbers you want.

Code: Select all

iss_lat = degrees(iss.sublat)
iss_long = degrees(iss.sublong)
if iss_long > A and iss_long < B and iss_lat > X and iss_lat < Y:
    cam.capture("foo.jpg")

Return to “Astro Pi”

Who is online

Users browsing this forum: No registered users and 3 guests