Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 hard to pin point my mistake
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
frank26080115




PostPosted: Thu Sep 07, 2006 10:44 pm   Post subject: hard to pin point my mistake

ok, i just entered grade 11 computer engineering, we didnt start turing yet, but this is my second day learning programming with turing by myself, yesterday i made a few simple calculators, looked at a few games you guys made (very nice btw) for examples

today i tried to make a program for an etchnsketch (spelling?) machine (i'll handle the mechanics), the program is currently supposed to simulate drawing horizontal or vertical lines only. (true diagonal lines wont be possible because i cant use turing to control motor speed, but i might make it zig zag)

i ran it and fed it values increasing by 10, that means each action by a motor should take the same amount of time, but after it goes into a loop, at one point, the amount of time will double, i checked for a mistake but i couldnt find it.

code:
View.Set ("text")

var startxcord : nat
var startycord : nat

var nextxcord1 : nat
var nextycord1 : nat

var nextxcord2 : nat
var nextycord2 : nat

var xdist1 : nat
var ydist1 : nat

var xdist2 : nat
var ydist2 : nat

var xdir1 : string
var ydir1 : string

var xdir2 : string
var ydir2 : string

var restart : string

%Begin

put "Input Start X Coordinate"
get startxcord

if startxcord > 100 then
    put "Invalid"
    put "100 is the maximum"
    put "Input Valid Start X Coordinate Again"
    put "Or the Program will Crash"
    get startxcord
    put "Input Start Y Coordinate"
    get startycord
else
    put "Input Start Y Coordinate"
    get startycord
end if

if startycord > 100 then
    put "Invalid"
    put "100 is the maximum"
    put "Input Valid Start Y Coordinate Again"
    put "Or the Program will Crash"
    get startycord
else
end if

if startxcord >= 1 then
    put "X Axis Motor Rotation Beginning"
    put "Please Wait for ", startxcord * 99, " Seconds"
    %PC.ParallelPut (port : int, value : int)
    delay (startxcord * 99)
    %PC.ParallelPut (port : int, value : int)
    put "X Axis Motor Rotation Finished"
else
    put "X Axis Motor not Instructed to Rotate"
end if

if startycord >= 1 then
    put "Y Axis Motor Rotation Beginning"
    put "Please Wait for ", startycord * 99, " Seconds"
    %PC.ParallelPut (port : int, value : int)
    delay (startycord * 99)
    %PC.ParallelPut (port : int, value : int)
    put "Y Axis Motor Rotation Finished"
else
    put "Y Axis Motor not Instructed to Rotate"
end if

put "Device in Starting Position"
put "Please Insert Tool"
put "When Ready, Press ANY Key and Enter"
get restart

%in start pos
%to next

put "Input Next X Coordinate"
put "Or Input Current X Coordinate to Set Y Coordinate"
get nextxcord1

if nextxcord1 > 100 then
    put "Invalid"
    put "100 is the maximum"
    put "Input Valid Next X Coordinate Again"
    put "Or the Program will Crash"
    get nextxcord1
    put "Next X Coordinate is ", nextxcord1
else
    put "Next X Coordinate is ", nextxcord1
end if

%x only

if nextxcord1 > startxcord then
    xdist1 := nextxcord1 - startxcord
    xdir1 := "Right / Positive"
    put "X Axis Motor Rotation Beginning"
    put "Direction is: ", xdir1
    put "Please Wait for ", xdist1 * 99, " Seconds"
    %PC.ParallelPut (port : int, value : int)
    delay (xdist1 * 99)
    %PC.ParallelPut (port : int, value : int)
    put "X Axis Motor Rotation Finished"
    put "Press ANY Key and then Enter to Continue"
    get restart
    put "Input Next Y Coordinate"
    put "Or Input Current Y Coordinate to Set X Coordinate"
    get nextycord1
elsif nextxcord1 < startxcord then
    xdist1 := startxcord - nextxcord1
    xdir1 := "Left / Negative"
    put "X Axis Motor Rotation Beginning"
    put "Direction is: ", xdir1
    put "Please Wait for ", xdist1 * 99, " Seconds"
    %PC.ParallelPut (port : int, value : int)
    delay (xdist1 * 99)
    %PC.ParallelPut (port : int, value : int)
    put "X Axis Motor Rotation Finished"
    put "Press ANY Key and then Enter to Continue"
    get restart
    put "Input Next Y Coordinate"
    put "Or Input Current Y Coordinate to Set X Coordinate"
    get nextycord1
elsif startxcord = nextxcord1 then
    put "X Axis Motor not Instructed to Rotate"
    put "Input Next Y Coordinate"
    put "Or Input Current Y Coordinate to Set X Coordinate"
    get nextycord1
else
    put "Error, Please Restart Program"
end if

%y only

if nextycord1 > startycord then
    ydist1 := nextycord1 - startycord
    ydir1 := "Up / Positive"
    put "Y Axis Motor Rotation Beginning"
    put "Direction is: ", ydir1
    put "Please Wait for ", ydist1 * 99, " Seconds"
    %PC.ParallelPut (port : int, value : int)
    delay (ydist1 * 99)
    %PC.ParallelPut (port : int, value : int)
    put "X Axis Motor Rotation Finished"
    put "Press ANY Key and then Enter to Continue"
    get restart
    put "Input Next X Coordinate"
    put "Or Input Current X Coordinate to Set Y Coordinate"
    get nextxcord2
elsif nextycord1 < startycord then
    ydist1 := startycord - nextycord1
    ydir1 := "Down / Negative"
    put "Y Axis Motor Rotation Beginning"
    put "Direction is: ", ydir1
    put "Please Wait for ", ydist1 * 99, " Seconds"
    %PC.ParallelPut (port : int, value : int)
    delay (ydist1 * 99)
    %PC.ParallelPut (port : int, value : int)
    put "Y Axis Motor Rotation Finished"
    put "Press ANY Key and then Enter to Continue"
    get restart
    put "Input Next X Coordinate"
    put "Or Input Current X Coordinate to Set Y Coordinate"
    get nextxcord2
elsif startycord = nextycord1 then
    put "Y Axis Motor not Instructed to Rotate"
    put "Input Next X Coordinate"
    put "Or Input Current X Coordinate to Set Y Coordinate"
    get nextxcord2
else
    put "Error, Please Restart Program"
end if

loop

    %x2 only

    if nextxcord2 > nextxcord1 then
        xdist2 := nextxcord2 - nextxcord1
        xdir2 := "Right / Positive"
        put "x2 only"
        put "X Axis Motor Rotation Beginning"
        put "Direction is: ", xdir2
        put "Please Wait for ", xdist2 * 99, " Seconds"
        %PC.ParallelPut (port : int, value : int)
        delay (xdist2 * 99)
        %PC.ParallelPut (port : int, value : int)
        put "X Axis Motor Rotation Finished"
        put "Press ANY Key and then Enter to Continue"
        get restart
        put "Input Next Y Coordinate"
        put "Or Input Current Y Coordinate to Set X Coordinate"
        get nextycord2
    elsif nextxcord2 < nextxcord1 then
        xdist2 := nextxcord1 - nextxcord2
        xdir2 := "Left / Negative"
        put "x2 only"
        put "X Axis Motor Rotation Beginning"
        put "Direction is: ", xdir1
        put "Please Wait for ", xdist1 * 99, " Seconds"
        %PC.ParallelPut (port : int, value : int)
        delay (xdist2 * 99)
        %PC.ParallelPut (port : int, value : int)
        put "X Axis Motor Rotation Finished"
        put "Press ANY Key and then Enter to Continue"
        get restart
        put "Input Next Y Coordinate"
        put "Or Input Current Y Coordinate to Set X Coordinate"
        get nextycord2
    elsif nextxcord1 = nextxcord2 then
        put "X Axis Motor not Instructed to Rotate"
        put "Input Next Y Coordinate"
        put "Or Input Current Y Coordinate to Set X Coordinate"
        get nextycord2
    else
        put "Error, Please Restart Program"
    end if

    %y2 only

    if nextycord2 > nextycord1 then
        ydist2 := nextycord2 - nextycord1
        ydir2 := "Up / Positive"
        put "y2 only"
        put "Y Axis Motor Rotation Beginning"
        put "Direction is: ", ydir2
        put "Please Wait for ", ydist2 * 99, " Seconds"
        %PC.ParallelPut (port : int, value : int)
        delay (ydist2 * 99)
        %PC.ParallelPut (port : int, value : int)
        put "X Axis Motor Rotation Finished"
        put "Press ANY Key and then Enter to Continue"
        get restart
        put "Input Next X Coordinate"
        put "Or Input Current X Coordinate to Set Y Coordinate"
        get nextxcord1
    elsif nextycord2 < nextycord1 then
        ydist2 := nextycord1 - nextycord2
        ydir2 := "Down / Negative"
        put "y2 only"
        put "Y Axis Motor Rotation Beginning"
        put "Direction is: ", ydir2
        put "Please Wait for ", ydist2 * 99, " Seconds"
        %PC.ParallelPut (port : int, value : int)
        delay (ydist2 * 99)
        %PC.ParallelPut (port : int, value : int)
        put "Y Axis Motor Rotation Finished"
        put "Press ANY Key and then Enter to Continue"
        get restart
        put "Input Next X Coordinate"
        put "Or Input Current X Coordinate to Set Y Coordinate"
        get nextxcord1
    elsif nextycord1 = nextycord2 then
        put "Y Axis Motor not Instructed to Rotate"
        put "Input Next X Coordinate"
        put "Or Input Current X Coordinate to Set Y Coordinate"
        get nextxcord1
    else
        put "Error, Please Restart Program"
    end if

    %x1 only

    if nextxcord1 > nextxcord2 then
        xdist1 := nextxcord1 - nextxcord2
        xdir1 := "Right / Positive"
        put "x1 only"
        put "X Axis Motor Rotation Beginning"
        put "Direction is: ", xdir1
        put "Please Wait for ", xdist1 * 99, " Seconds"
        %PC.ParallelPut (port : int, value : int)
        delay (xdist1 * 99)
        %PC.ParallelPut (port : int, value : int)
        put "X Axis Motor Rotation Finished"
        put "Press ANY Key and then Enter to Continue"
        get restart
        put "Input Next Y Coordinate"
        put "Or Input Current Y Coordinate to Set X Coordinate"
        get nextycord2
    elsif nextxcord1 < nextxcord2 then
        xdist1 := nextxcord2 - nextxcord1
        xdir1 := "Left / Negative"
        put "x1 only"
        put "X Axis Motor Rotation Beginning"
        put "Direction is: ", xdir1
        put "Please Wait for ", xdist1 * 99, " Seconds"
        %PC.ParallelPut (port : int, value : int)
        delay (xdist1 * 99)
        %PC.ParallelPut (port : int, value : int)
        put "X Axis Motor Rotation Finished"
        put "Press ANY Key and then Enter to Continue"
        get restart
        put "Input Next Y Coordinate"
        put "Or Input Current Y Coordinate to Set X Coordinate"
        get nextycord2
    elsif nextxcord2 = nextxcord1 then
        put "X Axis Motor not Instructed to Rotate"
        put "Input Next Y Coordinate"
        put "Or Input Current Y Coordinate to Set X Coordinate"
        get nextycord2
    else
        put "Error, Please Restart Program"
    end if

    %y1 only

    if nextycord1 > nextycord2 then
        ydist1 := nextycord1 - nextycord2
        ydir1 := "Up / Positive"
        put "y1 only"
        put "Y Axis Motor Rotation Beginning"
        put "Direction is: ", ydir1
        put "Please Wait for ", ydist1 * 99, " Seconds"
        %PC.ParallelPut (port : int, value : int)
        delay (ydist1 * 99)
        %PC.ParallelPut (port : int, value : int)
        put "Y Axis Motor Rotation Finished"
        put "Press ANY Key and then Enter to Continue"
        get restart
        put "Input Next X Coordinate"
        put "Or Input Current X Coordinate to Set Y Coordinate"
        get nextxcord2
    elsif nextycord1 < nextycord2 then
        ydist1 := nextycord2 - nextycord1
        ydir1 := "Down / Negative"
        put "y1 only"
        put "Y Axis Motor Rotation Beginning"
        put "Direction is: ", ydir1
        put "Please Wait for ", ydist1 * 99, " Seconds"
        %PC.ParallelPut (port : int, value : int)
        delay (ydist1 * 99)
        %PC.ParallelPut (port : int, value : int)
        put "Y Axis Motor Rotation Finished"
        put "Press ANY Key and then Enter to Continue"
        get restart
        put "Input Next X Coordinate"
        put "Or Input Current X Coordinate to Set Y Coordinate"
        get nextxcord2
    elsif nextycord2 = nextycord1 then
        put "Y Axis Motor not Instructed to Rotate"
        put "Input Next X Coordinate"
        put "Or Input Current X Coordinate to Set Y Coordinate"
        get nextxcord2
    else
        put "Error, Please Restart Program"
    end if

end loop


i put parallel put as a comment because i cant calibrate the machine if i havent built it yet, and i dont want to send 5v to my printer

and i saved this "transcript"

code:
Input Start X Coordinate
10
Input Start Y Coordinate
10
X Axis Motor Rotation Beginning
Please Wait for 990 Seconds
X Axis Motor Rotation Finished
Y Axis Motor Rotation Beginning
Please Wait for 990 Seconds
Y Axis Motor Rotation Finished
Device in Starting Position
Please Insert Tool
When Ready, Press ANY Key and Enter
1
Input Next X Coordinate
Or Input Current X Coordinate to Set Y Coordinate
10
Next X Coordinate is 10
X Axis Motor not Instructed to Rotate
Input Next Y Coordinate
Or Input Current Y Coordinate to Set X Coordinate
20
Y Axis Motor Rotation Beginning
Direction is: Up / Positive
Please Wait for 990 Seconds
X Axis Motor Rotation Finished
Press ANY Key and then Enter to Continue
1
Input Next X Coordinate
Or Input Current X Coordinate to Set Y Coordinate
10
X Axis Motor not Instructed to Rotate
Input Next Y Coordinate
Or Input Current Y Coordinate to Set X Coordinate
30
y2 only
Y Axis Motor Rotation Beginning
Direction is: Up / Positive
Please Wait for 990 Seconds
X Axis Motor Rotation Finished
Press ANY Key and then Enter to Continue
1
Input Next X Coordinate
Or Input Current X Coordinate to Set Y Coordinate
10
X Axis Motor not Instructed to Rotate
Input Next Y Coordinate
Or Input Current Y Coordinate to Set X Coordinate
40
y1 only
Y Axis Motor Rotation Beginning
Direction is: Down / Negative
Please Wait for 1980 Seconds
Y Axis Motor Rotation Finished
Press ANY Key and then Enter to Continue


notice the 1980, not supposed to happen, since i eliminated any x axis movement, it can only be something wrong with the y section

i'm sorry if i broke any programming rules or anything like format or etc

can anyone help me find the error?[/b]
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Thu Sep 07, 2006 11:13 pm   Post subject: (No subject)

there seems to be a lot of redundancy in there... way too much of that code repeats over and over again.

I suggest trying to isolate the common parts, and have this running inside a single loop. This way all your different parts work equally well (hopefully well Wink )
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
frank26080115




PostPosted: Fri Sep 08, 2006 7:37 pm   Post subject: (No subject)

stupid mistake, i put a small note before every action so to trouble shoot, then found out one variable was wrong, so all i had to do was change a cord2 to a cord1

u can lock or delete this now
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: