# Looking for Function to drive at certain speed and rotate

I have 2 functions which need me to set a speed and rotation(but speed most importantly).
Now I know it’s a simple test but it’s exams here so I won’t be able to test anything for a couple/several days so I want to make sure I’m not wasting my time.
These are two testing methods really but the first one,
Spin(), makes the robot do a right spin when a button is pressed.
For this, I use

MainDrive.drive(0.5, 1); //main drive is the robotdrive

Now this is the function that takes magnitude and (- 1 to +1) and as for turning, > 0 is right and < 0 left turn.

Is this correct?

Now the second is DriveBackAndForth() which is pretty self-explainable. I don’t want it to rotate or anything, just move a meter or two.

For the driving portion, I use

This said that it takes a moveValue(10) and rotateValue(0).

Is this good? I couldn’t find any solid, concrete methods to use for this so this is the best I could find

Any help appreciated, Thanks

It’s hard to really tell what’s going on and what needs to happen based off of your post, but I’ll try to give some suggestions.

You may already be doing this, but I highly suggest that you use WPILib’s built in drive classes. You’ll probably want to use DifferentialDrive, so long as you have a normal non-holonomic chassis.
That being said, since you already use the arcadeDrive method, you may already be using this, though I’m not sure that your understanding of the parameters is correct.

From your post, it looks like you are trying to create two separate commands, one for spinning and one for driving straight. If this is correct, is there a reason for this? It typically makes the most sense to use one command for all driver controlled driving, unless you never foresee wanting to drive forward and turn at the same time. The Screensteps has some information on this if you need help.

For spinning: where did the drive method come from? Did you write it? What is its second parameter and why did you set it to 1? If you were to use the arcadeDrive method from DifferentialDrive, you could easily spin using MainDrive.arcadeDrive(0, 0.5); where 0.5 is your turning speed.

For driving straight: it sounds like your goal here is to move a short distance then stop, like in a line-cross auto routine. As far as I can tell without your full code, this will keep the robot driving at full speed forever, until a new command is started. If you are using the arcadeDrive method from DifferentialDrive, the parameters are values from -1 to 1, and they set the motors at that speed. It seems like you are using 10 as a distance setting, while DifferentialDrive will regard this as a speed setting. If you want to drive for just a short distance, you’ll need to use a timer and check each loop if you have been driving longer than some time, then stop the motors.
If you are trying to write a line-crossing auto routine, check out 1619’s project line cross. There is already a simple line-crossing auto routine written for iterative programming, and I’m sure that a command based routine will be added sometime.

I’m not sure if I understood your question correctly or if my answer makes any sense, but please ask for clarification if needed. Also, it is a lot easier for us to help you if you post code with your question, including the implementation of methods like drive and arcadeDrive, unless they are from WPI.

OK so first off, both functions are for testing really. Spin() for joystick buttons and the driving one as a simple Autonomous command.

As for what I’m using, I just used what I had from the Wpilib library(both from there) and used what I thought fitted the most but admittedly, didn’t understand them super well due to (not the best) documentation.

I’m totally open to new suggestions so here is what is want the functions to do.

Spin();

I want it to do a simple, medium -paced 360. That’s it.

Drive(); (its not called that, but I mean the driving straight).

i just want the robot to drive forward a meter or two at a medium pace.
In the real program, I make it drive back and forth but all I want to know is how to make it drive.

That’s it really. I’m just looking for the appropriate fucntions that I can use with my drive train.

Thanks!