View unanswered posts | View active topics It is currently Tue Jul 22, 2014 11:45 pm






Reply to topic  [ 6 posts ] 
Some Questions on the Drive 
Author Message
Novice

Joined: Thu Oct 09, 2008 7:58 pm
Posts: 79
Post Some Questions on the Drive
Hello, I have some questions about the drive for the robots.

1. The joystick values range from -128 to 127, so I am wondering does the value 127 correspond to 100, and then from there, a ratio is used to figure out the values, like when the joystick reads 100, it will really mean only 78? Or is a strict value, where if the joystick is below 100, it is automatically assumed to be 100.

2. Is there a way to decrease the sensitivity on the motors with the joysticks?

3. Is there any sample code for an arcade style of driving? I could not find it in the sample programs file.

4. Is there a way to sync servos? Can we use the same function to sync motors and use that to sync servos?

Thankx.
:programmer:


Sun Jan 11, 2009 1:05 pm
Profile
Rookie

Joined: Thu Jan 08, 2009 7:51 pm
Posts: 25
Post Re: Some Questions on the Drive
1. The values of the joysticks don't automatically translate over to the motor. You can fix that with this statement:
Code:
motor[motorD]= (int)(((float)joystick.joy1_y1/127.0)*100.0);


2. If by decrease sensitivity, you mean be able to push the sticks farther without moving, you can use this:
Code:
if(abs(joystick.joy1_y1)>20)
{
motor[motorD]= (int)(((float)joystick.joy1_y1/127.0)*100.0);
}
else
{
motor[motorD] = 0;
}

Change 20 to adjust the deadzone to your liking.

3. What do you mean by "arcade style"?

4. You shouldn't need to sync them, you should just set them all to the same position.

Hope this helps.

_________________
It must be user error.


Sun Jan 11, 2009 4:03 pm
Profile WWW
Novice

Joined: Thu Oct 09, 2008 7:58 pm
Posts: 79
Post Re: Some Questions on the Drive
Ah thanks for the answers.

1. I don't mean a dead zone, but I think i figured it out.

2. Arcade drive is the style where the left joystick controls the forward/backward speed and the left joystick controls the turning...does anyone have a sample code for that?


Sun Jan 11, 2009 9:32 pm
Profile
Rookie

Joined: Thu Jan 08, 2009 7:51 pm
Posts: 25
Post Re: Some Questions on the Drive
One of our team's drivers preferred it this way so this is what I wrote:

Code:
while(true)
  {
    getJoystickSettings(joystick);
    float nMotorPower;
    float nDirection;
    int pwr = 0;
    int turn = 0;
    int mtrD = 0;
    int mtrE = 0;

    nMotorPower = joystick.joy1_y2;
    nDirection = joystick.joy1_x1;

    pwr = (int)(((float)nMotorPower/127.0)*100.0);
    turn = (int)(((float)nDirection/127.0)*100.0);

    nxtDisplayTextLine(0, ""+pwr);

    if(abs(turn) > 10)
   {
     mtrD = pwr - turn;
     mtrE = pwr + turn;

   }
   else if (abs(pwr) > 10)
   {
      mtrD = pwr;
      mtrE = pwr;
   }
   else
   {
      mtrD =0;
      mtrE = 0;
   }

    nxtDisplayTextLine(1, "D "+mtrD);
    nxtDisplayTextLine(2, "E "+mtrE);

  motor[leftDriveMotor] = mtrD;
  motor[rightDriveMotor] = mtrE;
 }


Hope this helps.

_________________
It must be user error.


Sun Jan 11, 2009 10:52 pm
Profile WWW
Novice

Joined: Thu Oct 09, 2008 7:58 pm
Posts: 79
Post Re: Some Questions on the Drive
hobbseltoff wrote:
One of our team's drivers preferred it this way so this is what I wrote:

Code:
while(true)
  {
    getJoystickSettings(joystick);
    float nMotorPower;
    float nDirection;
    int pwr = 0;
    int turn = 0;
    int mtrD = 0;
    int mtrE = 0;

    nMotorPower = joystick.joy1_y2;
    nDirection = joystick.joy1_x1;

    pwr = (int)(((float)nMotorPower/127.0)*100.0);
    turn = (int)(((float)nDirection/127.0)*100.0);

    nxtDisplayTextLine(0, ""+pwr);

    if(abs(turn) > 10)
   {
     mtrD = pwr - turn;
     mtrE = pwr + turn;

   }
   else if (abs(pwr) > 10)
   {
      mtrD = pwr;
      mtrE = pwr;
   }
   else
   {
      mtrD =0;
      mtrE = 0;
   }

    nxtDisplayTextLine(1, "D "+mtrD);
    nxtDisplayTextLine(2, "E "+mtrE);

  motor[leftDriveMotor] = mtrD;
  motor[rightDriveMotor] = mtrE;
 }


Hope this helps.


Hmm. Let me get this straight.

1. If the motor value is below 10, or if the scaled value is below 10, then the robot will not do anything. ie. a Dead Zone.

2. The way I see it, is if you are holding the right joystick down, you can't change your speed, because then it would never get thrown into the second conditional. Wouldn't it be better to perform all of those actions so you can check for the speed in the Y direction and the X direction?


Mon Jan 12, 2009 6:44 pm
Profile
Rookie

Joined: Thu Jan 08, 2009 7:51 pm
Posts: 25
Post Re: Some Questions on the Drive
First, the Logitech controllers are of poor quality so we had to add a dead zone to prevent unwanted movement.

Second, I don't quite understand what you're saying in your second point but the speed can be controlled because the first conditional would do the same thing the second one does, just modified by the steering. The reason I used an If.. Else If statement instead of separating it into two If statements is because in order for the robot to stop moving after you took your hands off the controls, you would need an else that set the power to zero for each If statement which would break the code.

_________________
It must be user error.


Tue Jan 13, 2009 1:43 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 6 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.