Skip to content

Commit

Permalink
Split HTML/CSS/JS
Browse files Browse the repository at this point in the history
Added calculated direction of plate-sovling correction in units
  • Loading branch information
artyom-beilis committed Apr 20, 2023
1 parent d334359 commit 59e8f60
Show file tree
Hide file tree
Showing 6 changed files with 984 additions and 871 deletions.
2 changes: 2 additions & 0 deletions include/plate_solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace ols {
class PlateSolver {
public:
struct Result {
double center_ra_deg;
double center_de_deg;
int center_row;
int center_col;
int target_row;
Expand Down
46 changes: 46 additions & 0 deletions include/plate_solver_ctl_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
#include <cppcms/service.h>
#include <booster/log.h>

#include "rotation.h"
#include "server_sent_events.h"
#include "util.h"

namespace ols {
class PlateSolverControlApp : public ControlAppBase {
public:
Expand All @@ -20,19 +22,63 @@ namespace ols {
{
dispatcher().map("POST","/?",&PlateSolverControlApp::solve,this);
}
struct DeltaAZ {
double delta_alt;
double delta_az;
};

DeltaAZ calc_delta_alt_az(double t_ra,double t_de,double c_ra,double c_de,double lat,double lon)
{
Derotator derot(lon,lat,c_ra,c_de);
double time_now = time(nullptr);
auto src = derot.rayFromPos(c_ra,c_de,time_now);
double src_E = src.x;
double src_N = src.y;
double src_U = src.z;
auto tgt = derot.rayFromPos(t_ra,t_de,time_now);
double tgt_E = tgt.x;
double tgt_N = tgt.y;
double tgt_U = tgt.z;

double d_alt = (std::asin(tgt_U) - std::asin(src_U)) * 180 / M_PI;
double d_az = (std::atan2(tgt_E,tgt_N) - std::atan2(src_E,src_N)) * 180 / M_PI;
if(d_az > 180)
d_az -= 360;
if(d_az < -180)
d_az += 360;
DeltaAZ res;
res.delta_alt = d_alt;
res.delta_az = d_az;
return res;
}

void solve()
{
double fov = content_.get<double>("fov");
double ra = content_.get<double>("ra");
double de = content_.get<double>("de");
double rad = content_.get<double>("rad");
double constexpr invalid_geolocation = 1e6;
double lat = content_.get<double>("lat",invalid_geolocation);
double lon = content_.get<double>("lon",invalid_geolocation);
std::string img = "/plate_solving_solution.jpeg";
std::string jpeg = data_dir_ + img;
try {
auto res = PlateSolver::solve_last_image(jpeg,fov,ra,de,rad);
response_["solved"]=true;
response_["distance_to_target"] = res.angle_to_target_deg;
response_["result_image"] = "/data" + img;
response_["delta_ra"] = ra - res.center_ra_deg;
response_["delta_de"] = de - res.center_de_deg;
if(lat != invalid_geolocation && lon != invalid_geolocation) {
auto delta = calc_delta_alt_az(ra,de,res.center_ra_deg, res.center_de_deg,lat,lon);
response_["delta_alt"] = delta.delta_alt;
response_["delta_az"] = delta.delta_az;
}
else {
response_["delta_alt"] = cppcms::json::null();
response_["delta_az"] = cppcms::json::null();
}
}
catch(std::exception const &e) {
response_["solved"]=false;
Expand Down
2 changes: 2 additions & 0 deletions src/plate_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ namespace ols {
r.target_col = xt;
r.target_row = rows - yt;
r.angle_to_target_deg = diff_deg;
r.center_ra_deg = ra0;
r.center_de_deg = de0;
return r;
}
double PlateSolver::get(std::map<std::string,double> const &vals,std::string const &name)
Expand Down
Loading

0 comments on commit 59e8f60

Please sign in to comment.