|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
CTRE Toolsuite with Command-Based C++
Hello,
I have been having an issue with using CANTalon.h class from the CTRE Toolsuite. I have been trying to run Talon Motor Controllers with a C++ Command-Based program and am having no luck. My current setup has a PDP powered by a 12V battery. The PDP is powering both the RoboRIO and the Talon Motor Controller. I then have the CANBus going from the Talon to (1) one set of wires to the RoboRIO and (2) one set of wires to the PDP. I have tried using both a wired ans wireless connection. I am using the following code to run the Talons: .h of the subsystem: Code:
#ifndef Motor_H
#define Motor_H
#include <Commands/Subsystem.h>
#include "CANTalon.h"
class Motor : public Subsystem {
private:
// It's desirable that everything possible under private except
// for methods that implement subsystem capabilities
CANTalon* motor;
public:
Motor();
void InitDefaultCommand();
void DriveMotor(float);
void StopMotor();
};
#endif // Motor_H
Code:
#include "Motor.h"
#include "../RobotMap.h"
#include "Commands/TestingMotor.h"
Motor::Motor() : Subsystem("Motor") {
motor = new CANTalon(3);
motor->EnableControl();
motor->SetControlMode(CANTalon::ControlMode::kPercentVbus);
motor->SetSafetyEnabled(false);
motor->Set(0);
}
void Motor::InitDefaultCommand() {
// Set the default command for a subsystem here.
// SetDefaultCommand(new MySpecialCommand());
SetDefaultCommand(new TestingMotor());
}
void Motor::DriveMotor(float motorPower) {
motor->Set(motorPower);
}
void Motor::StopMotor() {
motor->Set(0);
}
// Put methods for controlling this subsystem
// here. Call these from Commands.
Code:
#ifndef TestingMotor_H
#define TestingMotor_H
#include "../CommandBase.h"
class TestingMotor : public CommandBase {
public:
TestingMotor();
void Initialize();
void Execute();
bool IsFinished();
void End();
void Interrupted();
};
#endif // TestingMotor_H
Code:
#include "TestingMotor.h"
TestingMotor::TestingMotor() {
// Use Requires() here to declare subsystem dependencies
// eg. Requires(Robot::chassis.get());
Requires(motor.get());
}
// Called just before this Command runs the first time
void TestingMotor::Initialize() {
}
// Called repeatedly when this Command is scheduled to run
void TestingMotor::Execute() {
motor->DriveMotor(.75f);
}
// Make this return true when this Command no longer needs to run execute()
bool TestingMotor::IsFinished() {
return false;
}
// Called once after isFinished returns true
void TestingMotor::End() {
motor->StopMotor();
}
// Called when another command which requires one or more of the same
// subsystems is scheduled to run
void TestingMotor::Interrupted() {
End();
}
Code:
motor = new CANTalon(3); Undefined Reference to CANTalon::CANTalon(int) I have v4.4.1.9 of the CTRE Toolsuite installed on my computer. There has been no error associated with #include "CANTalon.h". There also has been no problems with the other functions of the CANTalon class I've been using: Code:
motor->EnableControl(); motor->SetControlMode(CANTalon::ControlMode::kPercentVbus); motor->SetSafetyEnabled(false); motor->Set(0); The Talons are always flashing orange, which mean the robot detects the CANBus and is disabled. When we enable the robot from the Driver Station, the lights are still flashing orange. Furthermore, the NI-Web Based Software shows the mode of the Talon in Mode 0: Throttle (Duty Cycle) when it is enabled. We are able to control the Talons from the RoboRIO because we were able to update the firmware of them. We have tested multiple Talons, and neither of them have worked. The PDP has firmware version 1.40 and its lights are flashing green, so there isn't a problem with that. Sometimes, that error goes away when we build Eclipse, and when we upload the code to the RoboRIO, we received the following error from the Driver Station: ERROR -52010 NIFPGA: Resource Not Initialized GetFPGATime [Utility.cpp:171] We assumed this error was a result of the CANTalon pointer motor not being defined because of the error it has received before. Another time, we built the code and we received the following build error from Eclipse: c:/frc/bin/../lib/gcc/arm-frc-linux-gnueabi/4.9.3/../../../../arm-frc-linux-gnueabi/bin/ld.exe: cannot find -lTalonSRXLib We were wondering if anyone is receiving the same problem and if anyone knows how to solve the issue we are having. |
|
#2
|
||||
|
||||
|
Re: CTRE Toolsuite with Command-Based C++
Could you post the full compiler output from when it fails? You can find this by opening the "Console" window in Eclipse. There are a number of things that can lead to you seeing an undefined reference error that we may see earlier in the output. I notice that your include for CANTalon.h uses quotes instead of angle brackets*, which could do it, but we would also see an error complaining that the included file wasn't found if this was the case.
The linker error you ran into ("c:/frc/bin/../lib/gcc/arm-frc-linux-gnueabi/4.9.3/../../../../arm-frc-linux-gnueabi/bin/ld.exe: cannot find -lTalonSRXLib") seems a little strange. I think the CTRE library in the current version of the toolsuite is called CTRLib, not TalonSRXLib. I may be completely off-base here, but are you using the 2017 version of WPILib, or an older one? Nonetheless, you should make sure that your include paths are set up correctly. In Eclipse, go into your C/C++ build settings for the project and take a look at the "Libraries" subsection for the linker. Is there a file called "libTalonSRXLib.so" or "libTalonSRXLib.a" at any of the paths in the "Library search path" section? If not, you need to find where that file actually exists on your machine and add the path here. If you don't have that file, you should probably change the library to be CTRLib instead of TalonSRXLib and give it the path to that instead. * Using quotes in an include makes the compiler check the relative path instead of the include path for the file, so it won't work here unless CANTalon.h happens to be at the given location relative to Motor.h, i.e. in the same directory. |
|
#3
|
|||
|
|||
|
Re: CTRE Toolsuite with Command-Based C++
Here is the build for the Command Based code that isn't working:
Code:
14:24:46 **** Incremental Build of configuration Debug for project 2017Code **** Info: Internal Builder is used for build arm-frc-linux-gnueabi-g++ -std=c++1y "-IC:\\Users\\Robotics/wpilib/cpp/current/include" "-IC:\\Users\\Robotics\\git\\2017Code\\2017Code\\src" "-IC:\\Users\\Robotics/wpilib/user/cpp/include" -O0 -Og -g3 -Wall -c -fmessage-length=0 -o "src\\CommandBase.o" "..\\src\\CommandBase.cpp" arm-frc-linux-gnueabi-g++ -std=c++1y "-IC:\\Users\\Robotics/wpilib/cpp/current/include" "-IC:\\Users\\Robotics\\git\\2017Code\\2017Code\\src" "-IC:\\Users\\Robotics/wpilib/user/cpp/include" -O0 -Og -g3 -Wall -c -fmessage-length=0 -o "src\\Subsystems\\ExampleSubsystem.o" "..\\src\\Subsystems\\ExampleSubsystem.cpp" arm-frc-linux-gnueabi-g++ -std=c++1y "-IC:\\Users\\Robotics/wpilib/cpp/current/include" "-IC:\\Users\\Robotics\\git\\2017Code\\2017Code\\src" "-IC:\\Users\\Robotics/wpilib/user/cpp/include" -O0 -Og -g3 -Wall -c -fmessage-length=0 -o "src\\Commands\\ExampleCommand.o" "..\\src\\Commands\\ExampleCommand.cpp" arm-frc-linux-gnueabi-g++ -std=c++1y "-IC:\\Users\\Robotics/wpilib/cpp/current/include" "-IC:\\Users\\Robotics\\git\\2017Code\\2017Code\\src" "-IC:\\Users\\Robotics/wpilib/user/cpp/include" -O0 -Og -g3 -Wall -c -fmessage-length=0 -o "src\\Robot.o" "..\\src\\Robot.cpp" arm-frc-linux-gnueabi-g++ "-LC:\\Users\\Robotics/wpilib/cpp/current/lib" "-LC:\\Users\\Robotics/wpilib/user/cpp/lib" -Wl,-rpath,/opt/GenICam_v3_0_NI/bin/Linux32_ARM -o FRCUserProgram "src\\CommandBase.o" "src\\Commands\\ExampleCommand.o" "src\\OI.o" "src\\Robot.o" "src\\Subsystems\\ExampleSubsystem.o" -lCTRLib -lwpi 14:24:59 Build Finished (took 13s.113ms) After I did this, the undefined reference for CANTalon::CANTalon(int) does not appear anymore. The only error that occurs now is the Driver Station one: Code:
ERROR -52010 NIFPGA: Resource not initialized GetFPGATime [Utility.cpp:171] Error at GetFPGATime [Utility.cpp:171]: NIFPGA: Resource not initialized at frc::GetFPGATime() at frc::Timer::GetFPGATimestamp() at frc::MotorSafetyHelper::MotorSafetyHelper(frc::MotorSafety*) at /home/lvuser/FRCUserProgram() [0x20fac] at /home/lvuser/FRCUserProgram() [0x16aac] at /home/lvuser/FRCUserProgram() [0x14018] at /home/lvuser/FRCUserProgram() [0x140c8] Also, I used <> instead of "" and the Driver Station error did not go away. |
|
#4
|
||||
|
||||
|
Re: CTRE Toolsuite with Command-Based C++
Your compiler output actually indicates that the build was successful. Important takeaway here: sometimes Eclipse gets it wrong. If it's giving you an error that doesn't make much sense, always check the console to verify that it's real and not just Eclipse being Eclipse.
The error showing up in the driver station log isn't directly related to the other problem you were having. The error says that MotorSafetyHelper is trying to check the FPGA time before the FPGA is initialized, which may be because you're calling CANTalon::SetSafetyEnabled() in the constructor for your subsystem. It may help to move that call to a later point in time, but I don't know how it works under the covers and I haven't seen the rest of your code, so I can't say for sure--maybe one of WPILib's maintainers could chime in on this. I don't think that should be blocking you, though; is your command running now? |
|
#5
|
|||
|
|||
|
Re: CTRE Toolsuite with Command-Based C++
No, that did not work unfortunately, I will see if maybe there is a way to either stop those functions from Timer and MotorSafetyControl to stop running before the initialize. But it doesn't make any sense because I'm not using timers at all.
|
|
#6
|
||||
|
||||
|
Re: CTRE Toolsuite with Command-Based C++
Quote:
I advise them to put those calls in the Init methods. By the time the Init()s are called, the hardware *must* be configured for our use. (Otherwise, what's the point?) If you give that a try, or if you find another solution, would you please let us know how it goes? Your experience will surely be helpful to other teams! |
|
#7
|
||||
|
||||
|
Re: CTRE Toolsuite with Command-Based C++
Quote:
|
|
#8
|
|||
|
|||
|
Re: CTRE Toolsuite with Command-Based C++
I have moved all the functions associated with the Configuration of the Talon not into the constuctor if the subsystem, but of the Initialize() of the Command. However, this has not seemed to change anything in terms of the errors we are receiving.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|