Holonomic Joystick Threshold

how do joystick thresholds work on holonomic drive?
I know how to do it on a standard tank drive but The code for holonomic confuses me a little as to what values it’s actually getting.

Here is my ROBOTC code for the holonomic drive:


#define C1LX vexRT[Ch4]
#define C1LY vexRT[Ch3]
#define C1RX vexRT[Ch1]

task main() {

	while(true) {
		motor[FL] = -C1LY - C1LX - C1RX;
		motor[FR] =  C1LY - C1LX - C1RX;
		motor[BR] =  C1LY + C1LX - C1RX;
		motor[BL] = -C1LY + C1LX - C1RX;
	}

Thanks

instead of using the #define function I would just says something like
Chn4= VexRt[Ch4];
if(Abs(Chn4)< 15){ Chn4 = 0;}
and do all of that stuff for every channel.

Ah thanks I’ll give that a try when I get back to my bot :slight_smile:

Pretty sure that’s actually my holonomic code. :stuck_out_tongue:

Ok funs over, moving on…

Disclaimer: totally untested code.


#define C1LX vexRT[Ch4]
#define C1LY vexRT[Ch3]
#define C1RX vexRT[Ch1]

#define JOYSTICK_THRESHOLD 40

// Returns the absolute value of foo
int abs(int foo) {
	return (foo < 0) ? -foo : foo;
}

task main() {

	while(true) {

		// Grab editable copies of the joystick values
		int x = C1LX;
		int y = C1LY;
		int r = C1RX;
	
		if(abs(x) <= JOYSTICK_THRESHOLD)
			x = 0;

		if(abs(y) <= JOYSTICK_THRESHOLD)
			y = 0;

		if(abs(r) <= JOYSTICK_THRESHOLD)
			r = 0;

		motor[FL] = -y - x - r;
		motor[FR] =  y - x - r;
		motor[BR] =  y + x - r;
		motor[BL] = -y + x - r;

		wait10Msec(2);

	}

}

Let’s see if we can do better…


#define C1LX vexRT[Ch4]
#define C1LY vexRT[Ch3]
#define C1RX vexRT[Ch1]

#define JOYSTICK_THRESHOLD 40

// Returns the absolute value of foo
int abs(int foo) {
	return (foo < 0) ? -foo : foo;
}

// Returns the squashed value of foo
int threshold(int foo, int threshold) {
	return (abs(foo) <= threshold) ? 0 : foo;
}

task main() {

	while(true) {

		// Grab editable copies of the joystick values
		int x = threshold(C1LX, JOYSTICK_THRESHOLD);
		int y = threshold(C1LY, JOYSTICK_THRESHOLD);
		int r = threshold(C1RX, JOYSTICK_THRESHOLD);

		motor[FL] = -y - x - r;
		motor[FR] =  y - x - r;
		motor[BR] =  y + x - r;
		motor[BL] = -y + x - r;

		wait10Msec(2);

	}

}

ROBOTC may wine about how I declared x, y, r. If so just declare them outside the loop but still set them inside. What I wrote is valid C, just not sure if RC will complain or not.

For those wondering why I didn’t just hardcode JOYSTICK_THRESHOLD into the threshold function, the reason is to keep clamp as generic and useful as possible. Maybe somewhere else clamp will be useful to have with a different value?

I DID define JOYSTICK_THRESHOLD so that there’s only one place it’s defined. This is so it can easily be changed and prevents possible unintended errors if you were to try to change it. If it’s only defined once, you can’t miss one of the instances.

That being said, if you need different clamp values for some reason, you can definitely do that with this code.

-Cody

EDIT: Did some name changing, just for more clarity.

Thanks cody, By saying my Holonomic code i meant the code i used on “my” robot and yes i did steal it from your post :stuck_out_tongue:

One question, why do you need to declare another function for abs when it is already defined in ROBOTC as abs() ??

I never thought of setting the joystick values to 0 instead of the motors, that makes a whole lot more sense now.

Thanks

You don’t, I didn’t know RC had an abs function. My bad. :rolleyes:

Also, Why does the code only sample the joystick values every 20 Milliseconds?
I removed this and it made no visible change on the robot

Internal crap only updates once every 20ms, updating any faster is just a waste of CPU cycles.

You won’t see the chance because you’re updating everything OVER AND OVER with no effect, that is until the 20ms poll comes around.

So would you rather free up the wasted time for other tasks? Short answer, yes (even if you don’t have other tasks yet).

Ah i never knew about the internal update speed.
Now I do :slight_smile:

It’s more the PWM cycle time of the motor than the Cortex itself.

Oldie but goodie explanation on PWM from James Pearman:

https://vexforum.com/t/best-motor-update-speed/19655/1

and here

https://vexforum.com/t/cortex-motor-speed-testing/21687/1

Nice extra background PWM and the 20ms…
http://en.wikipedia.org/wiki/Servo_control