Mecanum Wheels Code Problems

Hey guys, so my team recently got our new mecanum Wheels and we went on programming the wheels so they could strafe and do cool stuff like that. But we were having some problems that when we strafed, the bot would kind of turn and swing a bit, which is confusing and this is same when driving backwards. I dont know if its a mechanical Problem or a Driving Problem but here is the code we have tried till now

		if ((fabs(controller.get_analog(pros::E_CONTROLLER_ANALOG_LEFT_Y)) + fabs(controller.get_analog(pros::E_CONTROLLER_ANALOG_RIGHT_Y))) > (fabs(controller.get_analog(pros::E_CONTROLLER_ANALOG_LEFT_X)) + fabs(controller.get_analog(pros::E_CONTROLLER_ANALOG_RIGHT_X)))) {
			set_drive((powf(controller.get_analog(pros::E_CONTROLLER_ANALOG_LEFT_Y), 3)) / powf(127, 2), (powf(controller.get_analog(pros::E_CONTROLLER_ANALOG_RIGHT_Y), 3)) / powf(127, 2));
		} else {
			strafe(controller.get_analog(pros::E_CONTROLLER_ANALOG_LEFT_X));
			strafe(-controller.get_analog(pros::E_CONTROLLER_ANALOG_RIGHT_X));
		}

and

drive_right = controller.get_analog(ANALOG_LEFT_Y) - controller.get_analog(ANALOG_RIGHT_X) - controller.get_analog(ANALOG_LEFT_X);
drive_right_b =  controller.get_analog(ANALOG_LEFT_Y) - controller.get_analog(ANALOG_RIGHT_X) + controller.get_analog(ANALOG_LEFT_X);
drive_left = controller.get_analog(ANALOG_LEFT_Y) + controller.get_analog(ANALOG_RIGHT_X) + controller.get_analog(ANALOG_LEFT_X);
drive_left_b =  controller.get_analog(ANALOG_LEFT_Y) + controller.get_analog(ANALOG_RIGHT_X) - controller.get_analog(ANALOG_LEFT_X);

so if you find something which is done wrong please let me know and if you could provide a sample of the opcontrol code for mecanum wheels that would be helpful as well.
(also please try not to say that this post or that post has good info, i have already looked at many posts related to mecanum wheels but i didnt find anything useful but if you find a post which has a lot of info please do post it here)
Thanks!!

2 Likes

I have reviewed your code. It is mostly correct but very hard to make sense of because you don’t use descriptive variable names.

I assume that in the second code snippet ANALOG_LEFT_Y is forward, ANALOG_RIGHT_X is turn and ANALOG_LEFT_X is sideways consisten with this code:

Then for the first code snippet I didn’t identify any problem except first strafe() call using E_CONTROLLER_ANALOG_LEFT_X is pointless if you override it with the second call.

The problem must be either with the rest of the code or with mechanical.

Do all wheels evenly contact ground and are they installed correctly?

Then if you can see if all motors are setup correctly forward and reverse and work in both directions when you lift your robot from the ground, then your problem has to be somewhere in the remaining code.