CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/Rover/balance_bot.cpp
Views: 1798
1
#include<stdio.h>
2
#include "Rover.h"
3
4
// Function to set a desired pitch angle according to throttle
5
void Rover::balancebot_pitch_control(float &throttle)
6
{
7
// calculate desired pitch angle
8
const float demanded_pitch = radians(-throttle * 0.01f * g2.bal_pitch_max) + radians(g2.bal_pitch_trim);
9
10
// calculate required throttle using PID controller
11
throttle = g2.attitude_control.get_throttle_out_from_pitch(demanded_pitch, radians(g2.bal_pitch_max), g2.motors.limit.throttle_lower || g2.motors.limit.throttle_upper, G_Dt) * 100.0f;
12
}
13
14
// returns true if vehicle is a balance bot
15
// called in AP_MotorsUGV::output()
16
// this affects whether the vehicle tries to control its pitch with throttle output
17
bool Rover::is_balancebot() const
18
{
19
return ((enum frame_class)g2.frame_class.get() == FRAME_BALANCEBOT);
20
}
21
22