View unanswered posts | View active topics It is currently Fri Oct 24, 2014 5:37 am






Reply to topic  [ 6 posts ] 
i keep getting this wierd error 
Author Message
Rookie

Joined: Wed Oct 22, 2008 3:32 pm
Posts: 7
Post i keep getting this wierd error
i get an error that says 7/8 is out of array bound 0...5
it happens wherever i make a command using the third or fourth 16 volt motor
how can i clear it here is my code

Code:
#pragma config(Hubs,  S1, HTMotor,  HTServo,  HTMotor,  none)
#pragma config(Motor,  motorD,          ,              tmotorNormal, openLoop, reversed)
#pragma config(Motor,  motorE,          ,              tmotorNormal, openLoop, )
#pragma config(Motor,  mtr_S1_C3_1,     motorF,        tmotorNormal, openLoop, )
#pragma config(Motor,  mtr_S1_C3_2,     baseMotor,     tmotorNormal, openLoop, )
#pragma config(Servo,  servo1,          armServo,             tServoNormal)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

//includes
#include "JoystickDriver.c"


int towerctrl;
void servoControler();
void armControl();
void motorControl();
void motorControlFixer(int excludeLow, int excludeHigh);
void baseMotorControl();

task main()
{
  while (true)
  {
    getJoystickSettings(joystick);
    armControl();
    motorControl();
    servoControler();
    baseMotorControl();
  }
}

void baseMotorControl()
{
    if (joy1Btn(1) != 0)//makes sure both 2 and 3 are not pressed at same times
    {
        if (joy1Btn(2) != 0)
        {
            return;
        }
    }
    if (joy1Btn(2) != 0)//make tower go one way
    {
        motor[baseMotor] = -25; //error here
    }
    else
    {
        if( joy1Btn(3) != 0)//make tower go other way
        {
            motor[baseMotor] = 25; //error here
        }
    }
}

void motorControlFixer(int excludeLow, int excludeHigh) //this bit seems to work fine
{
    towerctrl = joystick.joy1_Buttons; //this is so i can adjust the output
    for (int testButton = 1; testButton <= 12; testButton++)
    {
        if (testButton >= excludeLow && testButton <=  excludeHigh)//will exclude 5 - 8 used for control when from arm control; might use this for other things //so added the variables
        {
          //will not execute anything and go on for another try
        }
        else
        {
            if (joy1Btn(testButton) != 0)//if a button is pressed
           {
              towerctrl = towerctrl - 2^(testButton - 1);//will adjust using bitmap
            }
        }
    }
}


void motorControl()
{
    motor[motorD] = joystick.joy1_y1;
  motor[motorE] = joystick.joy1_y2;
}

void servoControler()
{
    if (joy1Btn(1) == 1)
    {
        servoTarget[armServo] = 255;
    }
    else
    {
        servoTarget[armServo] = 0;
    }
}

void armControl()
{
   motorControlFixer(4,9);//remove erroneous readings from buttons 1,2,3,4,9,10,11,12
  if (joystick.joy1_Buttons != 0)// if a button is pressed that was not filtered by fixer
  {
      switch (towerctrl)
      {
          case 16://button 5 pressed
            motor[motorF] = -25; //error here
            break;

        case 64://button 7 pressed
            motor[motorF] = -50; //error here
            break;

          case 80://button 5 and 7 pressed
            motor[motorF] = -100; //error here
            break;

          case 32://button 6 pressed
            motor[motorF] = 25; //error here
            break;

          case 128://button 8 pressed
            motor[motorF] = 50; //error here
            break;

          case 160://button 6 and 8 pressed
            motor[motorF] = 100; //error here
            break;

          default:
            break;
          
     }
    }
}


please help


Fri Feb 06, 2009 10:15 pm
Profile
Novice

Joined: Thu Oct 09, 2008 7:58 pm
Posts: 79
Post Re: i keep getting this wierd error
When I compiled the code you posted, i got an error on lines 2 and 3. And i can see that your motors, MotorD and MotorE aren't correctly plugged into the motors and sensors set up. Try fixing that up.


Fri Feb 06, 2009 10:53 pm
Profile
Rookie

Joined: Wed Oct 22, 2008 3:32 pm
Posts: 7
Post Re: i keep getting this wierd error
thats strange i used the gui for that it didnt ping me on mine only later


Fri Feb 06, 2009 10:55 pm
Profile
Rookie

Joined: Wed Oct 22, 2008 3:32 pm
Posts: 7
Post Re: i keep getting this wierd error
pelase i really need help!!


Sat Feb 07, 2009 9:30 pm
Profile
Novice

Joined: Fri Oct 24, 2008 8:58 am
Posts: 87
Post Re: i keep getting this wierd error
XBHS,

I made changes to the top #pragma section (which gave me errors too, I don't know how yours compiled at all)

I made only a slight change to servoControler()...don't use if(joy1Btn(x) == 1) ... just use if(joy1Btn(x))
I also fixed baseMotorControl() ...which didn't seem to work at all so I rewrote it based on your comments.
and I simplified armControl() ...which mostly worked but seemed like a difficult way to get what you wanted.

One issue that I had to guess because I couldn't quite tell if it was intentional in your code: What do you want to happen when NO buttons are pressed? Either the motors stop moving or the continue moving at the last commanded speed.

I thought it more likely you want to stop motor movement when the buttons are released, but your code wasn't doing that.
If the original logic was intentional then there is a comment in the code how to fix it back the way you had it.

Although, you didn't have ANY way of stopping the motor once started so I figured it was a mistake to begin with.

Code:
#pragma config(Hubs,  S1, HTMotor,  HTServo,  HTMotor,  none)

#pragma config(Motor,  mtr_S1_C1_1,     motorD,        tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C1_2,     motorE,        tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C3_1,     motorF,        tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C3_2,     baseMotor,     tmotorNormal, openLoop)
#pragma config(Servo,  servo1,          armServo,             tServoNormal)

//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#include "JoystickDriver.c"


void servoControler();
void armControl();
void motorControl();
void baseMotorControl();

task main()
{
  while (true)
  {
    getJoystickSettings(joystick);
    armControl();
    motorControl();
    servoControler();
    baseMotorControl();
  }
}

void baseMotorControl()
{
  int basePower = 0;

  if (joy1Btn(2))
    basePower -= 25;  // make tower go one way

  if (joy1Btn(3))
    basePower += 25;  // Make tower go the other way

  // Note: pressing both 2 & 3 is the same as pressing none at all

  motor[baseMotor] = basePower;
}

void motorControl()
{
  motor[motorD] = joystick.joy1_y1;
  motor[motorE] = joystick.joy1_y2;
}

void servoControler()
{
    if (joy1Btn(1))
    {
        servoTarget[armServo] = 255;
    }
    else
    {
        servoTarget[armServo] = 0;
    }
}

void armControl()
{
  int motorPwr = 0;

  if(joy1Btn(5))
    motorPwr -= 25;

  if(joy1Btn(7))
  {
    if (joy1Btn(5))
      motorPwr -= 75;
    else
      motorPwr -= 50;
 }


  if(joy1Btn(6))
    motorPwr += 25;

  if(joy1Btn(8))
  {
    if (joy1Btn(6))
      motorPwr += 75;
    else
      motorPwr += 50;
 }

 // Note: Pressing nothing stops the motor (which is different than your code, but it seems correct)
 // if want motion even after the button is released then uncomment the next line:
 // if (motorPwr != 0)
 motor[motorF] = motorPwr;
}


I never got your error. But this code compiles and runs for me.
Obviously I couldn't test it on a robot, but I ran in on my NXT while watching the motor outputs. It seems to do what your comments were saying it should (except all the "error here" comments I didn't understand at all)

If you still get the error then reload the RobotC firmware and try again.

Good luck


Sat Feb 07, 2009 11:10 pm
Profile
Rookie

Joined: Wed Oct 22, 2008 3:32 pm
Posts: 7
Post Re: i keep getting this wierd error
thanks


Sun Feb 08, 2009 2:34 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 6 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.