View unanswered posts | View active topics It is currently Sat Aug 02, 2014 1:46 am






Reply to topic  [ 4 posts ] 
Need quick TeleOp Help! 
Author Message
Rookie

Joined: Sun Jan 23, 2011 11:24 am
Posts: 5
Post Need quick TeleOp Help!
I keep getting this error from my code:

Byte Code Interpreter Exception:

Program Slot: 0, Task ID:main[0]
Error at PC: Sub: PowerFromJoystick+0x005E
Task PC: Task offset start (0).
TaskState: "Exception"
Exception Type: "Real Address Range Exception(59)"


I dont know why this keeps popping up. My code will compile fine, but just wont download and run. Help would be greatly appreciated.
Here is my code if that helps at all:

#pragma config(Hubs, S1, HTMotor, HTMotor, none, none)
#pragma config(Motor, motorA, kickMotor, tmotorNormal, PIDControl, encoder)
#pragma config(Motor, motorB, leftGrabber, tmotorNormal, PIDControl, encoder)
#pragma config(Motor, motorC, rightGrabber, tmotorNormal, PIDControl, encoder)
#pragma config(Motor, mtr_S1_C1_1, leftMotors, tmotorNormal, PIDControl, encoder)
#pragma config(Motor, mtr_S1_C1_2, rightMotors, tmotorNormal, PIDControl, encoder)
#pragma config(Motor, mtr_S1_C2_1, armMotors, tmotorNormal, openLoop, reversed)
#pragma config(Motor, mtr_S1_C2_2, motorG, tmotorNormal, openLoop)

#include "JoystickDriver.c"

//PowerFromJoystick
//
// Joysticks Return x and y coordinates ranging from -128 to +127
// The power range for the motors is from -100 to +100. This function
// Takes a joystick value (x or y) and returns a power value scaled
// to the motor's power range. This is true for the NXT motors and
// the Tetrix 12V motors.
//
int PowerFromJoystick(int y)
{
int power;
int sign;

if (y < 0)
sign = -1;
else
sign = 1;
// There can be some fluctuations when the joystick is pegged to
// a maximum or minimum value. Keep the power steady.

if (abs(y) >= 127)
power = 100 * sign;
else if (abs(y) < 10) // We can also get fluctuations at idle.
power = 0; // If we very are close to 0 force us to 0.
else
power = (y * 100) / 127; // Normal case, just scale the value.

return -power; // Negate all joystick values to match motor configuration.
}

task main ()
{
while (true)
{
getJoystickSettings(joystick);

// Vert axis of left joystick
motor[leftMotors] = PowerFromJoystick(joystick.joy1_y1);

// Vert axis of right joystick
motor[rightMotors] = PowerFromJoystick(joystick.joy1_y2);
}
}


Sun Jan 23, 2011 9:57 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3170
Location: Rotterdam, The Netherlands
Post Re: Need quick TeleOp Help!
This works:
Code:
int PowerFromJoystick(int y)
{
  // There can be some fluctuations when the joystick is pegged to
  // a maximum or minimum value. Keep the power steady.
 
  if (abs(y) >= 127)
    return 100 * sgn(y);    // sgn() returns -1, 0 or +1, depending on sign
  else if (abs(y) < 10)     // We can also get fluctuations at idle.
    return 0;               // If we very are close to 0 force us to 0.

  return -1 * ((y * 100) / 127);  // Normal case, just scale the value and negate
  // can be replaced with:
  // return (y * -100) / 127);
}

task main ()
{
  // Vert axis of left joystick
  nxtDisplayTextLine(2,"%d", PowerFromJoystick(100));
 
  // Vert axis of right joystick
  nxtDisplayTextLine(4,"%d", PowerFromJoystick(-100));
  wait1Msec(10000);

}


The problem was the "return -power;", "return -1 * power;" fixed the issue, but I thought I'd make your code a bit nicer in the process. I used the sgn() function to check if the number is negative or positive.

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Mon Jan 24, 2011 3:39 am
Profile WWW
Rookie

Joined: Sun Jan 23, 2011 11:24 am
Posts: 5
Post Re: Need quick TeleOp Help!
ok so this is my new code:

Code:
#pragma config(Hubs,  S1, HTMotor,  HTMotor,  none,     none)
#pragma config(Motor,  motorA,          kickMotor,     tmotorNormal, PIDControl, encoder)
#pragma config(Motor,  motorB,          leftGrabber,   tmotorNormal, PIDControl, encoder)
#pragma config(Motor,  motorC,          rightGrabber,  tmotorNormal, PIDControl, encoder)
#pragma config(Motor,  mtr_S1_C1_1,     leftMotors,    tmotorNormal, PIDControl, encoder)
#pragma config(Motor,  mtr_S1_C1_2,     rightMotors,   tmotorNormal, PIDControl, encoder)
#pragma config(Motor,  mtr_S1_C2_1,     armMotors,     tmotorNormal, PIDControl, reversed, encoder)
#pragma config(Motor,  mtr_S1_C2_2,     motorG,        tmotorNormal, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

/////////////////////////////////////////////////////////////////////////////////////////////////////
//
//                           Tele-Operation Mode Code Template
//
// This file contains a template for simplified creation of an tele-op program for an FTC
// competition.
//
// You need to customize two functions with code unique to your specific robot.
//
/////////////////////////////////////////////////////////////////////////////////////////////////////

#include "JoystickDriver.c"  //Include file to "handle" the Bluetooth messages.


/////////////////////////////////////////////////////////////////////////////////////////////////////
//
//                                    initializeRobot
//
// Prior to the start of tele-op mode, you may want to perform some initialization on your robot
// and the variables within your program.
//
// In most cases, you may not have to add any code to this function and it will remain "empty".
//
/////////////////////////////////////////////////////////////////////////////////////////////////////

void initializeRobot()
{
  // Place code here to sinitialize servos to starting positions.
  // Sensors are automatically configured and setup by ROBOTC. They may need a brief time to stabilize.

  return;
}


/////////////////////////////////////////////////////////////////////////////////////////////////////
//
//                                         Main Task
//
// The following is the main code for the tele-op robot operation. Customize as appropriate for
// your specific robot.
//
// Game controller / joystick information is sent periodically (about every 50 milliseconds) from
// the FMS (Field Management System) to the robot. Most tele-op programs will follow the following
// logic:
//   1. Loop forever repeating the following actions:
//   2. Get the latest game controller / joystick settings that have been received from the PC.
//   3. Perform appropriate actions based on the joystick + buttons settings. This is usually a
//      simple action:
//      *  Joystick values are usually directly translated into power levels for a motor or
//         position of a servo.
//      *  Buttons are usually used to start/stop a motor or cause a servo to move to a specific
//         position.
//   4. Repeat the loop.
//
// Your program needs to continuously loop because you need to continuously respond to changes in
// the game controller settings.
//
// At the end of the tele-op period, the FMS will autonmatically abort (stop) execution of the program.
//
/////////////////////////////////////////////////////////////////////////////////////////////////////

task main()
{
  initializeRobot();

  waitForStart();   // wait for start of tele-op phase

  int thresholdP = 10;
  int thresholdN = -10;

  while (true)
  {
    getJoystickSettings(joystick);
        if(abs((joystick.joy1_y1)) > thresholdP);

        motor[leftMotors] = (joystick.joy1_y1);

      motor[leftMotors] = 0;
    {
      motor[leftMotors] = (joystick.joy1_y1);
    }
    if(abs((joystick.joy1_y2)) > thresholdP);
    {
      motor[rightMotors] = -(joystick.joy1_y2);

      motor[armMotors] = (joystick.joy2_y2);

      motor[kickMotor] = (joystick.joy2_y1);
    }
  }
}


and it works fine except for some reason the left side motors go forward when you toggle back and the vice/versa for when you toggle forward. The same thing also happens to the right side. Can anyone help me find out why this is occuring?? thank you.


Tue Jan 25, 2011 8:34 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3170
Location: Rotterdam, The Netherlands
Post Re: Need quick TeleOp Help!
The ";" after the if statements are messing you up. I can't tell which parts are supposed to be executed when when they are TRUE, due to your lack of proper indentation in your code.

You can either have a single code statement after an "if" statement -or- open a block of code with accolades.

Code:
// Single statement after if()
if (foo == 100)
  do_something(foo);

// multiple statements in a code block
if (foo == 100)
{
    do_something(foo);
    and_another_thing(42);
}


Note the lack of ";" after the if statement. Putting a ";" after the "if" makes it not execute anything. It basically means an empty statement.

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Wed Jan 26, 2011 3:22 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 4 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.