programming problem

I am a newbie in programming and my english language skills are rudimentary. Could anyone be kind enough to teach me how I could hold the arm position without pressing any buttons? How could this program be written? Could any of you guys provide me with a few samples for referencing? Very thanks

Welcome to the forums.

Tell us a bit more about your robot, what type of arm system do you have, how many motors etc. Also let us know which programming environment you are using and what you have tried so far.

thx for your reply.
-Our arm system is “Four-Bar”
-We are using four motors
-EasyC v4
-Actually,we read some kinds of post in this forum.They suggested to use PID or ‘add new function’ in EasyC. However, there are too difficult for us. can guys provide some simple and easiest program for us?

There are posts discussing this type of issue on the forum, here is one from last year.

https://vexforum.com/t/arm-help/19650/1

I assume your arm is lowering under the weight of the sacks and gravity. To hold the arm at a given position you need to counteract this force with an equal force pushing up. You can do this by either adding something physical, typically rubber bands, or by using the motors to apply a constant upwards force. The problem in using the motors is that they are then in a stall condition and you need to be careful they don’t overheat (by which I mean trip the internal thermal fuse) or cause the cortex/power expander PTC to trip.

There are two ways (perhaps more) to program this.

  1. Use the PID control you have already read about.
  2. Instead of sending 0 to the motors send a small value that causes the arm to hold instead. This value is probably somewhere about 20 but you need to experiment. If the value needed goes over around 30 you are in the danger zone for tripping PTCs.

As far as I know this cannot be done using the built in EasyC functions like JoystickToMotor or whatever so you will at least need to program the reading of joystick position and sending that value to the motors.

you mention that “2. Instead of sending 0 to the motors send a small value that causes the arm to hold instead. This value is probably somewhere about 20 but you need to experiment. If the value needed goes over around 30 you are in the danger zone for tripping PTCs.”

Where can i do this in EasyC? thx

Here is a trivial example, I don’t really recommend this type of control without further logic to be able to remove all power to the motors if they overheat and the PTCs trip, however, if you really need some code to get to going…

#include "Main.h"

void OperatorControl ( unsigned long ulTime )
{
    int Ch2; 

    while ( 1 ) // Insert Your RC Code Below
        {
        // Get the joystick value 
        Ch2 = GetJoystickAnalog( 1 , 2 );
        
        // Don't use near the center of the joystick
        if ( (Ch2 > 20) || (Ch2 < -10)  )
            {
            // Send joystick value to motor if outside deadband 
            SetMotor ( 1 , Ch2 ) ;
            }
        else
            {
            // Send holding power to motor 
            SetMotor ( 1 , 20 ) ;
            }
      }
}

But please search the forums some more, there are some other examples posted and some more complex code in the code repository. For example, Josh posted an EasyC PID example here

https://vexforum.com/local_links.php?action=jump&catid=26&id=229

Thx for your teaching. I can hold the arm position now
But I have another problem. When I raise up the arm through the joystick, the motors were not smooth. Is it the programming problem? How can i solve?

I have no idea. It may be code, I don’t know what your code looks like, perhaps you are trying to send motor commands from more than one function. It may be a mechanical problem, but I’ve never seen your robot so how could I know.

I think what jpearman is saying is that you should post the code you are running and supply pictures of your arm mechanism at the very least so that we can help you more.

Okay! I will post it on Monday or Tuesday because i am not at school





Can you tell me more details about PID? How to use it?thx

The robot design looks reasonable, the tower probably need a bit more support and you could reduce the spacing so the axle lengths are shorter but otherwise 5:1 gearing with 4 393 motors will probably lift a few sacks. As a comparison, one of the 8888 teams has a design using two 393 motors with 8.3:1 gearing and can lift 6 sacks without problem using 2 393 motors and no elastic assistance. The potentiometer may not work where you have mounted it, it will depend on the angular change of the 4 bar, for example, if the 4 bar can move through 90 deg then, due to gearing, the motor (and potentiometer) will move through 5x90 = 450 deg. This is greater than the range of a pot which is 270 deg max (more usefully around 200 deg). Simple solution is to mount the pot on one of the output axles.

Are you planning to post software? I still cannot answer your original question about motor smoothness.

For an overview of PID this paper is a good starting point.

http://igor.chudov.com/manuals/Servo-Tuning/PID-without-a-PhD.pdf

This thread has a guide on PID that George wrote a few months ago.

https://vexforum.com/t/pid-programming-guide/21877/1

The built in PID control for EasyC rely on the IMEs and I don’t think will work with a pot so you will have to create your own.

yes~thx for your reminder~

Is there any problems in this programme? Can you edit it for us?thx a lot!!:slight_smile:

Think about the logic.

If c5_down == 1 then you set the motors to 127 (why is one -127? ). Next you test c5_up and if that is not pressed you set the motors to 0. So the motors will be getting commands to run then stop then run etc. You need another else as follows.

if( c5_down == 1 )
    {
    SetMotor( 4, 127 );
    SetMotor( 5, -127 ); // ??? is this correct
    SetMotor( 6, 127 );
    SetMotor( 7, 127 );
    }
else
if( c5_up == 1 )
    {
    SetMotor( 4, -127 );
    SetMotor( 5, 127 );
    SetMotor( 6, -127 );
    SetMotor( 7, -127 );
    }
else
    {
    SetMotor( 4, 0 );
    SetMotor( 5, 0 );
    SetMotor( 6, 0 );
    SetMotor( 7, 0 );
    }
if( c5_down == 1 )
    {
    SetMotor( 4, -127 );
    SetMotor( 5, -127 ); // ??? is this correct
    SetMotor( 6, 127 );
    SetMotor( 7, 127 );
    }
else
if( c5_up == 1 )
    {
    SetMotor( 4, 127 );
    SetMotor( 5, 127 );
    SetMotor( 6, -127 );
    SetMotor( 7, -127 );
    }
else
    {
    SetMotor( 4, 0 );
    SetMotor( 5, 0 );
    SetMotor( 6, 0 );
    SetMotor( 7, 0 );
    }

(i sent the wrong code and this is the right one.)

According your code that you have provided, can you include the code which can be hold the arm position?thx a lot~

Adding it isn’t super difficult but in my opinion you should give it a shot for yourself just so it makes more sense to you what it is doing and why.

+1, do some experiments, make some mistakes, see what happens and if you are still stuck we can help some more.

We don’t understand the guide of PID because it has involved physical and out of our knowledge:confused:. So we are very very very need the example of PID for hold the arm position. Thank you for your help!