Skip to content

Commit

Permalink
Added reset position functions to the rotation-sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
WillXuCodes committed Oct 19, 2020
1 parent 20a5598 commit 20c6651
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
18 changes: 17 additions & 1 deletion include/pros/rotation.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace c {
int32_t rotation_reset(uint8_t port);

/**
* Set the Rotation sensor to a desired rotation value.
* Set the Rotation sensor position reading to a desired rotation value.
*
* This function uses the following values of errno when an error state is
* reached:
Expand All @@ -63,6 +63,22 @@ int32_t rotation_reset(uint8_t port);
*/
int32_t rotation_set_position(uint8_t port, uint32_t position);

/**
* Resets the Rotation sensor position to 0.
*
* This function uses the following values of errno when an error state is
* reached:
* ENXIO - The given value is not within the range of V5 ports (1-21).
* ENODEV - The port cannot be configured as an Rotation Sensor
*
* \param port
* The V5 Rotation Sensor port number from 1-21
* \return 1 if the operation was successful or PROS_ERR if the operation
* failed, setting errno.
*/
int32_t rotation_reset_position(uint8_t port);

/**
* Get the Rotation sensor's current rotational position. Specifically, in
* terms of hundreths of degrees.
Expand Down
17 changes: 16 additions & 1 deletion include/pros/rotation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Rotation {
virtual std::int32_t reset();

/**
* Set the Rotation sensor to a desired rotation value.
* Set the Rotation sensor position reading to a desired rotation value.
*
* This function uses the following values of errno when an error state is
* reached:
Expand All @@ -58,6 +58,21 @@ class Rotation {
*/
virtual std::int32_t set_position(std::uint32_t position);

/**
* Reset the Rotation sensor to a desired rotation value.
*
* This function uses the following values of errno when an error state is
* reached:
* ENXIO - The given value is not within the range of V5 ports (1-21).
* ENODEV - The port cannot be configured as an Rotation Sensor
*
* \param position
* The position in terms of ticks
* \return 1 if the operation was successful or PROS_ERR if the operation
* failed, setting errno.
*/
virtual std::int32_t reset_position(void);

/**
* Resets rotation sensor by multiplying the rotation reading by
* -1 only if the direction was recently reversed.
Expand Down
6 changes: 6 additions & 0 deletions src/devices/vdml_rotation.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ int32_t rotation_reset(uint8_t port) {
return_port(port - 1, 1);
}

int32_t rotation_reset_position(uint8_t port) {
claim_port_i(port - 1, E_DEVICE_ROTATION);
vexDeviceAbsEncPositionSet(device->device_info, 0);
return_port(port - 1, 1);
}

int32_t rotation_set_position(uint8_t port, uint32_t position) {
claim_port_i(port - 1, E_DEVICE_ROTATION);
vexDeviceAbsEncPositionSet(device->device_info, position);
Expand Down
6 changes: 5 additions & 1 deletion src/devices/vdml_rotation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ std::int32_t Rotation::set_position(std::uint32_t position) {
return pros::c::rotation_set_position(_port, position);
}

std::int32_t Rotation::reset_position(void) {
return pros::c::rotation_set_position(_port, 0);
}

std::int32_t Rotation::get_position(void) {
return pros::c::rotation_get_position(_port);
return pros::c::rotation_get_angle_cpp(_port);
}

std::int32_t Rotation::get_velocity(void) {
Expand Down

0 comments on commit 20c6651

Please sign in to comment.