Go to Post If you're a spectator that's going to complain about a "bad" call, you darn well better know for a FACT that the call was "bad". - AmyPrib [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

 
 
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 02-09-2011, 08:41 PM
~Cory~'s Avatar
~Cory~ ~Cory~ is offline
Student
AKA: Cory Rypkema
FRC #0706
Team Role: Alumni
 
Join Date: Jan 2010
Rookie Year: 2010
Location: Worcester MA
Posts: 216
~Cory~ is a splendid one to behold~Cory~ is a splendid one to behold~Cory~ is a splendid one to behold~Cory~ is a splendid one to behold~Cory~ is a splendid one to behold~Cory~ is a splendid one to behold~Cory~ is a splendid one to behold
Working CAN Jaguar [w/ Example Code]

We recently got CAN working on our test platform. I hope we can save all of the c++ teams a bit of time with this:

One Black Jaguar
Code:
#include "WPILib.h" //includes everything

/**
WORKING CAN JAGUAR - CYBERHAWKS 706
Built from simple template
 */ 
class RobotDemo : public SimpleRobot
{
	RobotDrive myRobot; // robot drive system, NOT USED
	Joystick stick; // only joystick
	CANJaguar jag;

public:
	RobotDemo(void):
		myRobot(3, 4),	// these must be initialized in the same order
		stick(1),		// as they are declared above.
		jag(1, CANJaguar::kSpeed)
		//jag(1)
	{
		myRobot.SetExpiration(0.1);
	}

	/**
	 * Drive left & right motors for 2 seconds then stop, NOT CAN
	 */
	void Autonomous(void)
	{
		myRobot.SetSafetyEnabled(false);
		myRobot.Drive(0.5, 0.0); 	// drive forwards half speed
		Wait(2.0); 				//    for 2 seconds
		myRobot.Drive(0.0, 0.0); 	// stop robot
	}

	/**
	 * Runs the motors with arcade steering. 
	 */
	void OperatorControl(void)
	{
//Set up CAN
		myRobot.SetSafetyEnabled(false);//on a dev board
		jag.SetPID(0.4, 0.005, 0.0);//PID
		jag.ConfigEncoderCodesPerRev(200);//This can change
		jag.SetSpeedReference(CANJaguar::kSpeedRef_Encoder);//NEED
		jag.EnableControl();//NEED
		
		DriverStationLCD *d_st = DriverStationLCD::GetInstance();//DS

		
		while (IsOperatorControl())
		{
			//myRobot.ArcadeDrive(stick); // simple template
			//jag.Set(20);
			jag.Set(stick.GetY()*150.0);//Set Jag


//The rest is DS output
			//printf("%f\n",stick.GetY());
			//printf("jag temp %f  speed %f  %f   %f  ref=%d\n",jag.GetTemperature(),
			//		jag.GetSpeed(),jag.GetOutputVoltage(),
			//		jag.GetOutputCurrent(), jag.GetSpeedReference());
			
			
			d_st->Printf(DriverStationLCD::kUser_Line1,1,"speed = %3.2f   ", jag.GetSpeed());
			d_st->Printf(DriverStationLCD::kUser_Line2,1,"set speed = %3.2f   ", stick.GetY()*150.0);
			d_st->Printf(DriverStationLCD::kUser_Line3,1,"current = %3.2f ", jag.GetOutputCurrent());
			d_st->UpdateLCD();
			Wait(0.005);				// wait for a motor update time
		}
	}
};

START_ROBOT_CLASS(RobotDemo);
Master/Slave:

Code:
#include "WPILib.h"


/**
 * CAN JAGUAR
 * Uses A master slave setup.  We are using 2CAN controller connected to the bridge.  The master jaguar has an encoder.  The slave does not.  The slave gets output from the master.
 */ 
class RobotDemo : public SimpleRobot
{
	//RobotDrive myRobot; //  drive system
	Joystick rightstick; // right joystick
	Joystick leftstick;// left joystick
	CANJaguar jag1; //Jaguars
	CANJaguar jag2;


public:
	RobotDemo(void):
//old my robot		//myRobot(3, 4),	// Reminants of Simple template
		rightstick(1),		//right stick
		leftstick(2),		//left stick
		//Declare CAN jaguar channels
		jag1(1, CANJaguar::kSpeed),//jag master left
		jag2(2, CANJaguar::kVoltage)//jag slave left
	{
		jag1.SetExpiration(0.1);
		jag2.SetExpiration(0.1);

	}


	void Autonomous(void)
	{
		//none
			
	}

	void OperatorControl(void)
	{
		//Jag 1 set up
		jag1.SetSafetyEnabled(false);//This is on a dev board
		jag1.SetPID(0.4, 0.005, 0.0);//PID
		jag1.ConfigEncoderCodesPerRev(200);//Changes per encoder
		jag1.SetSpeedReference(CANJaguar::kSpeedRef_Encoder);//This is on a dev board
		jag1.EnableControl();
		//jag 2 set up
		jag2.SetSafetyEnabled(false);//This is on a dev board
		jag2.EnableControl();
		
		//DS stuff
		DriverStationLCD *d_st = DriverStationLCD::GetInstance();

		
		while (IsOperatorControl())
		{
			jag1.Set(rightstick.GetY()*150.0);
			jag2.Set(jag1.GetOutputVoltage());
			//printf("%f\n",stick.GetY());
			//printf("jag temp %f  speed %f  %f   %f  ref=%d\n",jag.GetTemperature(),
			//		jag.GetSpeed(),jag.GetOutputVoltage(),
			//		jag.GetOutputCurrent(), jag.GetSpeedReference());
			d_st->Printf(DriverStationLCD::kUser_Line1,1,"speed = %3.2f   ", jag1.GetSpeed());
			d_st->Printf(DriverStationLCD::kUser_Line2,1,"set speed = %3.2f   ", rightstick.GetY()*150.0);
			d_st->Printf(DriverStationLCD::kUser_Line3,1,"current = %3.2f ", jag1.GetOutputCurrent());
			d_st->UpdateLCD();
			Wait(0.005);				// wait for a motor update time
		}
	}
};

START_ROBOT_CLASS(RobotDemo);
__________________
corin.rypkema.org
WPI Class of '17
'12 Dean's List Finalist, Mentor of 706 - Cyberhawks

Last edited by ~Cory~ : 02-09-2011 at 08:44 PM.
Reply With Quote
 


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 10:22 AM.

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