Go to Post I think it will be very hard to find one aspect of FIRST which doesn't inspire us. - Arefin Bari [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 14-01-2017, 16:25
CSkillet CSkillet is offline
Registered User
FRC #0135
 
Join Date: Jan 2016
Location: Indiana
Posts: 11
CSkillet is an unknown quantity at this point
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
.cpp of the Subsystem
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.
.h of the Command
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
.cpp of the Command
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();
}
The following line in the .cpp of the command:
Code:
motor = new CANTalon(3);
gives the following error:
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 weird thing is, when I use an IterativeRobot Program instead of a CommandBased Robot Program, the Talon runs perfectly fine. That's why I'm assuming the problem is associated with CommandBased. It's the exact same code as the one in the CommandBased file, just in a different strcutire obviously.

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.
Reply With Quote
  #2   Spotlight this post!  
Unread 15-01-2017, 01:32
Thomas DeSilva's Avatar
Thomas DeSilva Thomas DeSilva is offline
Programming Fury
FRC #1983 (Skunkworks)
Team Role: Mentor
 
Join Date: Feb 2009
Rookie Year: 2009
Location: Des Moines, WA
Posts: 22
Thomas DeSilva is on a distinguished road
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.
__________________
Programmer 2009-2011
Driver 2011
WPI Class of 2015
Reply With Quote
  #3   Spotlight this post!  
Unread 15-01-2017, 14:32
CSkillet CSkillet is offline
Registered User
FRC #0135
 
Join Date: Jan 2016
Location: Indiana
Posts: 11
CSkillet is an unknown quantity at this point
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)
I did what you said and looked in the C/C++ build settings linker, and the CTRLib wasn't in there, so I added it. The build error with the TalonSRXLib only occurred after I installed the CTRE Toolsuite v4.4.1.9, which is the first version of the CTRE Toolsuite where they changed it from TalonSRXLib to CTRLib. I was able to find libCTRLib.a on my computer and included the file path for the CTRLib.

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]
This seems to be the only difference between the working IterativeRobot Program and the CommandBased Program in terms of build errors, deploying the robot code, and the driver station errors.

Also, I used <> instead of "" and the Driver Station error did not go away.
Reply With Quote
  #4   Spotlight this post!  
Unread 16-01-2017, 02:05
Thomas DeSilva's Avatar
Thomas DeSilva Thomas DeSilva is offline
Programming Fury
FRC #1983 (Skunkworks)
Team Role: Mentor
 
Join Date: Feb 2009
Rookie Year: 2009
Location: Des Moines, WA
Posts: 22
Thomas DeSilva is on a distinguished road
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?
__________________
Programmer 2009-2011
Driver 2011
WPI Class of 2015
Reply With Quote
  #5   Spotlight this post!  
Unread 16-01-2017, 02:54
CSkillet CSkillet is offline
Registered User
FRC #0135
 
Join Date: Jan 2016
Location: Indiana
Posts: 11
CSkillet is an unknown quantity at this point
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.
Reply With Quote
  #6   Spotlight this post!  
Unread 16-01-2017, 16:16
jlindquist74's Avatar
jlindquist74 jlindquist74 is offline
WOPR Software Integration Lead
FRC #1622
Team Role: Mentor
 
Join Date: Feb 2011
Rookie Year: 1337
Location: Poway, CA
Posts: 51
jlindquist74 has a brilliant futurejlindquist74 has a brilliant futurejlindquist74 has a brilliant futurejlindquist74 has a brilliant futurejlindquist74 has a brilliant futurejlindquist74 has a brilliant futurejlindquist74 has a brilliant futurejlindquist74 has a brilliant futurejlindquist74 has a brilliant futurejlindquist74 has a brilliant futurejlindquist74 has a brilliant future
Re: CTRE Toolsuite with Command-Based C++

Quote:
Originally Posted by Thomas DeSilva View Post
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
I strongly discourage our programming team from making any calls that might communicate with hardware in their constructors. To do so assumes that the "under the covers" initialization done by WPILib is complete and the hardware can be reached at the time the constructor executes. That's the kind of thing that worries me, "it may work today, but it may change in the next update.

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!
Reply With Quote
  #7   Spotlight this post!  
Unread 18-01-2017, 01:56
Thomas DeSilva's Avatar
Thomas DeSilva Thomas DeSilva is offline
Programming Fury
FRC #1983 (Skunkworks)
Team Role: Mentor
 
Join Date: Feb 2009
Rookie Year: 2009
Location: Des Moines, WA
Posts: 22
Thomas DeSilva is on a distinguished road
Re: CTRE Toolsuite with Command-Based C++

Quote:
Originally Posted by jlindquist74 View Post
I strongly discourage our programming team from making any calls that might communicate with hardware in their constructors. To do so assumes that the "under the covers" initialization done by WPILib is complete and the hardware can be reached at the time the constructor executes.
I agree. In this case, I was actually more worried about the EnableControl() call than the SetSafetyEnabled() call, but figured it was outside the scope of this question. You raise a good point, though.
__________________
Programmer 2009-2011
Driver 2011
WPI Class of 2015
Reply With Quote
  #8   Spotlight this post!  
Unread 18-01-2017, 21:24
CSkillet CSkillet is offline
Registered User
FRC #0135
 
Join Date: Jan 2016
Location: Indiana
Posts: 11
CSkillet is an unknown quantity at this point
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.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 13:31.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi