programming question

Ok here is the concept

Input from transmitter on Channel 5
Checks the status of limit switch A and B

If A is 0 (Open) and B is 0 (Open)
Then motor port 1 travels CW to Limit switch B and stops when limit switch B is 1 (Closed)
(Ends here to wait for input to cycle again)

If A is 1 (Closed) and B is 0 (Open)
Then motor port 1 travels CW to limit switch B and stops when limit switch B is 1 (Closed) Led 16 lights to indicate limit activation.
(Ends here to wait for input to cycle again)

If A is 0 (Open) and B is 1 (Closed)
then motor port 1 travels CCW to limit switch A and stops when limit switch A is 1 (Closed) Led 15 Lights to indicate limit activation.
(Ends here to wait for input to cycle again)

If A is 1 (Closed) and B is 1 (Closed)
Then motor remains stopped and LED1 flashes 5 times at 1/2 second off 1/2 on
(Ends here to wait for input to cycle again)

Here is what it is doing so far. I’m very inexperienced at programming less than 1 week worth.

I’ve managed to get the motor to move clockwise (CW) to limit switch b. but when it activates limit switch b it moves counterclockwise (CCW) to limit switch a. and the cycle just keeps going on and on. I have the indicator LED’s working when the switch is pressed they light up and when no longer pressed they go off.

I am working with Easy C v2. Having lots of fun but the programming insert for the inventers guide isn’t all that in depth. and the help files are great but I’m just not getting the understanding of it.I click the examples and checked the sample code but theres just no explanation of why… I’m thinking of taking a programming class at the local community college but not sure what kind of language Easy c is… I’m going to go out on a limb and say it’s C but may not be the same version.

here is my code. I’m sure it could use some cleaning up.

1 #include “Main.h”
2
3 Void main ( Void )
4 {
5 int limita = 0;
6 int limitb = 0;
7 int rx5 = 1;
8 char x;
9 char x2;
10
11 SetDigitalOutput ( 1 . 1 ) ;
12 SetDigitalOutput ( 3 . 1 ) ;
13 SetDigitalOutput ( 16 . 1 ) ;
15 while ( 1 == 1 )
16 {
17 for ( x=0 ; x<=0 ; x++ )
18 {
19 limita = GetDigitalInput ( 2 ) ;
20 limitb = GetDigitalInput ( 15 ) ;
21 if (limita == 0)
22 {
23 SetDigitalOutput ( 3 . 0 ) ; //Limit lamp on
24 SetMotor ( 1 . 110 ) ;
25 }
26 else if ( limitb == 1)
27 {
28 SetDigitalOutput ( 3 . 1 ) ; //Limit lamp off
29 SetDigitalOutput ( 16 . 1 ) ;
30 }
31 else
32 {
33 SetDigitalOutput (16 . 0 ) ;
34 }
35 }
36 for ( x2=0 ; x2<=0 ; x2++ )
37 {
38 limita = GetDigitalInput ( 2 );
39 limitb = GetDigitalInput (15 );
40 if ( limitb == 0 )
41 {
42 SetMotor ( 1 . 154 ) ;
43 }
44 else
45 {
46 }
47 }
48 }
49 }

P.S.
Does anyone know of a simple way to get the code output like this without having to type it? Was a bit intense. and i’m completly responsible for typo’s.

Whew… Stumbled across some sample code and tore it apart learned a whole bunch… While it’s not a routine like I was hoping for it’s good code. Tests great on my test rig. The sample was included on the cd which I later found copied on my hdd in a totally different area than where I thought it would be… thats besides the point… Now if I could just figure out how to slow the motors down… Where can i upload the code? …Now to get the nephew ungrounded so we can finish the truck itself.

Looking at your Programming Issue, will get back to you on it…

Here is a Trick, works with EasyC v2, but not with EasyC Pro (v3) I need to report that…

  1. Load your EasyC Project.

  2. Click the Project Tab at the Bottom of the Left Window.

  3. The Left Window changes to show the different files than make up the project.

  4. DOUBLE Click on the Main.c file under Source Files.

  5. The Window on the Right shows the Source Code for the Main Function.

  6. On the Right Window, Right Click on it and the Click, Select All.

  7. Now Right Click and then Click, Copy.

  8. Click the Child Window Close Button (The ‘X’ in the upper Right corner), to Close the Main.h Source Windows and see your EasyC Drag-and-Drop Window again.

The entire Source Code of the Main.c Module is in the Windows Clipboard.

NOW, On Vex Forum…

  1. Start your Thread, or Reply or Quote, whatever it takes to get the Editor Box.

  2. Use the Tags CODE, around your Source Code.

(I type the Code Tags in, (e.g. CODE ] /CODE ], with no spaces between the Brackets and the words CODE and /CODE), and then Paste from the Clipboard right between them.)

When done like this, it looks like this:

#include "Main.h"

void main ( Void )
{
   int limita = 0;
   int limitb = 0;
   int rx5 = 1;
   char x;
   char x2;

   ...

The CODE Tags also preserve the Tabs and White Space, so your Source Code stays nicely indented…

BTW, EasyC Pro (v3) will let you click the Project Tab, but won’t show you any of the Source Files. I find this a very discouraging bug… Makes it real hard to Copy the Code out…

The EasyC Samples are quite valuable… The Older Versions of EasyC located them with the EasyC System in the Program Files directory. Vista (and Windows 7) don’t like that, so the Samples were Re-Located to the Users Profile Directory.

I have Questions…

Your Pseudo Code Logic is more complete than you Code, but there are Holes Still in it

As Documented, the Fourth State, can never be obtained, [FONT=Courier New](A is 1) and (B is 1)[/FONT] unless the Motor is at Both End simultaneously, unless you want to detect that each of the ends has been reached at some point in the run of the program.

Can you fill in a few more details…

I actually have 4 -5 pages of comments on your code, but the further I go, the more Paths I have to consider without knowing how you want to proceed…

Correct the 4th state should mechanically never be possible unless a failed switch. and thus the reason for the possibility for the code. don’t want to drive it into a switch that has failed. the equal is also turn if the switch doesn’t make contacts then it will never know it has reached the limit. So in all actuality the 4th state can be omitted.

If you would like you can click my name and send me a pm with your questions and i can answer them. it actually goes back to my email and not on site anymore i think there was a post talking about the pm feature being disabled at some point. or i’ll just post it here and hope no bots see it.
i d m i l l e r @ y a h o o . c o m. of course no spaces.

Also it will give me an oppurtunity to send you the code i got working which does what i’m looking for but requires constant user input for travel and i’d like it a little more automated.

I was quite proud that the code actually works as intended and it only took 37 hours this weekend to do 90 lines… hehe. but the knowledge i gained was well worth the time spent. I also have some pics of the frame work i’m going to try and get posted this afternoon. i just got off work (3rd shift) and had a rough day yesterday so i’m pretty beat.

and in refrence to the PID in another thread i do belive the 1st generation encoders will not work with that so going to have to get a couple packs of the quads.

thanks for everything. you’ve pointed me in alot of right directions and shown alot ideas i wasn’t aware of.

The new code and your idea to get the code out was perfect and easy.

#include "Main.h"

void main ( void )
{
      int loop = 1; 
      int Steer; 
      int SteerUpperlimit; 
      int SteerLowerLimit; 
      int Dump; 
      int DumpUpperLimit; 
      int DumpLowerLimit; 
      int Drive; 

      // Foward and Reverse, Left and Right Motors. 1, 2 
      // Dump Lift Motor 7 
      // Steer Lift Motor 8 
      // Steer Upper Limit Switch 5 
      // Steer Lower Limit Switch 6 
      // Dump Upper Limit Switch 7 
      // Dump Lower Limit Switch 8 
      // Dump Upper Limit LED 13 (red) 
      // Dump Lower Limit LED 14 (red) 
      // Steer Upper Limit LED 15 (red) 
      // Steer Lower Limit LED 16 (red) 
      SetDigitalOutput ( 16 , 1 ) ; // Steer Lower Limit Off
      SetDigitalOutput ( 15 , 1 ) ; // Steer Upper Limit Off
      SetDigitalOutput ( 14 , 1 ) ; // Dump Up Limit Off
      SetDigitalOutput ( 13 , 1 ) ; // Dump Down Limit Off
      SetDigitalOutput ( 12 , 1 ) ; // Strobe Off
      SetDigitalOutput ( 11 , 1 ) ; // Horn Off
      while ( loop == 1 )
      {
            Arcade2 ( 1 , 3 , 4 , 1 , 2 , 0 , 0 ) ; // Drive Signal RX1CH3CH4
            Steer = GetRxInput ( 1 , 1 ) ; // Steer Lift Signal RX1CH1
            SteerUpperlimit = GetDigitalInput ( 5 ) ; // Steer Upper Limit
            SteerLowerLimit = GetDigitalInput ( 6 ) ; // Steer Lower Limit
            if ( SteerUpperlimit == 0 ) // Steer Upper Limit
            {
                  SetDigitalOutput ( 15 , 0 ) ; // Steer Upper Limit Active
            }
            else
            {
                  SetDigitalOutput ( 15 , 1 ) ; // Steer Upper Limit Off
            }
            if ( SteerLowerLimit == 0 ) // Steer Lower Limit
            {
                  SetDigitalOutput ( 16 , 0 ) ; // Steer Lower Limit Active
            }
            else
            {
                  SetDigitalOutput ( 16 , 1 ) ; // Steer Lower Limit Off
            }
            if ( SteerUpperlimit  == 0 && Steer <= 128 )
            {
                  Steer = 127 ;
            }
            if ( SteerLowerLimit == 0 && Steer >= 128 )
            {
                  Steer = 127 ;
            }
            SetPWM ( 8 , Steer ) ;
            Dump = GetRxInput ( 1 , 2 ) ; // Dump Signal RX1CH2
            DumpUpperLimit = GetDigitalInput ( 7 ) ; // Dump Upper Limit
            DumpLowerLimit = GetDigitalInput ( 8 ) ; // Dump Lower Limit
            if ( DumpUpperLimit  == 0 ) // Dump Upper Limit
            {
                  SetDigitalOutput ( 13 , 0 ) ; // Dump Upper Limit Active
            }
            else
            {
                  SetDigitalOutput ( 13 , 1 ) ; // Dump Upper Limit Off
            }
            if ( DumpLowerLimit == 0 ) // Dump Lower Limit
            {
                  SetDigitalOutput ( 14 , 0 ) ; // Dump Lower Limit Active
            }
            else
            {
                  SetDigitalOutput ( 14 , 1 ) ; // Dump Lower Limit Off
            }
            if ( DumpUpperLimit == 0 && Dump  <= 128 )
            {
                  Dump = 127 ;
            }
            if ( DumpLowerLimit == 0 && Dump  >= 128 )
            {
                  Dump = 127 ;
            }
            SetPWM ( 7 , Dump ) ;
      }
}

http://i49.photobucket.com/albums/f291/immille/IMG_0001.jpg

http://i49.photobucket.com/albums/f291/immille/IMG_0002.jpg

http://i49.photobucket.com/albums/f291/immille/IMG_0003.jpg

http://i49.photobucket.com/albums/f291/immille/IMG_0005.jpg

you do know that with the length of your base and only 2 motor drive and no omni wheels, it would be imposable for it to turn right?
i would shorten it a bit and if the rest of your design doesn’t allow that, then at least have 4 motor drive
the 5" wheels also might have too much friction, im not sure on that one though
nvm i thought your gearing was 1:1
but i still think it will have a hard time turning

Yes i sure do. Thats what this whole thread was about I’m looking to automate a lift sequence to lift the frame off the ground. the device is not present in the photos because i havn’t found an acceptable idea yet to mount the lift that won’t look too far out there. It has 2 omni directional wheels that are 90 perpendicular to the drive wheels so it uses the 2 rear wheels to turn.

Actually the gear ratio is working really well it’s not nearly as slow as i thought it was going to be about a foot every 6 seconds. speed wasn’t a concern as much as letting him use his imigination. and giving experience to my nephew of why some things are better.

that is correct. i’ll have to go back and count the gear ratio if you would like. can’t remember it right off the top of my head.

Thanks for the post though.

Finished product hope the link works

http://www.youtube.com/watch?v=csM60W1erng