|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||||
|
|||||
|
in robotC what is the code you need to put in to make your Max speed decrease?
|
|
#2
|
||||
|
||||
|
Re: [FTC]: Slow Down Max Speed!!
Divide the input by a constant before sending the value to the motors. I'm not too familiar with FTC, but in RobotC for Vex, it would look like something like this:
Code:
motor[port1] = vexRT[Ch3] / 1.5; |
|
#3
|
|||||
|
|||||
|
Re: [FTC]: Slow Down Max Speed!!
We need to slow the drive motors because we are using a 4:1 ratio and it's still too fast. i want to make the joysticks max be a certain speed.
|
|
#4
|
||||
|
||||
|
Re: [FTC]: Slow Down Max Speed!!
The code i put above would scale the input to the output. To limit it without scaling, do something like this:
Code:
if(vexRT[Ch1]>80){
motor[port1] = 80;
}else if(vexRT[Ch1]<-80){
motor[port1] = -80;
}else{
motor[port1] = vexRT[Ch1];
}
|
|
#5
|
|||||
|
|||||
|
Re: [FTC]: Slow Down Max Speed!!
i will try and see if i can make this into FTC code thanks.
|
|
#6
|
|||
|
|||
|
Re: [FTC]: Slow Down Max Speed!!
I would recommend you take the scaling route (NickE's first example) as the second example will limit the output to the motor by only listening to 2/3 of the range of your analog stick (less control).
That or use a predefined speed constant with a simplified on/off control. |
|
#7
|
|||||
|
|||||
|
Re: [FTC]: Slow Down Max Speed!!
Quote:
|
|
#8
|
|||
|
|||
|
Re: [FTC]: Slow Down Max Speed!!
There are many ways to go about it, but I would create a scaling function. Here is an example with the important constants defined within the function. For best performance, I would recommend you calculate the ratio with the constants defined staticaly outside of the function (avoid calculating the ratio on each call).
Code:
int simpleScale(int joyVal) {
const int MAX_JOY_VAL = 127;
const int MAX_MOTOR_VAL = 100;
const int DEADZONE = 5;
//check for deadzone
if(abs(joyVal) < DEADZONE) {
return 0;
}
//calculate ratio based on max motor speed and max analog stick value
float ratio = (MAX_MOTOR_VAL/MAX_JOY_VAL);
//apply ratio to actual joystick value
int result = (joyVal)*ratio;
return result;
}
You can call the function from your main task similar to this: Code:
//scale output to someMotor based on joystick 1 analog stick 1 y axis motor[someMotor] = simpleScale(joy1_y1); |
|
#9
|
||||
|
||||
|
Re: [FTC]: Slow Down Max Speed!!
Instead of using variables as in l0jec's example, you could use #define statements to reduce memory usage and potentially speed up the program execution some. With a #define statement, the compiler in RobotC will replace all instances of 'MAX_JOY_VAL', for instance, with the value defined in the statement. The robot will see the defined values and not the names for the values defined in the statements. Be sure not to use either equals signs or semicolons in these lines.
Here's the same code he posted, except with #define statments: Code:
int simpleScale(int joyVal) {
#define MAX_JOY_VAL 127
#define MAX_MOTOR_VAL 100
#define DEADZONE 5
//check for deadzone
if(abs(joyVal) < DEADZONE) {
return 0;
}
//calculate ratio based on max motor speed and max analog stick value
float ratio = (MAX_MOTOR_VAL/MAX_JOY_VAL);
//apply ratio to actual joystick value
int result = (joyVal)*ratio;
return result;
}
|
|
#10
|
|||||
|
|||||
|
Re: [FTC]: Slow Down Max Speed!!
Quote:
. |
|
#11
|
|||
|
|||
|
Re: [FTC]: Slow Down Max Speed!!
Quote:
If we're not changing the MAX_MOTOR_VAL or MAX_JOY_VAL, then we're still wasting CPU on a floating point calculation on each call though. The ratio variable could also be pulled out of the function and made a constant if we want to be crazy with optimization. Another more flexible option for such a method would be to take a joystick analog stick value as well as a max motor speed as arguments and calculate a custom scale on the fly. Would be useful if you want to provide multiple scales (based on max output) for different motors from a single function. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [FTC]: January Run Down and New FTC Pictures | ttldomination | FIRST Tech Challenge | 6 | 04-02-2009 13:18 |
| Slow down teh motors! | brennerator | Programming | 21 | 18-01-2007 23:30 |
| Cheapest and easiest way to slow down a motor | sanddrag | Technical Discussion | 41 | 21-12-2005 07:26 |
| speed controller max speed | Team 668 | Programming | 15 | 13-02-2005 14:05 |
| Segway max speed? | Morgoth | Dean Kamen's Inventions | 2 | 15-04-2003 20:11 |