So, the issue that I am currently having is trying to make the arm in our code move to the correct positions in a 5 index array when I press the Y button. Right now, the index selection part of the code works but the arm does not go the correct angles that are specified by this array. For example, it thinks the zero position is near the top part of the lift.
clawarm.hpp:
#pragma once
//-----------------------------------------
// File name: clawarm.hpp
// Creation date: 7/13/26
// Created By: Zach D
// Description: The claw arm mechanism class, contains methods for controling the claw's arm
//-----------------------------------------
// File includes
//--------------------
#include "EZ-Template/PID.hpp"
#include "pros/motors.hpp"
#include "pros/rotation.hpp"
#include "EZ-Template/api.hpp"
// the Claw arm class
namespace ArmClass {
// the position array, will have data after rotation is plugged into brain
const inline int positionArray[5] = {0, -29, 0, -60, -30};
// The arm class
class arm {
// contains vars and functions that can only be acessed internally
private:
pros::Motor* armMotor;
pros::Rotation* armRotation;
ez::PID ArmPID{0.15, 0, 0.05, 0, "Arm"};
int angle_target = 0;
// conatains vars and functions that can be acessed publicly by class members or other .cpp file
public:
// the constructor function for the arm class, it takes in a motor, rotation sensor
arm(pros::Motor &clawArmMotor, pros::Rotation &clawArmRotation) {
armMotor = &clawArmMotor;
armRotation = &clawArmRotation;
}
// this function will move the arm based on an int that ranges from 0-4.
void move_to_position(int position);
// initalizer function that sets up motor and sensor
void initalize();
// updates pid
void update_pid();
};
}
clawarm.cpp
//-----------------------------------------
// File name: clawarm.hpp
// Creation date: 7/13/26
// Created By: Zach D
// Description: The claw arm mechanism class, contains methods for controling the claw's arm
//-----------------------------------------
// File includes
//--------------------
#include "mechanisums/clawarm.hpp"
#include "EZ-Template/PID.hpp"
#include "EZ-Template/util.hpp"
#include "pros/motors.hpp"
#include "pros/rotation.hpp"
#include "EZ-Template/api.hpp"
#include "helpers.hpp"
#include "pros/rtos.hpp"
// this contains all of the function code
// this function will move the arm based on an int that ranges from 0-4.
void ArmClass::arm::move_to_position(int position) {
// getting angle from array index
angle_target = positionArray[position];
pros::screen::print(
pros::E_TEXT_MEDIUM,
0,
"Index: %d Target: %d",
position,
angle_target
);
// setting pid
ArmPID.target_set(angle_target);
}
void ArmClass::arm::update_pid() {
// getting angle
int current_angle = get_rotation_value(*armRotation);
// caculating ouput
double output = ArmPID.compute(current_angle);
//pros::screen::print(pros::E_TEXT_MEDIUM, 0, "Angle: %d", current_angle);
pros::screen::print(
pros::E_TEXT_MEDIUM,
3,
"Angle: %d",
current_angle
);
// moving arm motor
armMotor->move(output);
}
// this function inits the sensors, pid and motor
void ArmClass::arm::initalize() {
armMotor->set_brake_mode(pros::v5::MotorBrake::hold);
armRotation->reset_position();
armMotor->tare_position();
ArmPID.exit_condition_set(5, 10);
}
helpers.cpp
//-----------------------------------------
// File name: helpers.cpp
// Creation date: 6/12/26
// Created By: Zach D
// Description: Contains some helper functions for the robot
//-----------------------------------------
// helper variables
//------------------
int positionState = 0;
// helper constant variables
//----------------------------
const int MAX_STATE = 5;
// includes
//-----------
#include "mechanisums/intake.hpp"
#include "mechanisums/lift.hpp"
#include "pros/misc.h"
#include "pros/rotation.hpp"
#include "pros/screen.h"
#include "helpers.hpp"
#include "subsystems.hpp"
#include "EZ-Template/util.hpp"
// conversion functions
int get_rotation_value(pros::Rotation rotSensor) {
int converted_val = rotSensor.get_angle() / 100;
//pros::screen::print(pros::E_TEXT_MEDIUM, 3, "Current rotation %d", converted_val);
return converted_val;
}
// helper functions for driver and auto
void driver_control_intake() {
if(master.get_digital(pros::E_CONTROLLER_DIGITAL_R2)) {
botIntake.set_intake_direction(IntakeClass::FORWARD);
botIntake.set_status(true);
} else if(master.get_digital(pros::E_CONTROLLER_DIGITAL_R1)) {
botIntake.set_intake_direction(IntakeClass::BACKAWRD);
botIntake.set_status(true);
} else {
botIntake.set_status(false);
}
}
void driver_control_lift() {
if(master.get_digital(pros::E_CONTROLLER_DIGITAL_L1)) {
botLift.move_lift_with_status(LiftClass::liftState::RAISE);
} else if(master.get_digital(pros::E_CONTROLLER_DIGITAL_L2)) {
botLift.move_lift_with_status(LiftClass::liftState::LOWER);
} else {
botLift.move_lift_with_status(LiftClass::liftState::STOP);
}
}
void init_the_bot() {
botLift.initalize();
botClawArm.initalize();
}
void arm_task() {
while (true) {
botClawArm.update_pid();
pros::delay(10);
}
}
void driver_control_arm() {
if(master.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_Y)) {
// incrementing by one every time when button is pressed
positionState++;
// preventing postionState from going outside of array index
if (positionState >= MAX_STATE) {
positionState = 0;
}
// for debugging
// pros::screen::print(pros::E_TEXT_MEDIUM, 4, "Current position %d", positionState);
// calling the arm position function
}
botClawArm.move_to_position(positionState);
}
This is all of the code that the robot uses to move the arm.