Go to Post You play your best, the refs do their best, and at the end of the day we are FIRST, collectively. - KenWittlief [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 31-01-2015, 19:40
1452-Leo 1452-Leo is offline
Registered User
FRC #1452 (Omnicats)
Team Role: Alumni
 
Join Date: Dec 2014
Rookie Year: 2014
Location: Los Angeles
Posts: 44
1452-Leo is an unknown quantity at this point
[C++] Use CAN Talons in RobotDrive

We are using CAN for the first time and after a few hours of learning how to do it, wiring, and formatting the Talons, our drive code didn't work. I tried controlling each motor individually and it works perfectly, but we would like to use RobotDrive because we are using Mecanum wheels with a gyro. Here is the non-working code:
Code:
class Robot: public SampleRobot {
	Joystick driveStick;
	CANTalon leftFront;
	CANTalon leftBack;
	CANTalon rightFront;
	CANTalon rightBack;
	RobotDrive drive;
	Gyro gyro;
public:
	Robot() :
		driveStick(1),
		leftFront(1),
		leftBack(5),
		rightFront(2),
		rightBack(6),
		drive(leftFront, leftBack, rightFront, rightBack),
		gyro(0)
{}
	void OperatorControl() {
		gyro.InitGyro();
		gyro.Reset();
		while (IsOperatorControl() && IsEnabled()) {
			drive.MecanumDrive_Cartesian(driveStick.GetX(),driveStick.GetY(),driveStick.GetThrottle(),gyro.GetAngle());
		}
	}
};
And here is the working code (I used tank drive to make it easier):
Code:
class Robot: public SampleRobot {
	Joystick driveStick;
	CANTalon leftFront;
	CANTalon leftBack;
	CANTalon rightFront;
	CANTalon rightBack;
	Gyro gyro;
public:
	Robot() :
		driveStick(1),
		leftFront(1),
		leftBack(5),
		rightFront(2),
		rightBack(6),
		gyro(0)
{}
	void OperatorControl() {
		gyro.InitGyro();
		gyro.Reset();
		while (IsOperatorControl() && IsEnabled()) {
			leftFront.Set(-driveStick.GetY());
			leftBack.Set(-driveStick.GetY());
			rightFront.Set(driveStick.GetThrottle());
			rightBack.Set(driveStick.GetThrottle());
		}
	}
};
Does anyone know why this doesn't work? Thanks!
  #2   Spotlight this post!  
Unread 31-01-2015, 19:53
viggy96 viggy96 is offline
Registered User
FRC #3331
Team Role: College Student
 
Join Date: Jan 2015
Rookie Year: 2010
Location: Charlotte
Posts: 54
viggy96 is infamous around these partsviggy96 is infamous around these parts
Re: [C++] Use CAN Talons in RobotDrive

Have you tried connecting the TalonSRXs via the PWM? That may alleviate your problem. Could also check if your TalonSRXs have the latest firmware.

Check here: http://crosstheroadelectronics.com/T...7s%20Guide.pdf

Last edited by viggy96 : 31-01-2015 at 20:05.
  #3   Spotlight this post!  
Unread 31-01-2015, 20:09
ozrien's Avatar
ozrien ozrien is offline
Omar Zrien
AKA: Omar
no team
Team Role: Mentor
 
Join Date: Sep 2006
Rookie Year: 2003
Location: Sterling Heights, MI
Posts: 522
ozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond repute
Re: [C++] Use CAN Talons in RobotDrive

Maybe grab the self test from the Rio web based configuration? Maybe its not in percent throttle mode. I don't have the implementation of robot drive in front of me but I think it just uses Set().
  #4   Spotlight this post!  
Unread 31-01-2015, 20:10
James Kuszmaul James Kuszmaul is offline
NEFIRST CSA
FRC #0971 (Spartan Robotics)
 
Join Date: Jan 2012
Rookie Year: 2011
Location: Worcester, MA
Posts: 61
James Kuszmaul has much to be proud ofJames Kuszmaul has much to be proud ofJames Kuszmaul has much to be proud ofJames Kuszmaul has much to be proud ofJames Kuszmaul has much to be proud ofJames Kuszmaul has much to be proud ofJames Kuszmaul has much to be proud ofJames Kuszmaul has much to be proud ofJames Kuszmaul has much to be proud ofJames Kuszmaul has much to be proud of
Re: [C++] Use CAN Talons in RobotDrive

What sort of problems are you encountering when you try to run the mecanum drive code? Does it simply not do anything at all, does it move the motors around but not in the way you expect, or something else? If the motors are running but the robot is responding how you expect, you should double check that everything is plugged into the right ports, that all the motors are turning the right direction, etc.
__________________
FRC971 (Student) 2011-2014
FRC190 (College Mentor-ish) 2014
WPILib Development 2014-present
  #5   Spotlight this post!  
Unread 31-01-2015, 20:28
1452-Leo 1452-Leo is offline
Registered User
FRC #1452 (Omnicats)
Team Role: Alumni
 
Join Date: Dec 2014
Rookie Year: 2014
Location: Los Angeles
Posts: 44
1452-Leo is an unknown quantity at this point
Re: [C++] Use CAN Talons in RobotDrive

Quote:
Originally Posted by viggy96 View Post
Have you tried connecting the TalonSRXs via the PWM? That may alleviate your problem. Could also check if your TalonSRXs have the latest firmware.

Check here: http://crosstheroadelectronics.com/T...7s%20Guide.pdf
I updated all the Talons to 1.4 (the newest I think) and we're trying to use CAN instead of PWM. Using PWM would involve soldering the CAN wires which we don't want to do just yet.

Quote:
Originally Posted by ozrien View Post
Maybe grab the self test from the Rio web based configuration? Maybe its not in percent throttle mode. I don't have the implementation of robot drive in front of me but I think it just uses Set().
I actually did do this earlier, but I had no idea what is means. When in drive, they are set to "No Drive" but otherwise set to "Throttle." This seems like it could be the problem if I knew more about it.

Quote:
Originally Posted by James Kuszmaul View Post
What sort of problems are you encountering when you try to run the mecanum drive code? Does it simply not do anything at all, does it move the motors around but not in the way you expect, or something else? If the motors are running but the robot is responding how you expect, you should double check that everything is plugged into the right ports, that all the motors are turning the right direction, etc.
Motors are not doing anything at all, but works fine when not using RobotDrive.
  #6   Spotlight this post!  
Unread 31-01-2015, 20:48
James Kuszmaul James Kuszmaul is offline
NEFIRST CSA
FRC #0971 (Spartan Robotics)
 
Join Date: Jan 2012
Rookie Year: 2011
Location: Worcester, MA
Posts: 61
James Kuszmaul has much to be proud ofJames Kuszmaul has much to be proud ofJames Kuszmaul has much to be proud ofJames Kuszmaul has much to be proud ofJames Kuszmaul has much to be proud ofJames Kuszmaul has much to be proud ofJames Kuszmaul has much to be proud ofJames Kuszmaul has much to be proud ofJames Kuszmaul has much to be proud ofJames Kuszmaul has much to be proud of
Re: [C++] Use CAN Talons in RobotDrive

try calling
robotDrive.SetSafetyEnabled(false);
before the while loop in OperatorControl.
Edit: actually, try calling that in the Robot() constructor. It's possible that the Talons are getting disabled before you start running the robot but that they aren't getting properly re-enabled.
__________________
FRC971 (Student) 2011-2014
FRC190 (College Mentor-ish) 2014
WPILib Development 2014-present

Last edited by James Kuszmaul : 31-01-2015 at 20:59.
  #7   Spotlight this post!  
Unread 31-01-2015, 20:54
1452-Leo 1452-Leo is offline
Registered User
FRC #1452 (Omnicats)
Team Role: Alumni
 
Join Date: Dec 2014
Rookie Year: 2014
Location: Los Angeles
Posts: 44
1452-Leo is an unknown quantity at this point
Re: [C++] Use CAN Talons in RobotDrive

Quote:
Originally Posted by James Kuszmaul View Post
try calling
robotDrive.SetSafetyEnabled(false);
before the while loop in OperatorControl.
I actually tried that earlier when I had some motor controllers set up wrong, but I forgot to try it again! I'll check back tomorrow and report if it worked or not.
  #8   Spotlight this post!  
Unread 31-01-2015, 20:57
ozrien's Avatar
ozrien ozrien is offline
Omar Zrien
AKA: Omar
no team
Team Role: Mentor
 
Join Date: Sep 2006
Rookie Year: 2003
Location: Sterling Heights, MI
Posts: 522
ozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond repute
Re: [C++] Use CAN Talons in RobotDrive

If you are seeing kNoDrive then most likely set is not being called. See software reference manual for more details.
  #9   Spotlight this post!  
Unread 31-01-2015, 21:12
1452-Leo 1452-Leo is offline
Registered User
FRC #1452 (Omnicats)
Team Role: Alumni
 
Join Date: Dec 2014
Rookie Year: 2014
Location: Los Angeles
Posts: 44
1452-Leo is an unknown quantity at this point
Re: [C++] Use CAN Talons in RobotDrive

Quote:
Originally Posted by ozrien View Post
If you are seeing kNoDrive then most likely set is not being called. See software reference manual for more details.
Can I just call Set() once at the beginning of teleop or is there something I have to change in RobotDrive? Unfortunately, I can't test until Monday.
  #10   Spotlight this post!  
Unread 31-01-2015, 22:48
TimTheGreat's Avatar
TimTheGreat TimTheGreat is offline
ArchdukeTim
FRC #1418 (Vae Victis)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2011
Location: Falls Church
Posts: 236
TimTheGreat has a spectacular aura aboutTimTheGreat has a spectacular aura aboutTimTheGreat has a spectacular aura about
Re: [C++] Use CAN Talons in RobotDrive

Are you calling Wait(.01) in your code? That may cause the code to do nothing.
__________________
There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.



2012 - Gracious Professionalism - Greater DC
2014 - Regional Finalist - Virginia | Industrial Design - Virginia | Regional Finalist - Greater DC
2015 - Innovation in Control - Greater DC
2016 - District Event Winner - VAHAY | Innovation in Control - VAHAY | District Event Winner - MDBET | Industrial Design - MDBET | District Champion - CHCMP | Innovation in Control - CHCMP
  #11   Spotlight this post!  
Unread 01-02-2015, 00:09
viggy96 viggy96 is offline
Registered User
FRC #3331
Team Role: College Student
 
Join Date: Jan 2015
Rookie Year: 2010
Location: Charlotte
Posts: 54
viggy96 is infamous around these partsviggy96 is infamous around these parts
Re: [C++] Use CAN Talons in RobotDrive

Could also try creating a new project. Sometimes projects get messed up. On the surface, it may not seem like it matters, but it could be worth a try.

I reccomend you switch from using the SampleRobot project to using IterativeRobot and try the code again.

Last edited by viggy96 : 01-02-2015 at 00:17.
  #12   Spotlight this post!  
Unread 01-02-2015, 00:45
viggy96 viggy96 is offline
Registered User
FRC #3331
Team Role: College Student
 
Join Date: Jan 2015
Rookie Year: 2010
Location: Charlotte
Posts: 54
viggy96 is infamous around these partsviggy96 is infamous around these parts
Re: [C++] Use CAN Talons in RobotDrive

This should work, but as I don't have a bot with TalonSRXs, I can't confirm this, but you could try it. I have used the IterativeRobot class.

Code:
class Robot: public IterativeRobot
{
private:
	LiveWindow *lw;

	CANTalon leftFront = new CANTalon(1);
	CANTalon leftBack = new CANTalon(5);
	CANTalon rightFront = new CANTalon(2);
	CANTalon rightBack = new CANTalon(6);

	RobotDrive drive = new RobotDrive(leftFront, leftBack, rightFront, rightBack);

	Joystick stick = new Joystick(1);

	Gyro gyro = new gyro(0);

	void RobotInit()
	{
		lw = LiveWindow::GetInstance();
	}

	void AutonomousInit()
	{

	}

	void AutonomousPeriodic()
	{

	}

	void TeleopInit()
	{

	}

	void TeleopPeriodic()
	{
		drive.MecanumDrive_Cartesian(stick.getX(), stick.getY(), stick.getThrottle(), gyro.getAngle());
	}

	void TestPeriodic()
	{
		lw->Run();
	}
};
  #13   Spotlight this post!  
Unread 01-02-2015, 16:29
1452-Leo 1452-Leo is offline
Registered User
FRC #1452 (Omnicats)
Team Role: Alumni
 
Join Date: Dec 2014
Rookie Year: 2014
Location: Los Angeles
Posts: 44
1452-Leo is an unknown quantity at this point
Re: [C++] Use CAN Talons in RobotDrive

Quote:
Originally Posted by viggy96 View Post
This should work, but as I don't have a bot with TalonSRXs, I can't confirm this, but you could try it. I have used the IterativeRobot class.
How would this be different than the code I started with? Iterative basically just adds a function to be called at the beginning, but doesn't really change what is actually going on in the program.
  #14   Spotlight this post!  
Unread 05-02-2015, 20:41
1452-Leo 1452-Leo is offline
Registered User
FRC #1452 (Omnicats)
Team Role: Alumni
 
Join Date: Dec 2014
Rookie Year: 2014
Location: Los Angeles
Posts: 44
1452-Leo is an unknown quantity at this point
Re: [C++] Use CAN Talons in RobotDrive

Ok I got it working! It's kind of an unusual workaround, but it works fine for us. Basically, create 4 fake motor controllers on unused PWM ports, and pass those to RobotDrive. From there, set the values of the real motor controllers to the values of the fake ones. Here is part of the code we used:
Code:
CANTalon *leftFront = new CANTalon(1); //Real ones
CANTalon *leftBack = new CANTalon(5);
CANTalon *rightFront = new CANTalon(2);
CANTalon *rightBack = new CANTalon(6);

TalonSRX *PWMlf = new TalonSRX(0); //Fake ones
TalonSRX *PWMlb = new TalonSRX(1);
TalonSRX *PWMrf = new TalonSRX(2);	
TalonSRX *PWMrb = new TalonSRX(3);	

void TeleopPeriodic()
{
	drive->MecanumDrive_Cartesian(driveStick->GetX(), driveStick->GetY(), driveStick->GetZ(), gyro->GetAngle());
	leftFront->Set(PWMlf->Get());
	leftBack->Set(PWMlb->Get());
	rightFront->Set(PWMrf->Get());
	rightBack->Set(PWMrb->Get());
}
  #15   Spotlight this post!  
Unread 05-02-2015, 21:27
ozrien's Avatar
ozrien ozrien is offline
Omar Zrien
AKA: Omar
no team
Team Role: Mentor
 
Join Date: Sep 2006
Rookie Year: 2003
Location: Sterling Heights, MI
Posts: 522
ozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond repute
Re: [C++] Use CAN Talons in RobotDrive

The problem looks like it's motor safety tripping. I reproduced the symptom with a similar project. Either the robot hits the motor safety trip once it boots up, or it fires during disable-to-enable transitions. When this happens the driver station will throw the MotorSafetyHelper assert (Section 16.14 in Talon SRX software reference manual), and the self-test will report "No-drive ".

I bet if you just called m_robotDrive->SetLeftRightMotorOutputs(0,0) in the disabled loop, that will keep feeding the motor safety object often enough to prevent your problem.

Or alternatively just TURN OFF the feature with...
m_robotDrive->SetSafetyEnabled(false)

Using dummy PWM objects seems like a drastic workaround.

Here's what I tested. If you comment out DisabledPeriodic(), you can reproduce the problem.

Code:
#include "WPILib.h"
class MecanumDefaultCode : public IterativeRobot
{
	CANTalon lf; /*left front */
	CANTalon lr;/*left rear */
	CANTalon rf; /*right front */
	CANTalon rr; /*right rear */
public:
	RobotDrive *m_robotDrive;		// RobotDrive object using PWM 1-4 for drive motors
	Joystick *m_driveStick;			// Joystick object on USB port 1 (mecanum drive)public:
	Gyro gyro;
	/**
	 * Constructor for this "MecanumDefaultCode" Class.
	 */
	MecanumDefaultCode(void) : lf(3), lr(1), rf(4), rr(5),  gyro(0)
	{
		// Create a RobotDrive object using PWMS 1, 2, 3, and 4
		m_robotDrive = new RobotDrive(lf, lr, rf, rr);

		/* alternatively you can disable safety features if you are not source-level debugging.
		 * uncomment this line to disable safety features. */
		//m_robotDrive->SetSafetyEnabled(false);

		// Define joystick being used at USB port #0 on the Drivers Station
		m_driveStick = new Joystick(0);
	}
	void TeleopInit()
	{
		gyro.Reset();
	}
	/** @return 10% deadband */
	double Db(double axisVal)
	{
		if(axisVal < -0.10)
			return axisVal;
		if(axisVal > +0.10)
			return axisVal;
		return 0;
	}

	void DisabledPeriodic(void)
	{
		/* while we are disabled, keep calling robotDrive's
		 * set routine to keep feeding the safety helper */
		m_robotDrive->SetLeftRightMotorOutputs(0,0);
	}
	/**
	 * Gets called once for each new packet from the DS.
	 */
	void TeleopPeriodic(void)
	{
		/* grab angle */
		float angle = gyro.GetAngle();

		/* printf for debugging - leave commented so it does affect performance. */
		//std::cout << "Angle : " << angle << std::endl;

		/* use angle with mec drive */
		m_robotDrive->MecanumDrive_Cartesian(	Db(m_driveStick->GetX()),
												Db(m_driveStick->GetY()),
												Db(m_driveStick->GetZ()),
												angle);

		/* my right side motors need to drive negative to move robot forward */
		m_robotDrive->SetInvertedMotor(RobotDrive::kFrontRightMotor,true);
		m_robotDrive->SetInvertedMotor(RobotDrive::kRearRightMotor,true);
	}
};
START_ROBOT_CLASS(MecanumDefaultCode);
Closed Thread


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 01:48.

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