Changing Motor Speed

Here’s our robot:

We feel that the motors on the robot are going way too fast. How do we change their speed? We have a VEX cortex micro controller and a robot arm built from a vex edr kit

Help is appreciated. Thank you.

Do you have a computer with programming language (RobotC, EasyC, PROS, etc) on it so that you can make a modified program for the robot? You would simply want to change the motor speed in the program. 0 is stopped and 127 is full power, so you’d want to find the best value in between.

Thanks for replying. No, I do not have these programs. I have a windows, so robotc works on mine. I have a little experience with robotc, but not much.
When I do install it, can you guide me through the process of setting the motor speed down?
How will I transfer the files from ROBOTC to the Vex microcontroller (I have a usb cord that came with the kit), and what commands should I use?

Thanks!

I can help with this part.
With RobotC, you’re going to have to go through a few additional steps to fully setup the program.
First off, you’ll want to select the robotics platform you’re using.

Start by creating a new file.

Go to Robot --> Platform Type --> Vex Robotics --> Vex 2.0 Cortex
This will set the platform type of RobotC so that it is compatible with Vex EDR and allow you to properly set your motors.

Next, you’ll want to go to Motor and Sensor Setup.
Go to the Motors tab.
You’ll have to check what ports each of your motors are plugged into and assign them in this window.

Now we can start programming. You’ll want to put your commands inside of the task main loop.
Start by adding a while loop:


task main()
{
	while(true)
	{
	}
}

This will make sure that your commands continuously loop.

Now we can make your motors move by using the command:


motor[port] = value

In place of “port” you’ll want to use the name that you assigned to the motor in motor and sensor setup. In place of “value” you’ll want to use a number in the range between 0 and 127, with 0 being no power and 127 being full throttle. Since you want to slow down your motors, a number around 60 should do the trick.

You’ll have to use this command for every motor you want to move and you’ll have to put these commands inside the while loop as shown:


task main()
{
	while(true)
	{
		motor[port1] = value;
		motor[port2] = value;
		motor[port3] = value;
		motor[port4] = value;
	}
}

(I’m only going to use 4 motors in this example.)

So that’s about it. When you want to load your program, use the orange usb cable that came with your kit by plugging in your computer to the microcontroller and hit download to robot. If you have any other questions, feel free to ask in this thread so that other forum members can help you as well. :slight_smile:

P.S. Are you using a joystick?

Thanks so much you two, especially Nehalem for the help!
Yes, we are using a joystick. I’ve got one more problem.
When I click downlaod to robot, an error pops up and says, “No communications link to Vex device, check that your device is connected to your pc” even though our cable is connected to the microcontroller?
What’s wrong?

Thanks.

Oh, looks like I forgot something.
You’re going to have to download RobotC firmware to the microcontroller and your joystick. You can do this by plugging in the microcontroller to your computer and hitting the firmware download button located at the top. You’ll have to do this for your joystick as well.

That can be a few things. But mainly your PC does not see the Cortex. It can be a number of issues and I have not found a good reason why one thing works while another does not.

First, make sure your platform is set to VRC and not IQ.

Second, what kind of connection are you doing? PC to Cortex directly A-A cable or the programming cable to the joystick then Vexnet to the Cortex? Choose the communication type in the robot menu as one of the Vexnet choices if doing it that way or USB if doing the A-A cable way.

Third, are you using the current modern programming cable or an old one? Old ones have chips that were not from Prolific so they may not work any more. Get a new programming cable from Vex and revert back to USB downloads/

OK, now look in the view menu for testing the communication ports. You should see the COM port you plugged into the programming cable. If it is not there, then you don’t have the drivers for the programming cable accessible or your user is not admin. Try forcing Robot C to run as administrator. That sometimes helps.

So I did everything and when I turned the controller all the motors went off crazy? Is this because the robot turned autonomous?

Yeah…thought this might happen.
It isn’t because of the robot going into autonomous. You’ll need a competition switch for that.
The code we wrote earlier was a proof of concept(I guess) about setting motor speeds. Since you’re using a joystick, we’re going to look into if loops now.

If loops will only execute when certain conditions are met that the if loop tests for. In this case, we’ll be testing for certain button presses on the joystick.

For the example, I’ll be mapping the motors to Channel 6 on the joystick. The channel contains 2 trigger buttons and is located on the back of the remote in place of a normal trigger.
In RobotC, the joystick is accessed through this command:


vexRT]

What goes in between the braces is whichever button/stick you wish to access.
Since we’re mapping to channel 6, we’ll be using this set of commands:


vexRT[Btn6U]
vexRT[Btn6D]

It might look a little confusing but it’s pretty simple.
Btn = Button(what we’re trying to access)
6 = Channel Number(the channel number is labelled on the remote)
U/D = Which Button(Are we pressing the upper or lower button?)

Now let’s look at using these statements in an if-loop.
Let’s take the code we had earlier:


task main()
{
	while(true)
	{
		motor[port1] = value;
		motor[port2] = value;
		motor[port3] = value;
		motor[port4] = value;
	}
}

We only want the code we’ve put in there to execute whenever we press a button. Let’s say for this scenario, we want it to execute when we press the upper button.

So write the if loop:


task main()
{
	while(true)
	{
		if(vexRT[Btn6U] == 1)//1 means pressed
		{
		}
	}
}

And add the motors back in:


task main()
{
	while(true)
	{
		if(vexRT[Btn6U] == 1)//1 means pressed
		{
			motor[port1] = value;
			motor[port2] = value;
			motor[port3] = value;
			motor[port4] = value;
		}
	}
}

This code isn’t complete yet though. More in the next post.

You can also set a motor to the value of a joystick, so the farther you push the joystick the faster the motor moves. This easy, because the joystick gives values from -127 to 127, exactly what the motor needs for a power setting, so you can program it like this:

task main()
{
    while(true)
        {
            motor[port1] = vexRT[ch1];
            motor[port2] = vexRT[ch2];
        }
}

You can find some more info here: http://www.robotc.net/tutor/Cortex/cortex.php?platform=Cortex&unit=vexnetremotecontrol&lesson=1

So this code is incomplete for two reasons:

  1. What if we want to go the opposite direction?
  2. Wait a second, the motors never stop! R.I.P. Robot

So now, we need to add more if loops that execute those commands. We want it to go the opposite direction when we hit the other button and we want it to stop when we don’t press any buttons.

For this section, we’re going to use two things: operators and else-if loops.

Else-if loops are alternative if loops that will only run when the original if loop isn’t true. So if we aren’t pressing the upper button, the robot will start looking at these loops.

Operators are extra symbols that we can use in order to modify the conditions our if loop will run under. We’ll be using the “and” operator “&&”.

So let’s modify our code some more. Let’s start by adding the “&&” operator to our first loop so that we make sure that it doesn’t run when we press other buttons.


task main()
{
	while(true)
	{
		if(vexRT[Btn6U] == 1 && vexRT[Btn6D] == 0)//0 means not pressed
		{
			motor[port1] = value;
			motor[port2] = value;
			motor[port3] = value;
			motor[port4] = value;
		}
	}
}

Now we can write our else-if loop so that the motors go the opposite way. Remember, we only want this to execute if only the bottom button is pressed.


task main()
{
	while(true)
	{
		if(vexRT[Btn6U] == 1 && vexRT[Btn6D] == 0)
		{
			motor[port1] = value;
			motor[port2] = value;
			motor[port3] = value;
			motor[port4] = value;
		}
		else if(vexRT[Btn6U] == 0 && vexRT[Btn6D] == 1)//Bottom button pressed only
		{
			motor[port1] = -value;//add a negative sign for the opposite
			motor[port2] = -value;
			motor[port3] = -value;
			motor[port4] = -value;
		}
	}
}

Now see if you can write the else-if loop for stopping the motors on your own. :slight_smile:

Also, you may have to reverse some of your motors. This usually happens when you have motors mounted on opposite sides turning in opposite directions. To reverse motors, go into the motor and sensor setup. Under the motors tab, you should see your list of assigned motors. Next to each motor should be a scroll down window. Click it and select the 393 Motor option. Now you should have a checkbox in the reversed column. Check it if you want to reverse the motor. Only reverse one side of the robot(i.e. reverse the motors on either the left side or the right side.)

Once you finish all of this, you should be set.

Ok, so we tried to reset the robot because it was getting really wierd. We clicked the reset button on the microcontroller but it just started blinking red lights from vexnet and robot, and the wifi between the joystick and the robot doesn’t work. We’re just trying to get it to its original state right now lol because right now nothing is really working

Alright, you’ll have to partner the joystick and cortex again. Connect the joystick to the cortex with the usb cable, turn both of them on, and wait until the lights flash green.

We did that and it worked, but for some reason the wireless connection won’t work.

Hmmm. Are you using Vexnet 2.0 keys?

Most likely they didn’t pair correctly. Try again and exactly follow the pairing procedure:

Also, the little reset button on the controller isn’t to stop the program, if it goes crazy just turn off the robot, or if you’re connected to the computer you can stop the program in the debugger.

I’ve done the reset thingy (clicking the button and usb-ing to the PC) and the procedure found in the vexnet firmware instructions but the wifi doesn’t work. It only works when the robot and joystick are tethered, and even then only the program that I created is used – it isn’t a reset really
Is this because my battery pack is low? I’m charging it now to see if it is the problem.
Thx for all the help.

By the way yes I’m using vexnet 2.0 keys

Alright. You may or may not need to update the firmware on the keys, but let’s see if the battery pack was the problem.

We’ve updated the firmware tons of times but whenever we use the wifi it doesn’t work. When we use the tether the motors go off?

Kind of confused, thanks. According to the flow chart in http://content.vexrobotics.com/docs/VEXnet_Cortex_UserGuide_081811.pdf

the problem is firmware but we’ve done it so many times that it can’t be. (As in it said download complete, etc. and we set the default to on and downloaded the default)

The vexnet 2.0 keys have a separate firmware utility that you’ll have to download. It’s a bit of a process…

More details here: