Thread: windriver c++?
View Single Post
  #2   Spotlight this post!  
Unread 06-01-2010, 08:52
EHaskins EHaskins is offline
Needs to change his user title.
AKA: Eric Haskins
no team (CARD #6 (SCOE))
Team Role: College Student
 
Join Date: Jan 2006
Rookie Year: 2006
Location: Elkhorn, WI USA
Posts: 998
EHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond repute
Send a message via MSN to EHaskins
Re: windriver c++?

Quote:
Originally Posted by yara92 View Post
hello Eric

Thank you for your help we were able to insert the code you sent us into RobotDemo however we are not sure if the mecanum wheels are fully doing all the right moves (it works fine in all direction except to the sides) we think that it could be a problem with not having a gray area specified ?!!!
Let us know what you think!!
the code,
Code:
#include "WPILib.h"

/**
 * This is a demo program showing the use of the RobotBase class.
 * The SimpleRobot class is the base of a robot application that will automatically call your
 * Autonomous and OperatorControl methods at the right time as controlled by the switches on
 * the driver station or the field controls.
 */ 
class RobotDemo : public SimpleRobot
{
	RobotDrive myRobot; // robot drive system
	Joystick stick; // only joystick 
	{
	public:
		typedef enum
		{
			kFrontLeftMotor = 0,
			kFrontRightMotor = 1,
			kRearLeftMotor = 2,
			kRearRightMotor = 3
		} MotorType;
public:
	RobotDemo(void):
		myRobot(1, 2, 3, 4),	// these must be initialized in the same order
		stick(1)		// as they are declared above.


	{
		GetWatchdog().SetExpiration(0.1);
	}

	/**
	 * Drive left & right motors for 2 seconds then stop
	 */
	void Autonomous(void)
	{
		GetWatchdog().SetEnabled(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)
	{
		GetWatchdog().SetEnabled(true);
		while (IsOperatorControl())
		{
			GetWatchdog().Feed();
			myRobot.ArcadeDrive(stick); // drive with arcade style (use right stick)
			Wait(0.005);				// wait for a motor update time
		}
		//INSERT IN: TeleopPeriodic or main loop
		float slide = m_leftStick->GetZ(); // was X
		float forward = m_leftStick->GetY(); // was Y
		float spin = m_leftStick->GetX(); // was Z
					
		forward *= -1;
		slide *= -1;
		float FrontLeft = forward + slide + spin;
		float FrontRight = forward - slide - spin;
		float RearLeft = forward - slide + spin;
		float RearRight = forward + slide - spin;
					
		FrontRight *= -1;
		KFrontLeftMotor->Set(FrontLeft);
		KFrontRightMotor->Set(FrontRight);
		KRearLeftMotor->Set(RearLeft);
		KRearRigtMotor->Set(RearRigt);
	}
};

START_ROBOT_CLASS(RobotDemo);

ps open the attachment
Thank you again
from
1946 programming team
When you say it doesn't work sideways what do you mean? Does it do nothing? Does it spin/go forward? Something else?

If you're not sure replace the joystick mapping code with the following, then support the robot with its wheels in the air, and report how each wheel is moving.

Then move the constant to each of the other values in turn, and post the result. This will confirm motor mappings, and wiring to the motors.

Code:
	float X = 0.2;
	float Y = 0.0;
	float Z= 0.0;
In any case, see the code above (changes bold) for cliarification of the variable names. Also those joystick mappings are for Logictech PS2 controller clone. If you are using the KOP joysticks or other traditional joysticks you will need to modify the mappings.

I assure you no additional code is necessary for a basic mecanum drive. I've used that piece of code many times.
__________________
Eric Haskins KC9JVH

Last edited by EHaskins : 06-01-2010 at 08:54.
Reply With Quote