Skip to content
This repository has been archived by the owner on Sep 22, 2024. It is now read-only.

Commit

Permalink
Merge pull request #19 from ubcuas/mp_integrate
Browse files Browse the repository at this point in the history
Mp integrate
  • Loading branch information
21chanas3 authored Apr 28, 2024
2 parents 94c1881 + 3d084a1 commit 4bab495
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
14 changes: 14 additions & 0 deletions configs/mp.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,20 @@ func (mp MissionPlanner) Takeoff(alt float64) bool {
return resp.StatusCode == http.StatusOK
}

func (mp MissionPlanner) Arm(arm int) bool {
json, err := json.Marshal(map[string]int{
"arm": arm,
})

if err != nil {
log.Fatal("[MP Functions] Error marshalling arm")
}

resp := genericPost(mp.url+"/arm", json)

return resp.StatusCode == http.StatusOK
}

func (mp MissionPlanner) SetHome(waypoint models.Waypoint) bool {
mpwp := mpWaypoint{
ID: strconv.Itoa(waypoint.ID),
Expand Down
24 changes: 24 additions & 0 deletions controllers/drone_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,30 @@ func Takeoff(c echo.Context) error {
return c.HTML(http.StatusAccepted, "")
}

// Arm arms the drone
//
// @Summary Arm drone
// @Description Arms the drone after takeoff request
// @Tags Drone
// @Produce json
// @Success 200 {object} models.Drone "Success"
// @Router /status [get]
func Arm(c echo.Context) error {
mp := c.Get("mp").(*configs.MissionPlanner)

var arm float64
json_map := make(map[string]interface{})
err := json.NewDecoder(c.Request().Body).Decode(&json_map)
if err != nil {
return err
} else {
arm = json_map["arm"].(float64)
}

mp.Arm(int(arm))
return c.HTML(http.StatusAccepted, "")
}

// Land tells the drone to land
//
// @Summary Take off Drone
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func main() {
}

e := echo.New()
e.Use(middleware.CORS())

e.Use(util.DBMiddleware(db))
e.Use(util.MPMiddleware(mp))
Expand Down Expand Up @@ -68,6 +69,7 @@ func main() {
e.GET("/drone/queue", controllers.GetQueue)
e.POST("/drone/queue", controllers.PostQueue)
e.POST("/drone/home", controllers.PostHome)
e.POST("/drone/arm", controllers.Arm)

//Ground Objects
e.POST("/groundobject", controllers.CreateGroundObject)
Expand Down

0 comments on commit 4bab495

Please sign in to comment.