comands

im trying to make a funtion for my arm motors. nothing i try works please help, sample code would help the best. theres for motors in the function comand

Can you explain in a little more detail what you are trying to do?

Do you just want a function to send the same command value to all four (??) motors on your arm?

Are you using EasyC or ROBOTC? What have you tried so far?

yes, RobotC

function arm(int power) {
motor[m_arm1] = power;
motor[m_arm2] = power;
}

int armTarget = 0;
task ArmP() {
float kP = 0.5;
while(true) {
int error = armTarget-nMotorEncoder[m_arm1];
arm(error*kP);
}
}

Does any of that help?
The arm() function applies the same power to both arm motors.
The ArmP() task sets the arm in a proportional loop so you can tell it what encoder value to go to. You’d have to mess around with the variables.

Takes a deep breath… Dreams of the day someone actually answers a question I ask in a detailed and thoughtful way.

Anyway, is this what you want?

#pragma config(Motor,  port2,           armMotor_1,    tmotorVex393, openLoop)
#pragma config(Motor,  port3,           armMotor_2,    tmotorVex393, openLoop)
#pragma config(Motor,  port8,           armMotor_3,    tmotorVex393, openLoop, reversed)
#pragma config(Motor,  port9,           armMotor_4,    tmotorVex393, openLoop, reversed)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

// Control the arm
// The arm has four motors
// armMotor_1 and armMotor_2 are on the left side
// armMotor_3 and armMotor_4 are on the right side and are reversed

void
armDrive( int speed )
{
    motor armMotor_1 ] = speed;    
    motor armMotor_2 ] = speed;    
    motor armMotor_3 ] = speed;    
    motor armMotor_4 ] = speed;    
}

task main()
{
    int x;
    
    while(1)
        {
        // Ch2 controls the arm
        if( abs(vexRT Ch2 ]) > 10 )
            x = vexRT Ch2 ];
        else
            x = 0;
        
        // send the control value (x) to the arm
        armDrive( x );

        // Don't hog the cpu
        wait1Msec(25);
        }
}

that went in one side out the other
this is ive been taught before

// Arm Control

	lift_command = vexRT[Ch3Xmtr2];
	if(SensorValue[limitSwitch] == 1 && lift_command < 0)
	{
	lift_command = 0;
	}

	motor[leftArm2]  = lift_command;  // Left Joystick Y value
	motor[leftArm3]  = lift_command;
	motor[rightArm2] = lift_command; // Right Joystick Y value
	motor[rightarm3] = lift_command;   // Right Joystick Y

I don’t mean to sound rude but you are providing us with hardly any information at all. Please be very clear about what you want to do and why it isn’t working.

One potential problem is that that code is meant for Joystick 2 (hence the Xmtr2) but we cannot be sure what is going wrong without a complete code sample.

You should probably just post your whole program and tell us very specifically what you want to do and why it isn’t working.

When you post code, press the “#” button. Two tags will appear:
CODE ] /CODE ]. Paste your code in between there and it will appear formatted much more nicely:


Like this!

oh for crying out loud can anyone who speaks english help

help

Are you kidding me? We all speak English just fine. You can’t even spell “commands” or “four” nor do you bother with basic punctuation and capitalization.

Please read this guide about how to ask questions on the web. You are not being clear with what’s wrong, you are not giving us your full source code, and you are being stubborn. You won’t even answer our questions.

When James asked:

You answered 1 out of 5 questions:

We are trying to help you; James even wrote an entire program which will do exactly what I believe you want. Nobody is going to write a 10 page manual for you.

Get off your high horse. We are not your slaves nor are we your personal programmers. Please post your full code sample, explain what you want it to do and what it is doing instead. This is not difficult.

Edit: So I removed my earlier somewhat more inflammatory comment, but the fact remains that your attitude is out of line.

Is this what you are after?

// Control the arm
// The arm has four motors

void
armDrive( int speed )
{
    motor[leftArm2]  = speed;
    motor[leftArm3]  = speed;
    motor[rightArm2] = speed;
    motor[rightarm3] = speed;
}

task main()
{
    int lift_command;
    
    while(1)
        {
        // Ch3 on partner joystick controls the arm
        lift_command = vexRT[Ch3Xmtr2];
        if(SensorValue[limitSwitch] == 1 && lift_command < 0)
            {
            lift_command = 0;
            }
        
        // send the control value (x) to the arm
        armDrive( lift_command );

        // Don't hog the cpu
        wait1Msec(25);
        }
}

Ok I’m going to try and start with more basic stuff because this sort of remark is usually caused by not understanding what is going.

A variable is something that is replaced by something else, so if X = 127, and the program sees you using X in a place where a number should be, it will think of it as 127.

This is jpearman’s example in pieces:

// Control the arm
// The arm has four motors

void//----------------------------------1
armDrive( int speed )//--------------2
{//-------------------------------------3
    motor[leftArm2]  = speed;//-----4
    motor[leftArm3]  = speed;//-----5
    motor[rightArm2] = speed;//----6
    motor[rightarm3] = speed;//----7
}//------------------------------------8

This creates a function, which can be referred to later. When you see ‘void’ (which is in line 1) you know that a function is being created.

This function sets the arms to a speed which is determined by the variable ‘speed’. ‘speed’ is “declared” (which means created) in line 2 where the name of the function, armDrive is also declared.

Now when the main task starts, you can call on this function by putting a value in the place of ‘int speed’.

For instance:


task main()
{
armDrive(127)
}

This would make the arm move at 127 (top speed).

This:


armDrive(127)

is the same as this:


motor[leftArm2]  = 127;
motor[leftArm3]  = 127;
motor[rightArm2] = 127;
motor[rightarm3] = 127;

because the function armDrive replaces all of it using the variable ‘speed’.


task main()
{
    int lift_command;
    
    while(1)
        {
        // Ch3 on partner joystick controls the arm
        lift_command = vexRT[Ch3Xmtr2];
        if(SensorValue[limitSwitch] == 1 && lift_command < 0)
            {
            lift_command = 0;
            }
        
        // send the control value (x) to the arm
        armDrive( lift_command );

        // Don't hog the cpu
        wait1Msec(25);
        }
}

In this code you will see first the main task start. The first thing it does is declare lift_command a variable (an integer to be specific).

The next thing is it starts a while loop (while(1) means while(true) which means whatever is in the while loop will run forever).

Next it sets the integer lift_command to be equal to the x values of the partner joystick’s left analog stick.

Then it asks an if statement: if the sensor value of the limit switch (which might, for instance, prevent the arm from going too low and pressing into the ground) is 1 (aka pressed) AND the variable lift_command (which is the x values on the partner joysticks left analog stick) is less than zero, then lift_command becomes 0, and the arm won’t move.

Next the function armDrive is called. It says armDrive(lift_command);, so lift_command is taking the place of speed. This will set all the lift motors to whatever speed lift_command is.

Finally there is a wait command. It waits for 25 milliseconds, or 1/40 of a second.

So in this example there are two variables, lift_command and speed.

In your example code, you were not using any variables.

What do you want the variables to do?

A: I’m going to be an engineer not a flipping journalists so lay off
B: I posted before going to bed(I’m working out of my house) so I didn’t spell check
C: “get off my high horse” really last I checked helping was optional
D: My code probably wasn’t enough to go on but it’s all I’ve been taught so I haven’t LEARNED enough to work with.
E: keyboard doesn’t always type what I wanted to.

More importantly, thank you to jpearman who was able to simplify the code instead of insulting.

journalist*, and engineers need to be able to communicate their ideas clearly just the same as journalists.

I would not have criticized you for it had it not been for your comment about us not speaking English.

It is, and I am helping by pointing out to you that you are acting out of line. If I didn’t care I wouldn’t have posted at all. I want you to learn that the way you are talking is not going to get you anywhere. I suppose James’s post didn’t do much to reinforce that, but the point remains that if you want help you need to be a little bit nicer.

The problem is that you were not clear about what you wanted, not that you haven’t learned enough. Instead of hastily asking before bed, we ask that you spend some time formulating a thoughtful question explaining exactly what you want, what you have tried, and why it didn’t work. Helping is absolutely voluntary and we want to help but get quickly aggravated when the person asking for help is unwilling to even put in the effort to clearly ask for what they want.

You expect people to help you with extensive, clear responses and you won’t even bother to make sure the “keyboard typed what you wanted it to.”

James is a very patient person, but I think he made it quite clear that he was upset with your posts:

I hope in the future you will be a little kinder on the forums and put a bit more thought into your posts.

I edited my original rather incendiary remark, despite what I though it’s not appropriate for me to make that kind of comment. We have generally managed to keep the standards high on this forum, if questions are carefully asked then they will receive quality answers.

Just a quick reminder that the VEX Forums exist to communicate and share ideas as well as lend assistance to help others. Please be mindful of negative comments and responses that appear to be sarcastic in nature.

It has been said, if you have nothing good to say, say nothing.

When I first joined these forums, I posted similar threads asking for help and I was met with answers that seemed to just ask for more details and criticize my post. I was frustrated, too, but it’s important to remember that these people are taking time out of their day to try to help you. The least you can do is give them information about your problem that can make it easier to help you more effectively.

If you don’t understand their posts, try googling some of the terms they are using to gain some background knowledge on what they’re saying, or tell them exactly what it is that’s confusing you so they can explain it better.

I hope you keep this in mind when others seem to bug you for more details and spout gobbledygook. They just want to help you better. :slight_smile:

Also thanks to frydaddy07 for simplyfying the process even further for me

Glad to help

I can make some sense of to make a function now, but when I tried imputing the code these are the errors I got.

Error:Internal Compiler: Unexpected use of proc ‘armDrive’ in an expression
Warning:Invalid ‘=’ operation for types ‘void’ and ‘char’
Error:Internal Compiler: Unexpected use of proc ‘armDrive’ in an expression
Warning:Invalid ‘=’ operation for types ‘void’ and ‘char’
Error:Internal Compiler: Unexpected use of proc ‘armDrive’ in an expression
Warning:Invalid ‘=’ operation for types ‘void’ and ‘char’

here’s the code

void
armDrive( int speed
{
motor[leftArm] = speed;
motor[leftArm2] = speed;
motor[rightArm] = speed;
motor[rightarm2] = speed;
}

task main
{
// Arm Control
if(vexRT[Btn5U] == 1 )//if button 6U is pressed the flap will go up
{
armDrive = 127;
}
else
if(vexRT[Btn5D] == 1 )
{
armDrive = -127;
}
else
{
armDrive = 0;
}
}

It looks a little different than the earlier code because that other code was last years.

Dont mind this part “//if button 6U is pressed the flap will go up” that was a screw up I didn’t see until I posted; it’s just a little bit of self-reminders I forgot to change.