Go to Post If they need a place where they can get a chance to learn interpersonal skills (like a team), it might just help them to become well-adjusted adults, as opposed to pathologically antisocial engineers (who got good grades). - Tristan Lall [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 09-05-2005, 20:00
mattsavela mattsavela is offline
Registered User
FRC #0255
 
Join Date: May 2005
Location: Lamphere
Posts: 12
mattsavela is an unknown quantity at this point
One Joystick Drive

Hey. My team is interested in one joystick drive. We have the code loaded into our robot, but it needs some tweaking. For example, when we turn right, we want the left motor to go slower than the right motor. How would we add this into our program? Any help is greatly appreciated.
  #2   Spotlight this post!  
Unread 09-05-2005, 21:07
Mark McLeod's Avatar
Mark McLeod Mark McLeod is offline
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,695
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: One Joystick Drive

The IFI default code does the axis mixing for you with this section of code in user_routines.c depending on how your motors are hooked up (both forward or one forward, the other reverse).
Code:
/*---------- 1 Joystick Drive ----------------------------------------------
*--------------------------------------------------------------------------
* This code mixes the Y and X axis on Port 1 to allow one joystick drive. 
* Joystick forward = Robot forward
* Joystick backward = Robot backward
* Joystick right	= Robot rotates right
* Joystick left	 = Robot rotates left
* Connect the right drive motors to PWM13 and/or PWM14 on the RC.
* Connect the left drive motors to PWM15 and/or PWM16 on the RC.
*/ 
pwm13 = pwm14 = Limit_Mix(2000 + p1_y + p1_x - 127);
pwm15 = pwm16 = Limit_Mix(2000 + p1_y - p1_x + 127);
However, I might not quite comprehend what you are asking, since if you make the left motor go slower than the right motor, the robot will only turn to the right by rotating counter-clockwise (what I'd normally consider turning to the left). If this is the case you could invert the x axis of the joystick prior to mixing, e.g., p1_x=254-p1_x;
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle

Last edited by Mark McLeod : 09-05-2005 at 21:20.
  #3   Spotlight this post!  
Unread 09-05-2005, 23:06
mattsavela mattsavela is offline
Registered User
FRC #0255
 
Join Date: May 2005
Location: Lamphere
Posts: 12
mattsavela is an unknown quantity at this point
Re: One Joystick Drive

We are using our IFI Controller for an underwater robotics competition. We want to use one joystick drive for many reasons. I loaded the code in at our meeting today and it seemed to work fine. We haven't tested it in the pool yet. One of the students on the team were saying something about how our left motor seems to move faster than our right motor. What I think I need to know is how to make our motors adjust to this, (For example: When we turn left, the right motor spins a bit faster than the left motor, and when we turn right, the left motor spins a bit faster than the right motor, which I may have worded incorrectly in the original post). Do you guys have any idea about what I could do with the code to help? BTW, I am new to programming.

Thanks a lot

Last edited by mattsavela : 09-05-2005 at 23:10.
  #4   Spotlight this post!  
Unread 09-05-2005, 23:07
mattsavela mattsavela is offline
Registered User
FRC #0255
 
Join Date: May 2005
Location: Lamphere
Posts: 12
mattsavela is an unknown quantity at this point
Re: One Joystick Drive

Yeah, sorry about that, I worded the example wrong in the original post.
  #5   Spotlight this post!  
Unread 09-05-2005, 23:31
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,112
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: One Joystick Drive

Quote:
Originally Posted by mattsavela
(For example: When we turn left, the right motor spins a bit faster than the left motor, and when we turn right, the left motor spins a bit faster than the right motor, which I may have worded incorrectly in the original post)
What you're describing sounds like it's working properly. If you think it's a problem, there's obviously something you're not getting across to us.
  #6   Spotlight this post!  
Unread 10-05-2005, 15:16
mattsavela mattsavela is offline
Registered User
FRC #0255
 
Join Date: May 2005
Location: Lamphere
Posts: 12
mattsavela is an unknown quantity at this point
Re: One Joystick Drive

Quote:
Originally Posted by Alan Anderson
What you're describing sounds like it's working properly. If you think it's a problem, there's obviously something you're not getting across to us.
Thats what we want the motors to do. At the moment, it looks like they are both moving at the same speed when we turn
  #7   Spotlight this post!  
Unread 10-05-2005, 16:05
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,112
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: One Joystick Drive

Quote:
Originally Posted by mattsavela
At the moment, it looks like [the motors] are both moving at the same speed when we turn
Sorry, I'm still not getting it. What makes you think the motors are at the same speed? Unless you're doing something you haven't mentioned, it wouldn't be turning if the motors aren't running at different speeds.
  #8   Spotlight this post!  
Unread 10-05-2005, 18:00
mattsavela mattsavela is offline
Registered User
FRC #0255
 
Join Date: May 2005
Location: Lamphere
Posts: 12
mattsavela is an unknown quantity at this point
Re: One Joystick Drive

Im not positive about that. I'll let you guys know more on Thursday when I get a chance to test it in the pool with new code you guys helped with.

Also, the first code the Mark posted, when I put it in MPLab, it won't compile. I think I may be doing something wrong considering that I am new to programming, but when I take it out, it compiles fine. Any ideas?
  #9   Spotlight this post!  
Unread 11-05-2005, 08:31
Mark McLeod's Avatar
Mark McLeod Mark McLeod is offline
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,695
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: One Joystick Drive

Quote:
Originally Posted by mattsavela
Also, the first code the Mark posted, when I put it in MPLab, it won't compile. I think I may be doing something wrong considering that I am new to programming, but when I take it out, it compiles fine. Any ideas?
Let's narrow the problem down.

What "baseline" code are you starting with? The IFI 2005 v2.2 default code (http://www.ifirobotics.com/docs/frc-...2-2005v2.2.zip) or something else, such as your team's 2005 modified code?

The code in my first post was quoted verbatim from the v2.2 default code and wouldn't have to be added. The default code already does what you want. The MPLAB problem you're encountering can be caused by lots of simple mistakes, especially if you've never used it before. It might be misplaced code, or if you aren't starting with the default code then the function Limit_Mix might be missing. Whenever you get an error you want to ask the forum about, post (copy and paste) the actual error message. That usually tells us all we need to know to solve the problem.

As an aside, you'll need to be sure the correct motor pwms are being used.

If you are starting with your team's customized 2005 code then post a zip of the user_routines.c file, so we can see what's been modified and how. Then we'll be able to describe the easiest may to add the one joystick lines if they aren't already there.
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle

Last edited by Mark McLeod : 11-05-2005 at 08:42.
  #10   Spotlight this post!  
Unread 11-05-2005, 15:06
mattsavela mattsavela is offline
Registered User
FRC #0255
 
Join Date: May 2005
Location: Lamphere
Posts: 12
mattsavela is an unknown quantity at this point
Re: One Joystick Drive

I attached my userroutines.c file
  #11   Spotlight this post!  
Unread 11-05-2005, 16:01
Mark McLeod's Avatar
Mark McLeod Mark McLeod is offline
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,695
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: One Joystick Drive

A couple of simple issues.
  • The code for joystick control is in the Default_Routine() a few lines below the Process_Data_From_Master_uP routine(). The 1-Joystick code starts there on line 226 (in the version I attached). (In MPLAB look under Edit -> Properties and check "line numbers" if you don't already see them.)
  • There was a ". . ." in my example above that isn't code and needs to be removed (sorry about that).
  • Set both the MOTOR_CORRECTION's to zero to begin with. You'll only need to adjust those values if the operator cannot manually correct for the robot pulling to one side or the other. I don't know how hard it will be for your operator to see the robot underwater.
  • Make sure your drive motor pwms are connected to pwm 13 (right motor) and pwm 15 (left motor).
I've attached a modified version, so you can see what I meant.
the new code is at lines 204-205 and 239-255.
What you wrote originally will actually work, but would be confusing to anyone reading the code, because it does all the joystick work in Default_Routine() then overrides it all in Process_Data_From_Master_uP().

Anyone else have comments to add?
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle

Last edited by Mark McLeod : 11-05-2005 at 16:33.
  #12   Spotlight this post!  
Unread 11-05-2005, 23:25
mattsavela mattsavela is offline
Registered User
FRC #0255
 
Join Date: May 2005
Location: Lamphere
Posts: 12
mattsavela is an unknown quantity at this point
Re: One Joystick Drive

We have cameras attached to our robot, so we can't actually see our robot, but we can see from certain perspectives.

Thank you guys so much for helping me with this.
  #13   Spotlight this post!  
Unread 10-05-2005, 11:07
Mark McLeod's Avatar
Mark McLeod Mark McLeod is offline
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,695
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: One Joystick Drive

Quote:
Originally Posted by mattsavela
One of the students on the team were saying something about how our left motor seems to move faster than our right motor. What I think I need to know is how to make our motors adjust to this...
You can rescale the power output of the faster motor to more closely match the slower motor using something proportional like:
Code:
#define LEFT_MOTOR_CORRECTION 42; // example value at full pwm (254)
 
signed int LeftPwm;
...
//Proportional drop in power
 
LeftPwm = (int)pwm15; //assume pwm15 has already been set by the joystick mixing code
LeftPwm -= 127; //Just because math is clearer if we make 0 neutral (-127 reverse, 127 forward)
 
if (LeftPwm > 0)
{
	LeftPwm = LeftPwm - (LeftPwm / 127 * LEFT_MOTOR_CORRECTION);
}
else if (LeftPwm < 0)
{
	LeftPwm = LeftPwm + (LeftPwm / 127 * LEFT_MOTOR_CORRECTION);
}
 
pwm15 = (unsigned char)(LeftPwm + 127); // restore the normal 0-254 range
This reduces the Left Motor pwm by an amount proportional to the “speed” requested by the joystick.

You’ll have to discover through measurement or trial & error what pwm value (e.g., 220 instead of 254) for the left motor matches the max pwm value on the right motor at full speed.

Also, be aware that reverse on your machine might require a completely different offset value, i.e., the right motor might be faster than the left motor in reverse. So measure in both directions and correct for them separately.
If that’s the case then something like the following might help:
Code:
#define LEFT_MOTOR_CORRECTION 42; // Correction value at full forward pwm (254)
#define RIGHT_MOTOR_CORRECTION 22; // Correction value at full reverse pwm (254)
// Assumes pwm15 is the Left motor,  pwm13 is the Right motor
…
if (pwm15 > 127) // Forward, slow the Left motor
{
	pwm15 -= (pwm15-127) / 127 * LEFT_MOTOR_CORRECTION;
}
 
if (pwm13 < 127) // Reverse, slow the Right motor
{ 
	pwm13 += (127 - pwm13) / 127 * RIGHT_MOTOR_CORRECTION;
}
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle

Last edited by Mark McLeod : 10-05-2005 at 12:40. Reason: editing
Closed Thread


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
If you could change one thing.... Koko Ed General Forum 48 31-03-2005 19:23
1 Joystick Drive or yaniv Programming 3 19-01-2005 14:18
Changing 1 joystick code to 2 (rookie team) Brawler006 Programming 5 20-02-2004 17:00
question about one joystick drive programing james700 Programming 13 29-01-2003 14:49
1 joystick drive Rickertsen2 Robotics Education and Curriculum 9 20-12-2002 20:00


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

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