View unanswered posts | View active topics It is currently Mon Jul 28, 2014 1:16 pm






Reply to topic  [ 9 posts ] 
Another Drive Code Question 
Author Message
Rookie

Joined: Mon Jan 03, 2011 10:52 pm
Posts: 22
Post Another Drive Code Question
Before I post this, I just want to say thanks to everyone that has helped out so far. Just so you know, the team that I joined did not have anyone that could program, and thus I decided that I would try it for them. So thank you for the help, I wouldn't been able to get this thing going without you.

I have a few issues with my drive code during teleop.

1.) In order to stop the left side drive from going either forward or backwards (it do go both ways depending on the joystick), I have to bring the joystick back to the center and press down on the joystick. However, the code should recognize that the joystick value is between -15 and 15 and stop the robot from moving. (If I wrote the code correctly)

2.) The right side of the drive only recognizes forward movement. But it stops when the joystick is returned to it's central position.

The shoulder and NXT motor work perfectly.

Code:
task main()
{
  initializeRobot();

  waitForStart();   // wait for start of tele-op phase

  int thresholdP = 15;
  int thresholdN = -15;

  while (true)
  {
    getJoystickSettings(joystick);
    if((joystick.joy1_y1) > thresholdP)
    {
      motor[leftMotor] = (((joystick.joy1_y1) * (joystick.joy1_y1)) / -161.29);
    }
    if((joystick.joy1_y1) < thresholdN)
    {
      motor[leftMotor] = (((joystick.joy1_y1) * (joystick.joy1_y1)) / 161.29);
    }
    if((joystick.joy1_y2) > thresholdP);
    {
      motor[rightMotor] = (((joystick.joy1_y2) * (joystick.joy1_y2)) / 161.29);
    }
    if((joystick.joy1_y2) < thresholdN);
    {
      motor[rightMotor] = (((joystick.joy1_y2) * (joystick.joy1_y2)) / -161.29);
    }
    if((joystick.joy2_y1) > thresholdP);
    {
      motor[shoulderMotor] = ((joystick.joy2_y1) * .8);
    }
    if((joystick.joy2_y1) < thresholdN);
    {
      motor[shoulderMotor] = ((joystick.joy2_y1) * .8);
    }
    if((joystick.joy2_y2) > thresholdP);
    {
      motor[motorA] = (joystick.joy2_y2);
    }
    if((joystick.joy2_y2) > thresholdN);
    {
      motor[motorA] = (joystick.joy2_y2);
    }
  }
}


Any help is greatly appreciated.

Thanks so much!

Tim


Sun Jan 23, 2011 11:41 am
Profile
Rookie

Joined: Mon Jan 03, 2011 10:52 pm
Posts: 22
Post Re: Another Drive Code Question
Ok,

Not sure why when I make the code this it works:

Code:
task main()
{
  initializeRobot();

  waitForStart();   // wait for start of tele-op phase

  int thresholdP = 15;
  int thresholdN = -15;

  while (true)
  {
    getJoystickSettings(joystick);
    if(abs((joystick.joy1_y1)) > thresholdP);
    {
      motor[leftMotor] = (joystick.joy1_y1);
    }
    if(abs((joystick.joy1_y2)) > thresholdP);
    {
      motor[rightMotor] = -(joystick.joy1_y2);
    }
  }
}


I thought this was telling it the same thing. If it's between -15 and 15 stop, if not follow the value of the joystick.


Sun Jan 23, 2011 12:04 pm
Profile
Rookie

Joined: Mon Jan 03, 2011 10:52 pm
Posts: 22
Post Re: Another Drive Code Question
So now that I have all of the tele-op code working at it's most basic form for one of our robots, I have a question to do with this code.

How can I make the drive (left and right motors) be more of an exponential power curve? I has hoping that the first code would do it... by:

Joystick Value * Joystick Value / Variable (figured out the variable by simple math) and then assigning a number based on if the joystick was pushed forward or backwards.


Mon Jan 24, 2011 2:06 pm
Profile
Rookie

Joined: Wed Feb 24, 2010 11:43 pm
Posts: 34
Post Re: Another Drive Code Question
Actually, I'm not sure I see where you set the value of the motor to zero if it's within the deadband?

I would have thought you'd want something like:
Code:

    if(abs((joystick.joy1_y1)) > thresholdP);
      motor[leftMotor] = (joystick.joy1_y1);
    else
      motor[leftMotor] = 0;



To make it more "exponential" you can experiment with math on the return value. We've tried a lot of different things and have yet to come up with a solution that all the drivers like!


Mon Jan 24, 2011 4:37 pm
Profile
Rookie

Joined: Mon Jan 03, 2011 10:52 pm
Posts: 22
Post Re: Another Drive Code Question
Alan,

You are completely right. I do in fact have that in my code already, I just never put up the finished portion of it. However, I find that if I want to make it an exponential equation (i.e. x^2/161.72) I run into it moving forward even when we want it to move backwards (because the square of a negative is positive).

I guess my question is would this work:

Code:
motor[leftMotor] = {((joystick.joy1_y1) * abs((joystick.joy1_y1)) / 161.72);


I think this would give it the appropriate exponential curve that I want with still having it have the appropriate sign.

I'll try it, especially since it looks a lot better than my first try at it.


Mon Jan 24, 2011 4:59 pm
Profile
Rookie

Joined: Wed Feb 24, 2010 11:43 pm
Posts: 34
Post Re: Another Drive Code Question
yes, that will work... but you might want to use the sgn() function... it returns a 1, 0, or -1 depending on the sign of the number...

thus you could also use:
Code:
motor[leftMotor] = sgn(Joystick.joy1_y1) * ((joystick.joy1_y1 ^2 )  /  161.72);


Tue Jan 25, 2011 5:04 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3164
Location: Rotterdam, The Netherlands
Post Re: Another Drive Code Question
I'm afraid the "^" operator does not raise a number to a particular power. It's the "exclusive or" operator.

Consider the code below:
Code:
task main () {
  int number = 2;
  int exponent = 2;

  nxtDisplayTextLine(2, "2^2: %d", number ^ exponent);
  nxtDisplayTextLine(3, "2*2: %d", number * exponent);
  while(nNxtButtonPressed != kEnterButton);
}


This produces the following result:

Image

Not quite what you thought, I'm sure. Keep that in mind :)

More info on the XOR operator: [LINK].

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Wed Jan 26, 2011 3:28 am
Profile WWW
Rookie

Joined: Wed Feb 24, 2010 11:43 pm
Posts: 34
Post Re: Another Drive Code Question
Quote:
I'm afraid the "^" operator does not raise a number to a particular power. It's the "exclusive or" operator.


oops... didn't realize that! Thanks Xander!

Is there a raisetopower() type function somewhere then?

(Also, in the RobotC helpfile documentation is the comment for the exp() function saying it's XOR or raise to power?)


Wed Jan 26, 2011 12:45 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3164
Location: Rotterdam, The Netherlands
Post Re: Another Drive Code Question
No, there is not but it should be easy to implement yourself :)
As for the help file, I have no idea.

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Wed Jan 26, 2011 4:09 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 9 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.