To put it simply, I’m trying to create four motor groups. I need :
FrontDrive
(FrontLeftDrive + FrontRightDrive)
BackDrive
(BackLeftDrive + BackRightDrive
LeftDrive
(FrontLeftDrive + BackLeftDrive
RightDrive
(FrontRightDrive + BackRightDrive)
The reason I need four and not two is because I have an X drive this year. I want to use these groups to easier program driving in all directions whether that be in auton or drivers.
Heres how I’ve attempted it
//Motor group test
//V1
int FrontDrive1 = (FrontLeftDrive, FrontRightDrive);
int BackDrive1 = (BackLeftDrive, BackRightDrive);
int LeftDrive1 = (FrontLeftDrive, BackLeftDrive);
int RightDrive1 = (FrontRightDrive, BackRightDrive);
//V2
bool FrontDrive2(){
FrontLeftDrive.spin(forward);
FrontRightDrive.spin(forward);
return 0;
}
bool BackDrive2(){
BackLeftDrive.spin(forward);
BackRightDrive.spin(forward);
return 0;
}
bool LeftDrive2(){
FrontLeftDrive.spin(forward);
BackLeftDrive.spin(forward);
return 0;
}
bool RightDrive2(){
FrontRightDrive.spin(forward);
BackRightDrive.spin(forward);
return 0;
}
I’ve tried a couple things but nothing is working. Any tips would be greatly appreciated.
I would really recommend against this approach. While you are re-using the motor instances, and are incorporating some notion of modularity, you run a very real risk of calling these functions in ways where the code issues contradictory commands to the motors.
Also, the way you have structured these functions, your X-Drive will only be able to move in directions at 90 degree increments.
Ok. I’m really only doing this to make typing everything out easier. Basically as a side project. I would also like to add that I’ve never programmed an X-Drive before. Are there any threads that you’d recommend?
I cant imagine that it would be much different from a tank set up with a regular drive but our bot isn’t operational so I cant really test anything.
This is a really well thought out holonomic drive class (there’s no difference from a coding perspective between an X-Drive and a Mecanum Drive, so don’t mind the class name)
It is, that’s where you’re confused. With holonomic, you can go in any horizontal direction without turning. With tank, you can only go forward or backward without turning. By setting it up as two tank drives, you would completely lose out on the ability to go in any diagonal direction. If you want to go every direction, you have to program a normal holonomic drive.
Yeah, pretty much. But it’s good that you’re trying to experiment. It means you’re trying to learn.
If you do wish to reinvent the wheel like I do for the sake of education (please don’t do this for a competition, it probably won’t work well) you could create a class that takes in two parameters in the constructor, both of which are motors, and then you make functions based on the motors base functions. If you REALLY wanted to make it portable, you could take an std::vector as a parameter instead, then you can do some magic, and then boom, custom motor groups. If you don’t know what any of that means, go on a google run and see (I don’t know how much you actually know so yeah). If you do, great. Playing around is a good way to learn C++. Id suggest the Cherno on YouTube, literally the best C++ teacher on the planet.
But hey. If you make it work right, show it on the forums. We’re bound to be interested
Where would be a great place to look for how to do it? I want it configured so that the left stick is regular arcade and right stick is all directional movement, with no turning. I’ve looked all over the forum but i haven’t found a step by step build and explanation of the code.
This is not an explanation, but it appears to be almost fully working code. I don’t know which axes are which, but if you apply it to your robot, you can test what the controls do and adjust the axis names accordingly. However, I’m reluctant to hand out answers without explanations, so I’m obligated to remind you that if you copy code you don’t understand, when it breaks you can’t fix it and you don’t learn anything. Here is a post with five other links about x-drives, and maybe some of them will contain explanations of the code.
I’m going to look for a video I was once explaining it.* Actually, YouTube is another one of those free resourses with hard-to-find nuggets, so search it up yourself a few times.