void autonomous( void ) {
while(Sonar1.distance(distanceUnits::in) <8)
{
Arm1.spin(vex::directionType::fwd,200, vex::velocityUnits::pct);
}
while(Sonar1.distance(distanceUnits::in)>8)
{
Frontleftmotor.spin(vex::directionType::fwd,200,vex::velocityUnits::pct);
Backleftmotor.spin(vex::directionType::fwd,200, vex::velocityUnits::pct);
Backrightmotor.spin(vex::directionType::fwd,200, vex::velocityUnits::pct);
Frontrightmotor.spin(vex::directionType::fwd,200, vex::velocityUnits::pct);
}
Frontleftmotor.stop();
Frontrightmotor.stop();
Backleftmotor.stop();
Backrightmotor.stop();
I need help with it
The only problem I see is that you are trying to use 200% power for your motors. Are you trying to use pct units(-100 to 100) or RPM units(-200 to 200)? Did you test it on your robot? What is it suppose to do?
I thought 200 was the max amount of power you can have.
So if a cap is less than 8 inches then it needs to move forward and flip it. Do you think it will work? Other people say it won’t.
When you use the pct units (vex::velocityUnits::pct), the range is from -100 to +100. The range for using RPM is dependent on what gear config your motors have (-MaxRPM to +MaxRPM). Where is the sonar attached? The code tells the arm to raise for as long as the sonar reads less than 8 inches. Then it move forward for as long as the sonar reads more than 8 inches.
Yes that is what I meant. With 200, all of the motors on my robot worked.
I think you need to switch the order of the two while loops. I’m not sure why the flip is before the drive.
The only downside with the sonars is that they have a cone shaped measuring to them which adds error to their readings. For my team, we use the encoders to move forward a certain distance and then we flip the cap with our flipper.
It would look something like this.
void autonomous( void )
{
Frontleftmotor.rotateFor(1500,vex::rotationUnits::deg,200,vex::velocityUnits::rpm,false);
Backleftmotor.rotateFor(1500,vex::rotationUnits::deg,200,vex::velocityUnits::rpm,false);
Backrightmotor.rotateFor(1500,vex::rotationUnits::deg,200,vex::velocityUnits::rpm,false);
Frontrightmotor.rotateFor(1500,vex::rotationUnits::deg,200,vex::velocityUnits::rpm);
Arm1.rotateFor(500,vex::rotationUnits::deg,200, vex::velocityUnits::rpm);
}
Nice. I was also trying to do something similar to this but i was not able to figure out the rotation Units and all that.
void autonomous( void ) {
while(Sonar1.distance(distanceUnits::in)>8)
{
Frontleftmotor.spin(vex::directionType::fwd,200,vex::velocityUnits::pct);
Backleftmotor.spin(vex::directionType::fwd,200, vex::velocityUnits::pct);
Backrightmotor.spin(vex::directionType::fwd,200, vex::velocityUnits::pct);
Frontrightmotor.spin(vex::directionType::fwd,200, vex::velocityUnits::pct);
}
while(Sonar1.distance(distanceUnits::in) <8)
{
Arm1.spin(vex::directionType::fwd,200, vex::velocityUnits::pct);
}
Frontleftmotor.stop();
Frontrightmotor.stop();
Backleftmotor.stop();
Backrightmotor.stop();
Would this be correct then
I still recommend using only encoders, but if you want to use a sonar then it would look like this:
void autonomous( void )
{
while(Sonar1.distance(distanceUnits::in)>8)
{
Frontleftmotor.spin(vex::directionType::fwd,200,vex::velocityUnits::rpm);
Backleftmotor.spin(vex::directionType::fwd,200, vex::velocityUnits::rpm);
Backrightmotor.spin(vex::directionType::fwd,200, vex::velocityUnits::rpm);
Frontrightmotor.spin(vex::directionType::fwd,200, vex::velocityUnits::rpm);
}
Frontleftmotor.stop(vex::brakeType::coast);
Backleftmotor.stop(vex::brakeType::coast);
Backrightmotor.stop(vex::brakeType::coast);
Frontrightmotor.stop(vex::brakeType::coast);
while(Sonar1.distance(distanceUnits::in) <8)
{
Arm1.spin(vex::directionType::fwd,200, vex::velocityUnits::rpm);
}
Arm1.stop(vex::brakeType::coast);
}
The “vex::brakeType::coast” param locks the motor in place when stopped. This will move forward and when the sonar detects less than 8 inches, the arm move up and the base stops.
No, it doesn’t. It allows motor’s axle holder (and whichever inner parts are need to accomplish this) to spin nearly freely. Most likely it disconnects the wires on the coils from anything else, which would mean it’s exactly the opposite of locking the motor in place. The result of using vex::brakeType::coast is that the robot will continue rolling until friction stops it, which probably won’t be so far.
vex::brakeType::brake tries to slow down the rotation to reach a stop but doesn’t try to specifically hold a position.
vex::brakeType::hold tries to keep the motor locked in place. I suspect you were suggesting this.
Oh yea sorry, I got mixed up.