Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   Mechanum wheel programming in C++ (http://www.chiefdelphi.com/forums/showthread.php?t=88686)

Micah Chetrit 16-01-2011 13:24

Re: Mechanum wheel programming in C++
 
Ok, I am really new to C++, we are using the SimpleRobot class. can help me out by telling me what kind of a loop I put around it (MecanumDefaultCode.cpp) and some details like that. Do I need a .h file to go with it? What else do I need to add to make it work with the default sample code? by the way, does anyone know of a tutorial that explains how to use most/all of the WPI Library commands? I don't know how to use hardly any of them. this is my first year coding and all of the programmers graduated last year so I'm looking for any possible help.

CodeMonkeyMatt 16-01-2011 23:35

Re: Mechanum wheel programming in C++
 
Most likely, you would want to put the mecanum code inside of the "while(IsOperatorControl())" loop of the OperatorControl function of the SimpleRobot class. Also, I believe the code would change slightly as the SimpleRobot template uses different variable names, and does not use pointers. (I don't have our classmate in front of me, so someone correct my code if I'm mistaken)

Code:

while(IsOperatorControl())
{
myRobot.MecanumDrive_Cartesian(stick.GetX(), stick.GetY(), stick.GetTwist());
...

This is a good document for getting started in C++ and making sure that Windriver is properly set up (which you may or may not need).
http://firstforge.wpi.edu/sf/docman/...tation/doc1197

While I haven't looked through this very much yet, this should document most, if not all the WPILib classes with examples of using them. It is written for both Java and C++, so make sure you don't get the code mixed up.
http://firstforge.wpi.edu/sf/docman/...tation/doc1196

WillF 17-01-2011 17:19

Re: Mechanum wheel programming in C++
 
Quote:

Originally Posted by johncap100 (Post 996651)
so does one need only two joysticks or do you need to use 4 with two drivers. seems to me two joysticks would work. Did you find any brand or type better than another. I am looking at the Logitech Extreme 3D Pro. It has the 3 axis capability.

Our team used mecanum wheels with the Logitech Extreme 3D Pro joystick last year for Breakaway and it worked very well. Programming was a little tricky but on the whole that was offset by how quickly we could change directions with only one joystick. I highly recommend the single joystick solution.

tomy 17-01-2011 23:03

Re: Mechanum wheel programming in C++
 
Quote:

Originally Posted by Ether (Post 996108)
You take the commands from the joysticks and you process them (it's called inverse kinematics) to create the 4 wheel speeds.

The drive interface could be a single 3-axis joystick, or two 2-axis joysticks, or any other input device(s).

Mecanum has three completely independent degrees of freedom:

fore/aft
strafe (right/left)
rotate (turn, yaw)

A mecanum vehicle can perform all three of these motions simultaneously.


Here's some reference C code for you:

Code:

// 3-axis joystick interface to a mecanum drive

// define your driver interface,
// in this case a 3-axis joystick:

forward = -Y;
right = X;
clockwise = Z;

// put any drivability adjustments here for forward, right, and clockwise,
// for example gain, deadband, etc:

// if rotate gain is too hot, tweak it down:

clockwise /= 2; 

// add deadband so you don't get strafe when you don't want it:

if ((right>-0.1)&&(right<0.1)) right = 0;


// now apply the inverse kinematic tranformation:

front_left = forward + clockwise + right;
front_right = forward - clockwise - right;
rear_left = forward + clockwise - right;
rear_right = forward - clockwise + right;


// finally, normalize so that no wheel speed command
// exceeds magnitude of 1:

max = abs(front_left);
temp = abs(front_right);
if (temp>max) max = temp;
temp = abs(rear_left);
if (temp>max) max = temp;
temp = abs(rear_right);
if (temp>max) max = temp;

if (max>1)
  {front_left/=max; front_right/=max; rear_left/=max; rear_right/=max;}


// you're done. send these four wheel commands to their respective wheels

Questions? Fire away.


So with that code I can just pop it into my code and it should work or will it have to be modified.?

johncap100 18-01-2011 11:00

Re: Mechanum wheel programming in C++
 
So Joe I downloaded your code and am trying to get it to build in Windriver.
Sorry but myself and the kids are just getting familiar with Windriver. I opened it but it would build. Any suggestions?

thanks John

Quote:

Originally Posted by jhersh (Post 997653)
I've attached an example. It's based on the IterativeRobot base class but could be moved to SimpleRobot (by just putting a loop around the Drive method).



Nope. Just one Extreme 3D Pro.

-Joe


Ether 18-01-2011 11:12

Re: Mechanum wheel programming in C++
 
Quote:

Originally Posted by tomy (Post 1002490)
So with that code I can just pop it into my code and it should work ...?

That was not the intent; it is reference code. It lacks window dressing (variable declarations etc), and you need to decide whether or not you want to shape the joystick response curves (gain, deadband, etc). I recommend that you study and understand it, then tailor it for your specific application.



jyaple 23-01-2014 21:00

Re: Mechanum wheel programming in C++
 
Would you be able to program/run it with only a two axis joystick? My team wants to run this years bot as a CO-OP and have two joysticks with one Logictech controller for the shooter/loader system.

Ether 23-01-2014 22:09

Re: Mechanum wheel programming in C++
 
Quote:

Originally Posted by jyaple (Post 1331469)
Would you be able to program/run it with only a two axis joystick? My team wants to run this years bot as a CO-OP and have two joysticks with one Logictech controller for the shooter/loader system.

You can use whatever operator interface you like.

How are you planning to take advantage of the 3 degrees of freedom of a mec drivetrain using only one 2-axis joystick? Changing modes with a button perhaps??

WPILib has code for mecanum.



ekapalka 25-01-2014 10:09

Re: Mechanum wheel programming in C++
 
Quote:

Originally Posted by Ether (Post 996108)

Questions? Fire away.


What about field-centric? My team tried this out a few times but got really weird results. Would the following code snippet be correct?
Code:

[...] gyro->Reset(); float theta = gyro->GetAngle(); [...]

yVal2=(float) (yVal*Math.cos(theta) - xVal*Math.sin(theta));
xVal2=(float) (yVal*Math.sin(theta) + xVal*Math.cos(theta));

When we tried using this in our mecanum code method the robot could drive straight but would jitter and twitch if we tried to rotate it (like some robots do when their power draw exceeds the operating power of the motor controllers when your battery is low).

Ether 25-01-2014 10:57

Re: Mechanum wheel programming in C++
 
Quote:

Originally Posted by ekapalka (Post 1332061)
What about field-centric?

WPILib now has mecanum code, with field-centric option. Take a look at that (use just use it as-is).



2501Programmer 03-06-2014 18:11

Re: Mechanum wheel programming in C++
 
1 Attachment(s)
Our team uses SimpleRobot and here's our code for Mecanum/Omni drive using a 3 axis joystick (you may have to reverse some motors for it to work right and/or switch axis channels around)


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

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