PID Subsystem help - what on earth am I doing wrong?

I am trying to create a PIDSubsystem for a lift joint (I need to repeat for more than one, but if I can get one fixed, the others will fall in line…)

I have created the following which generates a giant splat that makes no sense to me… I have no attachment to the shared_ptr, so if there is a more approriate way, I am all for it.

LiftJoint1.h

#pragma once

#include <frc/WPILib.h>
#include <frc/commands/PIDSubsystem.h>
#include <ctre/Phoenix.h>

class LiftJoint1 : public frc::PIDSubsystem
{
    public:
		std::shared_ptr<WPI_TalonSRX> LiftJoint1_Motor;
		std::shared_ptr<frc::Potentiometer> LiftJoint1_Pot;

		LiftJoint1();
		void InitDefaultCommand() override;
		double ReturnPIDInput();
		void UsePIDOutput(double output);
		void SetLiftJointSetpoint(double pos);
};

LiftJoint1.cpp

#include "subsystems/LiftJoint1.h"
#include "RobotMap.h"

LiftJoint1::LiftJoint1() : frc::PIDSubsystem("LiftJoint1", LIFT_JOINT_KP, LIFT_JOINT_KI, LIFT_JOINT_KD){
	GetPIDController()->SetContinuous(false);
	LiftJoint1_Pot = std::make_shared<frc::Potentiometer>(1); //this would be a variable from robotmap.h
	LiftJoint1_Motor = std::make_shared<WPI_TalonSRX>(1); //this would be a variable from robotmap.h

	SetSetpoint(LIFT_POS_STOW_1);
	Enable();
}

void LiftJoint1::InitDefaultCommand(){
}

void LiftJoint1::UsePIDOutput(double output) {
	LiftJoint1_Motor->PIDWrite(output);
}

double LiftJoint1::ReturnPIDInput() {
	return LiftJoint1_Pot->PIDGet();
}

void LiftJoint1::SetLiftJointSetpoint(double pos) {
	SetSetpoint(pos);
}

And the gigantic splat…

> Task :compileFrcUserProgramReleaseExecutableFrcUserProgramCpp
In file included from c:\users\public\frc2019\roborio\arm-frc2019-linux-gnueabi\usr\include\c++\6.3.0\arm-frc2019-linux-gnueabi\bits\c++allocator.h:33:0,
                 from c:\users\public\frc2019\roborio\arm-frc2019-linux-gnueabi\usr\include\c++\6.3.0\bits\allocator.h:46,
                 from c:\users\public\frc2019\roborio\arm-frc2019-linux-gnueabi\usr\include\c++\6.3.0\memory:63,
                 from C:\Storage\FRC\2019\Code\TestRobot.Mk1\build\tmp\expandedArchives\cameraserver-cpp-2019.2.1-headers.zip_6d5c4a8bf55973d76d90eeb158bc5c66/cameraserver/CameraServer.h:12,
                 from C:\Storage\FRC\2019\Code\TestRobot.Mk1\build\tmp\expandedArchives\wpilibc-cpp-2019.2.1-headers.zip_c5f7002a6c1dfda8aa2899e2594d01fe/frc/WPILib.h:10,
                 from C:\Storage\FRC\2019\Code\TestRobot.Mk1\src\main\include/subsystems/LiftJoint1.h:3,
                 from C:\Storage\FRC\2019\Code\TestRobot.Mk1\src\main\cpp\subsystems\LiftJoint1.cpp:1:
c:\users\public\frc2019\roborio\arm-frc2019-linux-gnueabi\usr\include\c++\6.3.0\ext\new_allocator.h: In instantiation of 'void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = frc::Potentiometer; _Args = {int}; _Tp = frc::Potentiometer]':
c:\users\public\frc2019\roborio\arm-frc2019-linux-gnueabi\usr\include\c++\6.3.0\bits\alloc_traits.h:455:4:   required from 'static void std::allocator_traits<std::allocator<_Tp1> >::construct(std::allocator_traits<std::allocator<_Tp1> >::allocator_type&, _Up*, _Args&& ...) [with _Up = frc::Potentiometer; _Args = {int}; _Tp = frc::Potentiometer; std::allocator_traits<std::allocator<_Tp1> >::allocator_type = std::allocator<frc::Potentiometer>]'
c:\users\public\frc2019\roborio\arm-frc2019-linux-gnueabi\usr\include\c++\6.3.0\bits\shared_ptr_base.h:520:39:   required from 'std::_Sp_counted_ptr_inplace<_Tp, _Alloc, _Lp>::_Sp_counted_ptr_inplace(_Alloc, _Args&& ...) [with _Args = {int}; _Tp = frc::Potentiometer; _Alloc = std::allocator<frc::Potentiometer>; __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]'
c:\users\public\frc2019\roborio\arm-frc2019-linux-gnueabi\usr\include\c++\6.3.0\bits\shared_ptr_base.h:615:4:   required from 'std::__shared_count<_Lp>::__shared_count(std::_Sp_make_shared_tag, _Tp*, const _Alloc&, _Args&& ...) [with _Tp = frc::Potentiometer; _Alloc = std::allocator<frc::Potentiometer>; _Args = {int}; __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]'
c:\users\public\frc2019\roborio\arm-frc2019-linux-gnueabi\usr\include\c++\6.3.0\bits\shared_ptr_base.h:1100:35:   required from 'std::__shared_ptr<_Tp, _Lp>::__shared_ptr(std::_Sp_make_shared_tag, const _Alloc&, _Args&& ...) [with _Alloc = std::allocator<frc::Potentiometer>; _Args = {int}; _Tp = frc::Potentiometer; __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]'
c:\users\public\frc2019\roborio\arm-frc2019-linux-gnueabi\usr\include\c++\6.3.0\bits\shared_ptr.h:319:64:   required from 'std::shared_ptr<_Tp>::shared_ptr(std::_Sp_make_shared_tag, const _Alloc&, _Args&& ...) [with _Alloc = std::allocator<frc::Potentiometer>; _Args = {int}; _Tp = frc::Potentiometer]'
c:\users\public\frc2019\roborio\arm-frc2019-linux-gnueabi\usr\include\c++\6.3.0\bits\shared_ptr.h:619:14:   required from 'std::shared_ptr<_Tp1> std::allocate_shared(const _Alloc&, _Args&& ...) [with _Tp = frc::Potentiometer; _Alloc = std::allocator<frc::Potentiometer>; _Args = {int}]'
c:\users\public\frc2019\roborio\arm-frc2019-linux-gnueabi\usr\include\c++\6.3.0\bits\shared_ptr.h:635:39:   required from 'std::shared_ptr<_Tp1> std::make_shared(_Args&& ...) [with _Tp = frc::Potentiometer; _Args = {int}]'
C:\Storage\FRC\2019\Code\TestRobot.Mk1\src\main\cpp\subsystems\LiftJoint1.cpp:6:57:   required from here
c:\users\public\frc2019\roborio\arm-frc2019-linux-gnueabi\usr\include\c++\6.3.0\ext\new_allocator.h:120:4: error: invalid new-expression of abstract class type 'frc::Potentiometer'
  { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from C:\Storage\FRC\2019\Code\TestRobot.Mk1\build\tmp\expandedArchives\wpilibc-cpp-2019.2.1-headers.zip_c5f7002a6c1dfda8aa2899e2594d01fe/frc/AnalogPotentiometer.h:14:0,
                 from C:\Storage\FRC\2019\Code\TestRobot.Mk1\build\tmp\expandedArchives\wpilibc-cpp-2019.2.1-headers.zip_c5f7002a6c1dfda8aa2899e2594d01fe/frc/WPILib.h:21,
                 from C:\Storage\FRC\2019\Code\TestRobot.Mk1\src\main\include/subsystems/LiftJoint1.h:3,
                 from C:\Storage\FRC\2019\Code\TestRobot.Mk1\src\main\cpp\subsystems\LiftJoint1.cpp:1:
C:\Storage\FRC\2019\Code\TestRobot.Mk1\build\tmp\expandedArchives\wpilibc-cpp-2019.2.1-headers.zip_c5f7002a6c1dfda8aa2899e2594d01fe/frc/interfaces/Potentiometer.h:17:7: note:   because the following virtual functions are pure within 'frc::Potentiometer':
 class Potentiometer : public PIDSource {
       ^~~~~~~~~~~~~
In file included from C:\Storage\FRC\2019\Code\TestRobot.Mk1\build\tmp\expandedArchives\wpilibc-cpp-2019.2.1-headers.zip_c5f7002a6c1dfda8aa2899e2594d01fe/frc/GyroBase.h:11:0,
                 from C:\Storage\FRC\2019\Code\TestRobot.Mk1\build\tmp\expandedArchives\wpilibc-cpp-2019.2.1-headers.zip_c5f7002a6c1dfda8aa2899e2594d01fe/frc/ADXRS450_Gyro.h:12,
                 from C:\Storage\FRC\2019\Code\TestRobot.Mk1\build\tmp\expandedArchives\wpilibc-cpp-2019.2.1-headers.zip_c5f7002a6c1dfda8aa2899e2594d01fe/frc/WPILib.h:16,
                 from C:\Storage\FRC\2019\Code\TestRobot.Mk1\src\main\include/subsystems/LiftJoint1.h:3,
                 from C:\Storage\FRC\2019\Code\TestRobot.Mk1\src\main\cpp\subsystems\LiftJoint1.cpp:1:
C:\Storage\FRC\2019\Code\TestRobot.Mk1\build\tmp\expandedArchives\wpilibc-cpp-2019.2.1-headers.zip_c5f7002a6c1dfda8aa2899e2594d01fe/frc/PIDSource.h:33:18: note:        virtual double frc::PIDSource::PIDGet()
   virtual double PIDGet() = 0;
                  ^~~~~~
In file included from C:\Storage\FRC\2019\Code\TestRobot.Mk1\build\tmp\expandedArchives\wpilibc-cpp-2019.2.1-headers.zip_c5f7002a6c1dfda8aa2899e2594d01fe/frc/AnalogPotentiometer.h:14:0,
                 from C:\Storage\FRC\2019\Code\TestRobot.Mk1\build\tmp\expandedArchives\wpilibc-cpp-2019.2.1-headers.zip_c5f7002a6c1dfda8aa2899e2594d01fe/frc/WPILib.h:21,
                 from C:\Storage\FRC\2019\Code\TestRobot.Mk1\src\main\include/subsystems/LiftJoint1.h:3,
                 from C:\Storage\FRC\2019\Code\TestRobot.Mk1\src\main\cpp\subsystems\LiftJoint1.cpp:1:
C:\Storage\FRC\2019\Code\TestRobot.Mk1\build\tmp\expandedArchives\wpilibc-cpp-2019.2.1-headers.zip_c5f7002a6c1dfda8aa2899e2594d01fe/frc/interfaces/Potentiometer.h:30:18: note:         virtual double frc::Potentiometer::Get() const
   virtual double Get() const = 0;
                  ^~~

Potentiometer is an interface. You should be using AnalogPotentiometer.

Edit: Sniped :slight_smile:

Potentiometer doesn’t have an implementation, you need to choose the actual WPILib class (like AnalogPotentiometer) instead.

I think I have suffered through one too many snow days… That was insanely simple to fix.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.