View unanswered posts | View active topics It is currently Sat Dec 20, 2014 5:09 pm






Reply to topic  [ 12 posts ] 
Tetrix power limiter? 
Author Message
Rookie

Joined: Thu Oct 06, 2011 6:37 pm
Posts: 9
Post Tetrix power limiter?
I'm in robotics club at my school and I have been designated as the lead programmer, as I had had some experience with C++ before. My club sponsor has said I can write any kind of program, but I can only run the motors at 50% capacity or less. This hasn't been difficult so far, as I have just entered 50 as the highest percentage I have used, but now I have graduated into joystick control and have no idea how to limit the motors to 50%. The code is below, any criticism is helpful, THANKS!!

Code:
#pragma config(Hubs,  S1, HTMotor,  HTServo,  none,     none)
#pragma config(Motor,  mtr_S1_C1_1,     motorD,        tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C1_2,     motorE,        tmotorNormal, openLoop, reversed)
#pragma config(Servo,  srvo_S1_C2_1,    servo1,               tServoStandard)
#pragma config(Servo,  srvo_S1_C2_2,    servo2,               tServoNone)
#pragma config(Servo,  srvo_S1_C2_3,    servo3,               tServoNone)
#pragma config(Servo,  srvo_S1_C2_4,    servo4,               tServoNone)
#pragma config(Servo,  srvo_S1_C2_5,    servo5,               tServoNone)
#pragma config(Servo,  srvo_S1_C2_6,    servo6,               tServoNone)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//


#include "JoystickDriver.c"

task main()
{
  int threshold = 20;             // Threshold is the area that the motor won't activate until the value is greater
                                  // than the threshold. This is so we don't have to edit the threshold

  while(true)                            // keeps loop going forever
  {
    getJoystickSettings(joystick);
    if(abs(joystick.joy1_y2) > threshold)   // If the right analog stick's Y-axis readings are either above or below the threshold:
    {
      motor[motorD] = joystick.joy1_y2;         // Motor D is assigned a power level equal to the right analog stick's Y-axis reading.
    }
    else                                    // Else if the readings are within the threshold:
    {
      motor[motorD] = 0;                        // Motor D is stopped with a power level of 0.
    }


    if(abs(joystick.joy1_y1) > threshold)   // If the left analog stick's Y-axis readings are either above or below the threshold:
    {
      motor[motorE] = joystick.joy1_y1;         // Motor E is assigned a power level equal to the left analog stick's Y-axis reading.
    }
    else                                    // Else if the readings are within the threshold:
    {
      motor[motorE] = 0;                        // Motor E is stopped with a power level of 0.
    }


    // BUTTONS TO CONTOL SERVO ARM
    // button 5 makes servo goes up, 6 goes down.

    if(joy1Btn(5))          // If Button 5 is pressed:
    {
      servo[servo1] = 245;      // Raise Servo 1 to position 200.
    }

    if(joy1Btn(6))          // If Button 6 is pressed:
    {
      servo[servo1] = 10;       // Lower Servo 1 to position 20.
    }
  }
}


Thu Oct 06, 2011 6:48 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1368
Post Re: Tetrix power limiter?
The following macros will help you.
Code:
 //
 // The BOUND macro limits the value (n) within the bounds between the given
 // low (l) and high (h).
 //
#define BOUND(n,l,h)            (((n) < (l))? (l): ((n) > (h))? (h): (n))

//
// The NORMALIZE macro transforms a value (n) in the range between (sl) and
// (sh) to the range between (tl) and (th).
//
#define NORMALIZE(n,sl,sh,tl,th) (int)(((long)(n) - (sl))*((th) - (tl))/((sh) - (sl)) + (tl))

//
// Joystick macros.
//
#ifndef DEADBAND_INPUT_THRESHOLD
    #define DEADBAND_INPUT_THRESHOLD 20
#endif

//
// These macros ignore input value (n) that is within the DEADBAND_THRESHOLD.
// This is necessary because analog joysticks do not always centered at zero.
// So if the joystick is at the rest position, we will consider it zero even
// though the value is non-zero but within DEADBAND_THRESHOLD.
//
#define DEADBAND(n,t)           ((abs(n) > (t))? (n): 0)
#define DEADBAND_INPUT(n)       DEADBAND(n, DEADBAND_INPUT_THRESHOLD)

You can use the macros like this:
Code:
    //
    // This basically scales the joystick range (-128 to 127) to whatever
    // range you want to limit (-50 to 50 in your case).
    //
    motor[motorE] = NORMALIZE(DEADBAND_INPUT(joystick.joy1_y1), -128, 127, -50, 50);
    motor[motorD] = NORMALIZE(DEADBAND_INPUT(joystick.joy1_y2), -128, 127, -50, 50);


Thu Oct 06, 2011 7:07 pm
Profile
Expert

Joined: Thu Sep 29, 2011 11:09 pm
Posts: 184
Location: Michigan USA
Post Re: Tetrix power limiter?
Why ever such a limitation?

_________________
Matt


Thu Oct 06, 2011 8:41 pm
Profile WWW
Rookie

Joined: Thu Oct 06, 2011 6:37 pm
Posts: 9
Post Re: Tetrix power limiter?
mattallen37 wrote:
Why ever such a limitation?


To avoid blowing up motors, one of my peers blew up two last year :-)


Thu Oct 06, 2011 9:37 pm
Profile
Rookie

Joined: Thu Oct 06, 2011 6:37 pm
Posts: 9
Post Re: Tetrix power limiter?
MHTS wrote:
The following macros will help you.


Thanks, it seems to be PERFECT! I haven't been able to download it to the brick yet but THANKS!


Thu Oct 06, 2011 10:01 pm
Profile
Expert

Joined: Thu Sep 29, 2011 11:09 pm
Posts: 184
Location: Michigan USA
Post Re: Tetrix power limiter?
christianik1407 wrote:
To avoid blowing up motors, one of my peers blew up two last year :-)

Sounds more like a mechanical limit than it does electrical. You shouldn't have to worry about them burning out at 100% PWM, unless mechanically you are restricting them too much.

_________________
Matt


Thu Oct 06, 2011 10:41 pm
Profile WWW
Rookie

Joined: Thu Oct 06, 2011 6:37 pm
Posts: 9
Post Re: Tetrix power limiter?
Any idea why the code would only allow me to engage the left motor while the right motor is in reverse or vise versa? This isn't a huge problem, but it would be more convienient if I could turn of a lesser degree.


Fri Oct 07, 2011 4:34 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1368
Post Re: Tetrix power limiter?
Depending on how you wired your motor, you may need to play with the "reversed" check box in the "Motor and Sensor setup menu" to get the motor direction you want. The "Motor and Sensor setup" will automatically generate an updated pragma section such as the one below.
Code:
#pragma config(Motor,  mtr_S1_C1_1,     motorD,        tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C1_2,     motorE,        tmotorNormal, openLoop, reversed)


Fri Oct 07, 2011 4:40 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1368
Post Re: Tetrix power limiter?
Wait, I think I misunderstood your question. Can you clarify your question? Are you saying you have problem turning the right amount?


Fri Oct 07, 2011 4:45 pm
Profile
Rookie

Joined: Thu Oct 06, 2011 6:37 pm
Posts: 9
Post Re: Tetrix power limiter?
Sorry, in order for me to have the left motor go backwards, the right motor must be going forwards. I can go forward with both motors or back with both, but they are unusable one at a time.


Fri Oct 07, 2011 6:53 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1368
Post Re: Tetrix power limiter?
Are you saying you were trying to turn by moving the one stick up (one motor going forward) and the other stick down (the other motor going backward) but one of the motors was not turning? Or both motors were not turning? What do you mean by "they are unusable one at a time"?
Can you post your current code so I can see what you mean?


Fri Oct 07, 2011 7:01 pm
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: Tetrix power limiter?
By running your motors at a lower power, you might actually be increasing the chance of them burning out. Motors burn out when there is power being sent through them, but they are not physically able to turn. This has to do with how current works in a motor. Basically, counter-current is not being generated if the motor is not spinning, and the amperage of the power draw gets too high because there is no counter-current to reduce it. The wires are not meant to handle so much current, and the insulation melts, and there is often a short. Google burned out motors for more information. If you mechanically gear the motors to go slower, then you will get more torque, and possibly prevent your motors from burning out. But you cannot really do anything with programming, except maybe making sure that you don't switch direction at full speed.

_________________
sudo rm -rf /


Fri Oct 07, 2011 9:15 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 12 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.