Go to Post I understand that I'm in the minority when it comes to these things, so when the coverage switches to one these stories I exercise my right to change the channel. - Karthik [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

 
Reply
Thread Tools Rating: Thread Rating: 4 votes, 4.75 average. Display Modes
  #16   Spotlight this post!  
Unread 16-01-2011, 13:24
Micah Chetrit's Avatar
Micah Chetrit Micah Chetrit is offline
Registered User
FRC #3276 (NSR)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2010
Location: New London - Spicer MN
Posts: 90
Micah Chetrit is on a distinguished road
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.
Reply With Quote
  #17   Spotlight this post!  
Unread 16-01-2011, 23:35
CodeMonkeyMatt CodeMonkeyMatt is offline
Registered User
FRC #2605
 
Join Date: Jan 2011
Rookie Year: 2008
Location: WA
Posts: 46
CodeMonkeyMatt is on a distinguished road
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
Reply With Quote
  #18   Spotlight this post!  
Unread 17-01-2011, 17:19
WillF WillF is offline
Team Captain
FRC #2945 (B.A.N.G (Bolts and Nuts Gang))
Team Role: Leadership
 
Join Date: Jan 2011
Rookie Year: 2009
Location: Manitou Springs, CO
Posts: 12
WillF is an unknown quantity at this point
Re: Mechanum wheel programming in C++

Quote:
Originally Posted by johncap100 View Post
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.
Reply With Quote
  #19   Spotlight this post!  
Unread 17-01-2011, 23:03
tomy tomy is offline
Registered User
FRC #3038 (I.C.E. Robotics)
Team Role: Mentor
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Stacy, Minnesota
Posts: 494
tomy has a spectacular aura abouttomy has a spectacular aura about
Re: Mechanum wheel programming in C++

Quote:
Originally Posted by Ether View Post
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.?
Reply With Quote
  #20   Spotlight this post!  
Unread 18-01-2011, 11:00
johncap100 johncap100 is offline
Registered User
FTC #0658
 
Join Date: Aug 2009
Location: Capital High School
Posts: 95
johncap100 is an unknown quantity at this point
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 View Post
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
Reply With Quote
  #21   Spotlight this post!  
Unread 18-01-2011, 11:12
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,044
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Mechanum wheel programming in C++

Quote:
Originally Posted by tomy View Post
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.



Last edited by Ether : 18-01-2011 at 11:14.
Reply With Quote
  #22   Spotlight this post!  
Unread 23-01-2014, 21:00
jyaple's Avatar
jyaple jyaple is offline
Registered User
FRC #1013
 
Join Date: Jan 2013
Location: Arizona
Posts: 10
jyaple is an unknown quantity at this point
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.
__________________
Tin Man~
Reply With Quote
  #23   Spotlight this post!  
Unread 23-01-2014, 22:09
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,044
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Mechanum wheel programming in C++

Quote:
Originally Posted by jyaple View Post
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.


Reply With Quote
  #24   Spotlight this post!  
Unread 25-01-2014, 10:09
ekapalka's Avatar
ekapalka ekapalka is offline
Registered User
FRC #3216
 
Join Date: Dec 2012
Location: Bermuda
Posts: 277
ekapalka has a spectacular aura aboutekapalka has a spectacular aura about
Re: Mechanum wheel programming in C++

Quote:
Originally Posted by Ether View Post

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).
Reply With Quote
  #25   Spotlight this post!  
Unread 25-01-2014, 10:57
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,044
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Mechanum wheel programming in C++

Quote:
Originally Posted by ekapalka View Post
What about field-centric?
WPILib now has mecanum code, with field-centric option. Take a look at that (use just use it as-is).


Reply With Quote
  #26   Spotlight this post!  
Unread 03-06-2014, 18:11
2501Programmer 2501Programmer is offline
Registered User
FRC #2501
 
Join Date: Jun 2014
Location: North St. Paul
Posts: 1
2501Programmer is an unknown quantity at this point
Re: Mechanum wheel programming in C++

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)
Attached Files
File Type: cpp MyRobot.cpp (3.2 KB, 19 views)
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 13:23.

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