Hey guys so I am building a six motor drivetrain and I need help coding my joysticks since I can’t create a drivetrain like you can with four motor. How am I able to code tank drive in python for a six motor drivetrain. Thanks
We just need the joysticks to function like a normal tank drive
Yes you can, just not in the graphical configuration menu – create a motor group for the wheels on each side, then set up the drivetrain passing the motor groups in place of motors.
I did that, I think I might have a solution but give me a sec and I will post the code
I am unable to test this currently so will this work
# drivetrain functions
def drivetrain_left_forward():
LF.spin(FORWARD)
LM.spin(REVERSE)
LB.spin(FORWARD)
def drivetrain_left_reverse():
LF.spin(REVERSE)
LM.spin(FORWARD)
LB.spin(REVERSE)
def drivetrain_right_forward():
RF.spin(FORWARD)
RM.spin(REVERSE)
RB.spin(FORWARD)
def drivetrain_right_reverse():
RF.spin(REVERSE)
RM.spin(FORWARD)
RB.spin(REVERSE)
def drivetrain_stop():
LF.stop()
LM.stop()
LB.stop()
RF.stop()
RM.stop()
RB.stop()
# fourbar functions
def fourbar_up():
FOURBAR.spin(FORWARD)
def fourbar_down():
FOURBAR.spin(REVERSE)
def fourbar_stop():
FOURBAR.stop()
# 4bar clamp functions
def fbclamp_clamp():
FBCLAMP.set(True)
def fbclamp_unclamp():
FBCLAMP.set(False)
# conveyor functions
def conveyor_forward():
CONVEYOR.spin(FORWARD)
def conveyor_reverse():
CONVEYOR.spin(REVERSE)
def conveyor_stop():
CONVEYOR.stop()
# clamp functions
def clamp_clamp():
CLAMP.set(True)
def clamp_unclamp():
CLAMP.set(False)
if controller_1.axis2.position(100)
else drivetrain_right_forward()
if controller_1.axis3.position(100)
else drivetrain_left_forward()
if controller_1.axis2.position(-100)
else drivetrain_right_reverse()
if controller_1.axis3.position(-100)
else drivetrain_left_reverse()
if controller_1.axis2.postion(0)
else drivetrain_stop()
if controller_1.axis3.position(0)
else drivetrain_stop
essentially does the drive code function as a tank drive
this is C++, but you should be able to do something like this in python, it just takes the axis values and sets them to the motor speed. (fwd- forward, pct - percent)
Right.spin(vex::directionType::fwd, Controller1.Axis2.value(), vex::velocityUnits::pct);
Right2.spin(vex::directionType::fwd, Controller1.Axis2.value(), vex::velocityUnits::pct);
Right3.spin(vex::directionType::fwd, Controller1.Axis2.value(), vex::velocityUnits::pct);
Left.spin(vex::directionType::fwd, Controller1.Axis3.value() , vex::velocityUnits::pct);
Left2.spin(vex::directionType::fwd, Controller1.Axis3.value() , vex::velocityUnits::pct);
Left3.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct);
You can also utilize the Vex Drivetrain with 6 motors.
Ok so based on this I think the python version I made will work
what you have is a little flawed, because you can only go at 100% or zero, and your if statements contradict each other making the robot go back and forth at a REALLY fast rate if the controller is at an axis value of -100 < x > 100 and x != 0
But with it like this how do I make it go a certain distance
Ok I will make the change then repost
if you want to go certain distances, you might want to do a spin for command, because it uses the internal encoders to track how many rotations or degrees the motor has turned
This is probably not correct but maybe.
if controller_1.axis2.position(100>x<-100)
else drivetrain_right_forward()
if controller_1.axis3.position(100>x<-100)
else drivetrain_left_forward()
if controller_1.axis2.position(-100>x<100)
else drivetrain_right_reverse()
if controller_1.axis3.position(-100>x<100)
else drivetrain_left_reverse()
if controller_1.axis2.postion(0)
else drivetrain_stop()
if controller_1.axis3.position(0)
else drivetrain_stop
Is there a good way to convert that to inches based on rpm
Or should I just guestimate and improve
yes, the distance = circumference of wheel * amount of rotations
Thanks that will make auton much easier
Now I just need to know if I solved the acceleration problem you brought up. I don’t know if that is the way you meant
i wouldn’t use if else statements, for many reasons
- you can only have the motors at 100% or 0%
a) you cant make fine adjustments
b) if you have any controller drift, than it would go at 100% power when you don’t want it to - you are using the if/ else statements wrong
- it is longer and more complicated than it needs to be