Controlling Robot Through Java

Discussion in 'Programming' started by demonlord07, Aug 30, 2013.

  1. #1
    Hello my good friends, i'm trying to build a Java program that when run controls a robot hand to move blocks. I have got a fair bit of the code working so far but i'm afraid i've run into a bit of a problem with moving the blocks. It just doesn't seem to work.

    I have the height of all bars set to 4 and the height of all blocks set to 3. Basically what i need done is to transport each of the blocks in the source pile (column 10) and drop them off on top of the bars - the robot can only drop one block on each bar and the first block must be dropped off on top of the left-most bar (column 3). Subsequent blocks should be dropped off on the next vacant bar to the right.

    Here is a picture of how it should look,

    [​IMG]

    When implementing this control mechanism you must move each of the sections of the robot arm using a loop to call the corresponding arm movement method as many times as is required.

    Here is the code i have so far,

    import javax.swing.*;
    
    class RobotControl
    {
        private Robot r;
    
        public RobotControl(Robot r)
        {
            this.r = r;
        }
    
        public void control(int[] barHeights, int[] blockHeights)
        {
    controlMechanismForStageA(barHeights, blockHeights);
    }
    public void controlMechanismForStageA(int barHeights[],
                int blockHeights[])
        {
            r.slowDown(2);
    int h = 2;
            int w = 1;
            int pickerHeight = 1;
    int sourceHeight;
            int blockHeight;
           
            int sourceLocation;
            int targetBarIndex;
            int maxBarHeight;
    while (pickerHeight < 10)
            {
                r.up();
                pickerHeight++;
            }
    
    Code (markup):
    Anyone able to help me with this? Please and thankyou.
     
    demonlord07, Aug 30, 2013 IP