Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add to GPS API #630

Merged
merged 10 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions include/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
#endif /* __cplusplus */

#define PROS_VERSION_MAJOR 3
#define PROS_VERSION_MINOR 8
#define PROS_VERSION_PATCH 0
#define PROS_VERSION_STRING "3.8.0"
#define PROS_VERSION_MINOR 7
#define PROS_VERSION_PATCH 4
#define PROS_VERSION_STRING "3.7.4-dirty.19.1e7513d"

#include "pros/adi.h"
#include "pros/colors.h"
Expand Down
10 changes: 10 additions & 0 deletions include/pros/gps.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,16 @@ double gps_get_error(uint8_t port);
*/
gps_status_s_t gps_get_status(uint8_t port);

double gps_get_x_position(uint8_t port);

double gps_get_y_position(uint8_t port);

double gps_get_pitch(uint8_t port);

double gps_get_roll(uint8_t port);

double gps_get_yaw(uint8_t port);

/**
* Get the heading in [0,360) degree values.
*
Expand Down
10 changes: 10 additions & 0 deletions include/pros/gps.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,16 @@ class Gps {
*/
virtual std::int32_t set_rotation(double target) const;

virtual double get_x_position() const;

virtual double get_y_position() const;

virtual double get_pitch() const;

virtual double get_roll() const;

virtual double get_yaw() const;

/**
* Tare the GPS sensor's rotation value
*
Expand Down
47 changes: 46 additions & 1 deletion src/devices/vdml_gps.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,51 @@ gps_status_s_t gps_get_status(uint8_t port) {
return_port(port - 1, rtv);
}

double gps_get_x_position(uint8_t port) {
claim_port_f(port - 1, E_DEVICE_GPS);
double rtv = PROS_ERR_F;
V5_DeviceGpsAttitude data;
vexDeviceGpsAttitudeGet(device->device_info, &data, false);
rtv = data.position_x;
return_port(port - 1, rtv);
}

double gps_get_y_position(uint8_t port) {
claim_port_f(port - 1, E_DEVICE_GPS);
double rtv = PROS_ERR_F;
V5_DeviceGpsAttitude data;
vexDeviceGpsAttitudeGet(device->device_info, &data, false);
rtv = data.position_y;
return_port(port - 1, rtv);
}

double gps_get_pitch(uint8_t port) {
claim_port_f(port - 1, E_DEVICE_GPS);
double rtv = PROS_ERR_F;
V5_DeviceGpsAttitude data;
vexDeviceGpsAttitudeGet(device->device_info, &data, false);
rtv = data.pitch;
return_port(port - 1, rtv);
}

double gps_get_roll(uint8_t port) {
claim_port_f(port - 1, E_DEVICE_GPS);
double rtv = PROS_ERR_F;
V5_DeviceGpsAttitude data;
vexDeviceGpsAttitudeGet(device->device_info, &data, false);
rtv = data.roll;
return_port(port - 1, rtv);
}

double gps_get_yaw(uint8_t port) {
claim_port_f(port - 1, E_DEVICE_GPS);
double rtv = PROS_ERR_F;
V5_DeviceGpsAttitude data;
vexDeviceGpsAttitudeGet(device->device_info, &data, false);
rtv = data.yaw;
return_port(port - 1, rtv);
}

double gps_get_heading(uint8_t port) {
claim_port_f(port - 1, E_DEVICE_GPS);
double rtv = vexDeviceGpsDegreesGet(device->device_info);
Expand All @@ -101,7 +146,7 @@ double gps_get_heading_raw(uint8_t port) {

double gps_get_rotation(uint8_t port) {
claim_port_f(port - 1, E_DEVICE_GPS);
double rtv = vexDeviceGpsRotationGet(device->device_info);
double rtv = vexDeviceGpsHeadingGet(device->device_info);
return_port(port - 1, rtv);
}

Expand Down
20 changes: 20 additions & 0 deletions src/devices/vdml_gps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,26 @@ pros::c::gps_status_s_t Gps::get_status() const {
return pros::c::gps_get_status(_port);
}

double Gps::get_x_position() const {
return pros::c::gps_get_x_position(_port);
}

double Gps::get_y_position() const {
return pros::c::gps_get_y_position(_port);
}

double Gps::get_pitch() const {
return pros::c::gps_get_pitch(_port);
}

double Gps::get_roll() const {
return pros::c::gps_get_roll(_port);
}

double Gps::get_yaw() const {
return pros::c::gps_get_yaw(_port);
}

double Gps::get_heading() const {
return pros::c::gps_get_heading(_port);
}
Expand Down
7 changes: 7 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ void opcontrol() {
pros::Controller master(pros::E_CONTROLLER_MASTER);
pros::Motor left_mtr(1);
pros::Motor right_mtr(2);
pros::Gps my_gps(10);

while (true) {
pros::lcd::print(0, "%d %d %d", (pros::lcd::read_buttons() & LCD_BTN_LEFT) >> 2,
Expand All @@ -85,6 +86,12 @@ void opcontrol() {
int left = master.get_analog(ANALOG_LEFT_Y);
int right = master.get_analog(ANALOG_RIGHT_Y);

pros::lcd::print(2, "X pos: %fm, Y pos: %fm", my_gps.get_x_position(), my_gps.get_y_position());
pros::lcd::print(3, "Pitch: %fdeg", my_gps.get_pitch());
pros::lcd::print(4, "Roll: %fdeg", my_gps.get_roll());
pros::lcd::print(5, "Yaw: %fdeg", my_gps.get_yaw());
pros::lcd::print(6, "Get rotation: %fdeg", my_gps.get_rotation());

left_mtr = left;
right_mtr = right;

Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.8.0
3.7.4-dirty.19.1e7513d