Programming Help Please

My program is not working
It is not doing what I want it to do. I have attached a photo below

I want to be able to do three things…
-have constant power to the arm motors(4 of them) at a value of 10
-Raise the arm at full power
-Lower the arm at full power

My program won’t work because…
-The cortex gets confused since there are two contradicting true statements so it keeps switching between the two lines of code that are both true.

This should be an easy fix, its just my incompetence in programming. I have attached a photo below. Please help, thanks.
Arm wont work.jpg

Great questions get quick answers.

You need some “else” statements so only one set of the four SetMotor commands run. Something like this.

if( ArmRaise == 1 )
    SetMotor( 6, 127 );
    SetMotor( 7, 127 );
    SetMotor( 8, -127 );
    SetMotor( 9, -127 );
if( ArmLower == 1 )
    SetMotor( 6, -127 );
    SetMotor( 7, -127 );
    SetMotor( 8, 127 );
    SetMotor( 9, 127 );
    SetMotor( 6, 10 );
    SetMotor( 7, 10 );
    SetMotor( 8, -10 );
    SetMotor( 9, -10 );

Okay I see, thanks. But what about when the variables equal to 0, like (armraise==0)? How do you do that? Because I think that like that the motors will keep spinning and not stop after letting go of the button on the joystick.

In psuedo code form, it reads like this.

If( the arm raise button is pushed )
    run the motors to raise the arm
else if ( the arm lower button is pushed )
    run the motors to lower the arm
else no buttons are pushed so
    run the motors to hold the arm

If neither button is pressed then the final “else” statement is true and the arm motors will be sent the holding power.

Ohhhh, okay thank you. I get it now.

Is it good practice to run the motors to hold the arm? It seems as though the motors would get almost “worn-out” from being constantly ran? We’ve been balancing the force of the arm with rubber bands to get the arm to hold at the intended level. Is it a good practice? :confused::confused::confused:

It’s best to avoid this situation if you can (it’s best to balance things as much as possible with elastics), but I think that it’s generally safe to “drive” or “hold” a motor at a value of up to about 15 for long periods of time without risk of overheating it. You can have the motor hold for somewhat more, maybe about 30 or so, for perhaps (I’m guessing) 20 seconds or so without overheating, too. However, much depends on what the motor was doing before the “hold” and it might even depend on the particular motor.

We have a robot that holds 6 lift motors at a power of “8” when no joystick input is detected. The reason is to maintain the position of the lift. It works great for us.

We have not had any trouble with it. It doesn’t cause them to overheat or trip and ptc’s, even with dozens of minutes of practice driving.

I run my motors at 16 to keep my lift up. Should I decrease it to like 10 or something?

A motor value of 16 would probably be okay but your experience is the best gauge of what to use. If everything works with 16 and you don’t see any problems, then stick with it.

I’ll try a value of 10. Thing is, when I have rubberbands on my lift, adding more already makes the arm go up on its own, probably because there is too much power already at 16.

My recommendation now that I’ve used arm hold on all my robots, is that it is always a good thing to have implemented in your code. Rubber bands are essential, and help, but motor idle increases lift stability and responsivenes a lot.

Balance the lift with elastics before putting in the idle in the code.
Just never put idle above 25, and if you think the lift has plenty of power to keep the lift up, lower the idle value to save battery life when you’re testing or practicing.

Do you know if it’s possible to do this, but where it only holds when the potentiometer is higher than a certain number?

Yes, something like this should be possible. For example, using RobotC my kids created a task that did nothing but command their cube intake motor to hold at a value of 15 so the cubes in their intake would not fall out. They start the task when they push a button assigned for that purpose, but such a task could easily be started or allowed to start only when a pot is above a certain value.

The task continues running on its own while they do other things. Then the task is stopped when they push any other buttons that control the cube intake. Essentially, they use an IF statement to start the “hold cubes” task and they stop the task whenever any of the other cubes intake buttons are pressed. The code requires the use of booleans (AND and maybe OR operators) in their IF statements.

As a programming exercise this is great but if where you put start task you set the motors at 15 power it would eliminate the need for the task. As long as nothing else is setting the motor power between when you set it to 15 and when you want to change it the motors should just run at 15 forever. Remember that motors just keep doing what they are told and don’t need to be constantly reminded.

Yes, that is true, and that’s a very good point.

here is what i did and it works really well. having an idle motor power of 10 is the best, 20 is just a little to much and heats up the motors really quickly
something that works.jpg