View unanswered posts | View active topics It is currently Tue Jul 22, 2014 10:20 am






Reply to topic  [ 6 posts ] 
Robotc Varible motor with one button 
Author Message
Rookie

Joined: Mon Feb 27, 2012 5:26 pm
Posts: 20
Post Robotc Varible motor with one button
Hi trying to make a code for a ball launcher for a class assignment but have the issue of a high speed gear ratio stripping the tetrix dc motors. I have two motors on one port on sensor port one motor controller 3. The idea one hit of button 6 motor = 25 the 2nd hit will go to 50 the 3rd to 75 the 4th to a 100 and have button 7 do the same thing but slow it down so to make it go down -25 each hit to 0. I don't know much but I can provide a code that has the details.


Tue May 29, 2012 2:28 pm
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: Robotc Varible motor with one button
Here's some code for what you want to do:
Code:
int numPressed = 0;
bool stillPressed6 = false;
bool stillPressed7 = false;
while(true){
  if(joy1Btn(6)){
    if(!stillPressed6){
      stillPressed6 = true;
      if(numPressed < 4){
        numPressed++;
      }
    }
  }else stillPressed6 = false;

  if(joy1Btn(7)){
    if(!stillPressed7){
      stillPressed7 = true;
      if(numPressed > 0){
        numPressed--;
      }
    }
  }else stillPressed7 = false;
 
  motor[shaft] = numPressed*25;
}

This is untested code, but it should give you an idea for what you want to do.

_________________
sudo rm -rf /


Thu May 31, 2012 2:38 am
Profile
Rookie

Joined: Mon Feb 27, 2012 5:26 pm
Posts: 20
Post Re: Robotc Varible motor with one button
hey would it be possible to do a motor power of 25 at 1 button press of button 7 and two presses at 7 = 100 motor power. and be able to do the same thing with button 6 in reverse?
Thanks for the previous post that was very great for an untested code thank you.


Thu Aug 16, 2012 7:37 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Robotc Varible motor with one button
Magicode's code with slight modification:
Code:
#define NUM_SPEEDS  5
int motorSpeed[NUM_SPEEDS] = {0, 25, 50, 75, 100};
int numPressed = 0;
bool stillPressed6 = false;
bool stillPressed7 = false;
while(true){
  if(joy1Btn(6)){
    if(!stillPressed6){
      stillPressed6 = true;
      if(numPressed < NUM_SPEEDS - 1){
        numPressed++;
      }
    }
  }else stillPressed6 = false;

  if(joy1Btn(7)){
    if(!stillPressed7){
      stillPressed7 = true;
      if(numPressed > 0){
        numPressed--;
      }
    }
  }else stillPressed7 = false;
 
  motor[shaft] = motorSpeed[numPressed];
}

To do just 2 speeds, change NUM_SPEEDS to 3 and just initialize the array to contain only 0, 25 and 100.


Thu Aug 16, 2012 9:02 pm
Profile
Rookie

Joined: Mon Feb 27, 2012 5:26 pm
Posts: 20
Post Re: Robotc Varible motor with one button
I tried the code it is fantastic alone how ever I can't have it do tel-op with the rest of the robot is there anything I can do to help and thanks for everything.


Thu Aug 30, 2012 3:01 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Robotc Varible motor with one button
I assume when you said tele-op, you meant using a joystick to drive the robot around? If so, you can do this with the same code:
Code:
#define NUM_SPEEDS  5
int motorSpeed[NUM_SPEEDS] = {0, 25, 50, 75, 100};
int numPressed = 0;
bool stillPressed6 = false;
bool stillPressed7 = false;
while(true){
  if(joy1Btn(6)){
    if(!stillPressed6){
      stillPressed6 = true;
      if(numPressed < NUM_SPEEDS - 1){
        numPressed++;
      }
    }
  }else stillPressed6 = false;

  if(joy1Btn(7)){
    if(!stillPressed7){
      stillPressed7 = true;
      if(numPressed > 0){
        numPressed--;
      }
    }
  }else stillPressed7 = false;
 
  motor[shaft] = motorSpeed[numPressed];

  int drivePower = joystick.joy1_y1;
  int turnPower = joystick.joy1_x1;
  //
  // Alternatively, instead of dividing by 2,
  // you can do slightly complex calculation to scale
  // the motor values to be within +/- 100.
  //
  motor[leftMotor] = (drivePower + turnPower)/2;
  motor[rightMotor] = (drivePower - turnPower)/2;
}


Thu Aug 30, 2012 3:38 pm
Profile
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.