OCCRA
Go to Post You have to start at the bottom to get to the top, usually. - Kyle [more]
Home
Go Back   Chief Delphi > Technical > Programming > WindRiver C++
CD-Events   CD-Media   CD-Spy   FRC-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 02-28-2012, 04:45 PM
Unforgiven_Hero Unforgiven_Hero is offline
Registered User
FRC #1989
 
Join Date: Feb 2012
Location: Vernon
Posts: 11
Unforgiven_Hero is an unknown quantity at this point
Programming Mecanum Wheels - 4 Victors

Okay, so I've been working on testing my code on a practice bot and need help. I'm using an Attack 3 Joystick (I have 2 ) and a robot with 4 mecanum wheels, each with 4 victors.

Problem is: I have the sample code for a 2 motor robot and am having trouble creating a 4 motor drivetrain and using mecanum wheels.

I create the drive system by doing this:

RobotDrive *myRobot;
Joystick stick;

then

myRobot = new Robotdrive(1,2,3,4);
stick = new Joystick(1);

then under operator control I write,

myRobot->MecanumDrive_Cartesian(stick->GetX(),stick->GetY(),stick->
getTwist());

Except this isn't working. Do I need to declare something specific for the victors or logitech attack 3 joystick? And am I assigning the one joystick to control the whole robotdrive? I really need some help, anything would be appreciated at this point.

Thank you in advance!
Reply With Quote
  #2   Spotlight this post!  
Unread 02-28-2012, 11:23 PM
Fletch1373's Avatar
Fletch1373 Fletch1373 is offline
Registered User
AKA: Fletch
FRC #3555 (Aluminati)
Team Role: College Student
 
Join Date: Jan 2008
Rookie Year: 2004
Location: Connecticut
Posts: 226
Fletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud of
Send a message via AIM to Fletch1373 Send a message via MSN to Fletch1373 Send a message via Skype™ to Fletch1373
Re: Programming Mecanum Wheels - 4 Victors

just a couple things jumping out at me...
  1. Joystick stick should be declared as a pointer, like so:
    Code:
    Joystick *stick;
  2. The Attack3 joysticks do not have a 3rd(Twist) axis. In order to properly handle this, you could use a different joystick with a 3rd axis, use an axis(x or y) from a 2nd joystick, or wire up your own potentiometer or other device to read rotation.
__________________
<04: 213 - BAE> <05-08: 1373 - CT>
<09: 809 - PA> <09: CT - Inspector>
<10: 809 - VA> <10: WPI, BOS, CT, CMP - Inspector>
<11: CMP - Official Scorer> <11-12: 3555 - CT> <11-12: WPI - FTAA> <11-12: CT - Inspector>
<12: 73 - Mentor> <12: CMP - CSA>

Reply With Quote
  #3   Spotlight this post!  
Unread 02-29-2012, 05:00 AM
Unforgiven_Hero Unforgiven_Hero is offline
Registered User
FRC #1989
 
Join Date: Feb 2012
Location: Vernon
Posts: 11
Unforgiven_Hero is an unknown quantity at this point
Re: Programming Mecanum Wheels - 4 Victors

Okay thank you. Would I have to declare the Victors then too, or does WPI's API handle that? Thank you for any help.
Reply With Quote
  #4   Spotlight this post!  
Unread 02-29-2012, 12:09 PM
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 596
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: Programming Mecanum Wheels - 4 Victors

By default, the RobotDrive class will instantiate Jaguars as its motor controllers. If you are using Victors you need to explicitly instantiating them yourself and use the following constructor instead:
Code:
RobotDrive(SpeedController *frontLeftMotor,
           SpeedController *rearLeftMotor,
           SpeedController *frontRightMotor,
           SpeedController *rearRightMotor);
In other words:
Code:
class MyRobot: public SimpleRobot
{
    Victor leftFrontMotor;
    Victor leftRearMotor;
    Victor rightFrontMotor;
    Victor rightRearMotor;
    RobotDrive drive;
 
    MyRobot():
        leftFrontMotor(1),
        leftRearMotor(2),
        rightFrontMotor(3),
        rightRearMotor(4),
        drive(&leftFrontMotor, &leftRearMotor, &rightFrontMotor, &rightRearMotor)
    {
    }
    ....
}
__________________

Last edited by mikets : 02-29-2012 at 12:17 PM.
Reply With Quote
  #5   Spotlight this post!  
Unread 02-29-2012, 01:33 PM
Unforgiven_Hero Unforgiven_Hero is offline
Registered User
FRC #1989
 
Join Date: Feb 2012
Location: Vernon
Posts: 11
Unforgiven_Hero is an unknown quantity at this point
Re: Programming Mecanum Wheels - 4 Victors

Okay so here is where I stand, don't have a chance to test it on the practice bot today but will tomorrow. Anyone got any advice on the program and is there anything essential I should add or do to this program? Not totally sure how to do the twist part for the Mecanum wheels using an Attack3 joystick...

Here it is:

Code:
#include "WPILib.h"
class RobotDemo : public SimpleRobot
{
	RobotDrive *drive;
	
	Victor *leftFrontMotor;
	Victor *leftRearMotor;
	Victor *rightFrontMotor;
	Victor *rightRearMotor;
	
	Joystick *Attack1;
	Joystick *Attack2;
	
public:
	RobotDemo(void)
	{		
		drive = new RobotDrive(leftFrontMotor,leftRearMotor,rightFrontMotor,rightRearMotor);	
		Attack1 = new Joystick(1);		
		Attack2 = new Joystick(2);
		GetWatchdog().SetExpiration(0.1); 
		drive->SetExpiration(0.1);
	}
	void Autonomous(void)
	{
	}
	void OperatorControl(void)
	{
		GetWatchdog().SetEnabled(true);
		drive->SetSafetyEnabled(true);
		while (IsOperatorControl())
		{
			drive->MecanumDrive_Cartesian(Attack1->GetX(),Attack1->GetY(),Attack2->GetTwist());
			Wait(0.005);				
		}
	}
};

START_ROBOT_CLASS(RobotDemo);
Reply With Quote
  #6   Spotlight this post!  
Unread 02-29-2012, 01:40 PM
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 596
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: Programming Mecanum Wheels - 4 Victors

No, your code just declared four Victor pointers but you did not instantiate them. Regarding the Attack3 joystick, can't help you on that since I am not familiar with it.
Code:
#include "WPILib.h"
class RobotDemo : public SimpleRobot
{
    Victor *leftFrontMotor;
    Victor *leftRearMotor;
    Victor *rightFrontMotor;
    Victor *rightRearMotor;
    RobotDrive *drive;
 
    Joystick *Attack1;
    Joystick *Attack2;
 
public:
    RobotDemo(void)
    {
        leftFrontMotor = new Victor(1);
        leftRearMotor = new Victor(2);
        rightFrontMotor = new Victor(3);
        rightRearMotor = new Victor(4);
        drive = new RobotDrive(leftFrontMotor,leftRearMotor,rightFrontMotor,rightRearMotor);    
        Attack1 = new Joystick(1);        
        Attack2 = new Joystick(2);
        GetWatchdog().SetExpiration(0.1); 
        drive->SetExpiration(0.1);
    }
    void Autonomous(void)
    {
    }
    void OperatorControl(void)
    {
        GetWatchdog().SetEnabled(true);
        drive->SetSafetyEnabled(true);
        while (IsOperatorControl())
        {
            drive->MecanumDrive_Cartesian(Attack1->GetX(),Attack1->GetY(),Attack2->GetTwist());
            Wait(0.005);                
        }
    }
};
 
START_ROBOT_CLASS(RobotDemo);
__________________

Last edited by mikets : 02-29-2012 at 01:42 PM.
Reply With Quote
  #7   Spotlight this post!  
Unread 02-29-2012, 02:18 PM
Unforgiven_Hero Unforgiven_Hero is offline
Registered User
FRC #1989
 
Join Date: Feb 2012
Location: Vernon
Posts: 11
Unforgiven_Hero is an unknown quantity at this point
Re: Programming Mecanum Wheels - 4 Victors

Oh wait my bad - forgot to do that....thank you. And do you know if I should program anything to handle switching between operator control and autonomous - or will this program automatically handle that during competition?
Reply With Quote
  #8   Spotlight this post!  
Unread 02-29-2012, 03:28 PM
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 596
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: Programming Mecanum Wheels - 4 Victors

Quote:
Originally Posted by Unforgiven_Hero View Post
Oh wait my bad - forgot to do that....thank you. And do you know if I should program anything to handle switching between operator control and autonomous - or will this program automatically handle that during competition?
I am not sure if I understand your question. The Field Management System will dictate what mode (autonomous or teleop) the robot is in and will call either Autonomous or OperatorControl methods of your robot code. So you don't need to write any code to "switch mode". However, you do need to write code for both the Autonomous and OperatorControl functions.
__________________
Reply With Quote
  #9   Spotlight this post!  
Unread 02-29-2012, 03:33 PM
Unforgiven_Hero Unforgiven_Hero is offline
Registered User
FRC #1989
 
Join Date: Feb 2012
Location: Vernon
Posts: 11
Unforgiven_Hero is an unknown quantity at this point
Re: Programming Mecanum Wheels - 4 Victors

Ah, was just wondering how each part of the game is handled. And last question (I promise!) - if I have lets say a jaguar powering a belt that moves the ball, how could I go about programming that? I'm lost on how to control motors that does not involve the wheels.

Thank you in advance.
Reply With Quote
  #10   Spotlight this post!  
Unread 02-29-2012, 04:08 PM
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 596
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: Programming Mecanum Wheels - 4 Victors

Quote:
Originally Posted by Unforgiven_Hero View Post
if I have lets say a jaguar powering a belt that moves the ball, how could I go about programming that? I'm lost on how to control motors that does not involve the wheels.
How do you control the Jaguar? By PWM or by CAN bus. Let me assume you are using PWM. Then it would look something like this:
Code:
Jaguar *beltMotor;
...
beltMotor = new Jaguar(1);  //assuming PWM channel 1
...
beltMotor->Set(1.0);  //turning one way full speed
beltMotor->Set(-1.0); //turning the other way full speed
beltMotor->Set(0.0);  //stop
__________________
Reply With Quote
  #11   Spotlight this post!  
Unread 02-29-2012, 05:00 PM
Unforgiven_Hero Unforgiven_Hero is offline
Registered User
FRC #1989
 
Join Date: Feb 2012
Location: Vernon
Posts: 11
Unforgiven_Hero is an unknown quantity at this point
Re: Programming Mecanum Wheels - 4 Victors

Okay thank you!
Reply With Quote
  #12   Spotlight this post!  
Unread 02-29-2012, 10:16 PM
Fletch1373's Avatar
Fletch1373 Fletch1373 is offline
Registered User
AKA: Fletch
FRC #3555 (Aluminati)
Team Role: College Student
 
Join Date: Jan 2008
Rookie Year: 2004
Location: Connecticut
Posts: 226
Fletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud of
Send a message via AIM to Fletch1373 Send a message via MSN to Fletch1373 Send a message via Skype™ to Fletch1373
Re: Programming Mecanum Wheels - 4 Victors

Quote:
Originally Posted by Unforgiven_Hero View Post
Okay so here is where I stand, don't have a chance to test it on the practice bot today but will tomorrow. Anyone got any advice on the program and is there anything essential I should add or do to this program? Not totally sure how to do the twist part for the Mecanum wheels using an Attack3 joystick...

Here it is:
You require the second joystick because each Attack3 only has 2 axes, but you need 3. So you will use the X- and Y-axis of Attack1 for moving straight(front/back and sideways), and the X-axis of Attack2 to do rotation. the getTwist method does nothing with Attack3 joysticks because they don't have the 3rd(or Twist) axis.

Code:
	void OperatorControl(void)
	{
		GetWatchdog().SetEnabled(true);
		drive->SetSafetyEnabled(true);
		while (IsOperatorControl())
		{
			drive->MecanumDrive_Cartesian(Attack1->GetX(),Attack1->GetY(),Attack2->GetX());
			Wait(0.005);				
		}
	}
__________________
<04: 213 - BAE> <05-08: 1373 - CT>
<09: 809 - PA> <09: CT - Inspector>
<10: 809 - VA> <10: WPI, BOS, CT, CMP - Inspector>
<11: CMP - Official Scorer> <11-12: 3555 - CT> <11-12: WPI - FTAA> <11-12: CT - Inspector>
<12: 73 - Mentor> <12: CMP - CSA>

Reply With Quote
  #13   Spotlight this post!  
Unread 03-04-2012, 03:36 PM
Unforgiven_Hero Unforgiven_Hero is offline
Registered User
FRC #1989
 
Join Date: Feb 2012
Location: Vernon
Posts: 11
Unforgiven_Hero is an unknown quantity at this point
Re: Programming Mecanum Wheels - 4 Victors

Alright, thank you! However, I was sure everything was ready to go but now im getting a watchdog not fed error. I feed the watchdog but its not working. Does anyone know how to fix this?

Code:
#include "WPILib.h"
class RobotDemo : public SimpleRobot
{	
    Victor *leftFrontMotor;
    Victor *leftRearMotor;
    Victor *rightFrontMotor;
    Victor *rightRearMotor;

    RobotDrive *drive; // Drive system for the robot
 
    Joystick *Attack1; // Plugged into USB port 1
    Joystick *Attack2; // Plugged into USB port 2
    
    Jaguar *beltMotor; // Slides the cart for the basketballs
    Jaguar *angleMotor; // Changes the angle for the basketball shooter
    Jaguar *bshooter; // Moves the belt to shoot the basketball (Must be able to go forward and backward)

public:
    RobotDemo(void)
    {

    	//Initialize the four Victors to power the Mecanum wheels
    	leftFrontMotor = new Victor(1); 
        leftRearMotor = new Victor(2);
        rightFrontMotor = new Victor(3);
        rightRearMotor = new Victor(4);

        //Initialize the drive system
        drive = new RobotDrive(leftFrontMotor,leftRearMotor,rightFrontMotor,rightRearMotor);  

        //Initialize the two joysticks used to control the robot
        //Define joysticks being used at USB port #1 and USB port #2 on the Driver's Station
        Attack1 = new Joystick(1);        
        Attack2 = new Joystick(2);

        //Initialize Jaguars for the various Robot's functions
        beltMotor = new Jaguar(5);
        angleMotor = new Jaguar(6);
        bshooter = new Jaguar(7);

        
        Watchdog().SetExpiration(0.1);
        drive->SetExpiration(0.1);
        drive->SetSafetyEnabled(false);

        printf("Object Initialization is a success!");
    }

    void Autonomous(void)
    {
    	while (IsAutonomous() && IsEnabled()) {
    		Watchdog().SetEnabled(false);
    	}
    }
    void OperatorControl(void)
    {
    	//Enable Watchdog  which is responsible for handling robot failure
    	Watchdog().SetEnabled(true);
        drive->SetSafetyEnabled(true);

        //Enter the loop where robot can be controlled manually

        while (IsOperatorControl())
        {
        	Watchdog().Feed();
        	printf("The Operator Controlled period has begun!");
            //Use Attack3 joysticks to drive the robot 
            drive->MecanumDrive_Cartesian(Attack1->GetX(),Attack1->GetY(),Attack2->GetX());
            Wait(0.001);                
        }
    }
}; 
START_ROBOT_CLASS(RobotDemo);
Reply With Quote
  #14   Spotlight this post!  
Unread 03-05-2012, 02:12 PM
Unforgiven_Hero Unforgiven_Hero is offline
Registered User
FRC #1989
 
Join Date: Feb 2012
Location: Vernon
Posts: 11
Unforgiven_Hero is an unknown quantity at this point
Re: Programming Mecanum Wheels - 4 Victors

Anyone know how to fix this watchdog not fed error? I really need help badly right now and have spent 2 hours trying to figure it out...
Reply With Quote
  #15   Spotlight this post!  
Unread 03-05-2012, 03:02 PM
wireties's Avatar
wireties wireties is offline
Principal Engineer
AKA: Keith Buchanan
FRC #1296 (Full Metal Jackets)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2004
Location: Rockwall, TX
Posts: 797
wireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond repute
Send a message via AIM to wireties
Re: Programming Mecanum Wheels - 4 Victors

Quote:
Originally Posted by Unforgiven_Hero View Post
Anyone know how to fix this watchdog not fed error? I really need help badly right now and have spent 2 hours trying to figure it out...

Move the printf function outside the while loop, right now it gets called so often it might screw up the timing.

HTH
__________________
Fast, cheap or working - pick any two!
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 02:27 PM.

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


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