Nxt shut off in autonomous.
| Author |
Message |
|
mightor
Moderator
Joined: Wed Mar 05, 2008 8:14 am Posts: 2864 Location: Rotterdam, The Netherlands
|
 Re: Nxt shut off in autonomous.
I can't test this at the moment, I'm at my dad's place in the south of France, chopping trees and I don't have my NXTs with me.
The gyro driver not overly complex though, it's basically just an analogue sensor. I may be able to test it next week, Monday or Tuesday, no guarantees, though.
- Xander
_________________| Some people, when confronted with a problem, think, "I know, I'll use threads," | and then two they hav erpoblesms. (@nedbat)| My Blog: I'd Rather Be Building Robots| ROBOTC 3rd Party Driver Suite: [ Project Page]
|
| Tue Jan 10, 2012 11:54 am |
|
 |
|
MHTS
Guru
Joined: Sun Nov 15, 2009 5:46 am Posts: 1023
|
 Re: Nxt shut off in autonomous.
If I have time tonight (e.g. getting stuck on the FRC CANJaguar code), I may download the code and try it on my little NXT test mobile which has a gyro but not any of the Tetrix motors or servos.
|
| Tue Jan 10, 2012 5:02 pm |
|
 |
|
MHTS
Guru
Joined: Sun Nov 15, 2009 5:46 am Posts: 1023
|
 Re: Nxt shut off in autonomous.
I loaded the code Tim has modified to my test mobile and made some modificatons myself since I don't have Tetrix motors and servos (modified code below). I successfully compiled, downloaded and ran the code. The robot jerked forward and turn round and round forever. At least it didn't hang or crash the NXT. So just like Tim, I can't reproduce your problem. Aside from the behavior is probably not what you intended, the code works fine. You may want to try downloading the NXT firmware again just in case it did not match your RobotC version.  |  |  |  | Code: #pragma config(Sensor, S3, gyro, sensorI2CCustom) #pragma config(Motor, motorA, motorRight, tmotorNormal, PIDControl, encoder) #pragma config(Motor, motorC, motorLeft, tmotorNormal, PIDControl, encoder) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
#include "JoystickDriver.c" //Include file to "handle" the Bluetooth messages. #include "gyro.h" #include "Encoders12.h"
#define BOUND(n, l, h) (((n) < (l))? (l): ((n) > (h))? (h): (n))
GYRO g_Gyro; float g_turnTarget = 0.0; bool g_turnEnabled = false; float g_turnTolerance = 0.5; //needs to be tuned float g_turnKp = 50.0; //needs to be tuned float g_driveTarget = 0.0; bool g_driveEnabled = false; float g_driveTolerance = 0.3; float g_driveKp = 50.0;
void SetTurnTarget(float angle) { GyroReset(g_Gyro); g_turnTarget = angle; g_turnEnabled = true; }
void TurnTask() { if (g_turnEnabled) { float error = GyroGetHeading(g_Gyro) - g_turnTarget; if (abs(error) > g_turnTolerance) { // // Simple proportional PID control. // Limit the outpout to the range of -70 to 70. // int turnPower = BOUND((int)(g_turnKp*error), -100, 100); motor[motorLeft] = turnPower; motor[motorRight] = -turnPower; } else { motor[motorLeft] = 0; motor[motorRight] = 0; g_turnEnabled = false; nxtDisplayTextLine(7, "err=%f", error); } nxtDisplayTextLine(3, "Heading=%f", GyroGetHeading(g_Gyro)); nxtDisplayTextLine(6, "target=%f,tol=%f", g_turnTarget, g_turnTolerance); } }
float GetDriveDistance() { return (float)(nMotorEncoder[motorLeft] + nMotorEncoder[motorRight])/2.0*INCHES_PER_CLICK; }
void SetDriveTarget(float distance) { nMotorEncoder[motorLeft] = 0; nMotorEncoder[motorRight] = 0; GyroReset(g_Gyro); g_driveTarget = distance; g_driveEnabled = true; }
void DriveTask() { if (g_driveEnabled) { float driveErr = g_driveTarget - GetDriveDistance();
if (abs(driveErr) > g_driveTolerance) { // // Simple proportional PID control. // Limit the outpout to the range of -100 to 100 for drive // and -50 to 50 for turn // int drivePower = BOUND((int)(g_driveKp*driveErr), -100, 100); float turnErr = GyroGetHeading(g_Gyro); int turnPower = BOUND((int)(g_turnKp*turnErr), -100, 100); motor[motorLeft] = BOUND(drivePower + turnPower, -100, 100); motor[motorRight] = BOUND(drivePower - turnPower, -100, 100); nxtDisplayTextLine(7, "drvErr=%f", driveErr); } else { motor[motorLeft] = 0; motor[motorRight] = 0; g_driveEnabled = false; } nxtDisplayTextLine(4, "Distance=%f", GetDriveDistance()); } }
void initializeRobot() { #if 0 servoTarget[Mag1] = 127; servoTarget[leftflap3] = 17; servoTarget[rightflap4] = 252; servoTarget[forkL7] = 83; servoTarget[forkR8] = 83; servoTarget[MagR5] = 0; #endif // 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. GyroInit(g_Gyro, gyro, 0);
return; }
task main() { int step = 0;
StopTask(displayDiagnostics); eraseDisplay(); initializeRobot(); // waitForStart(); // Wait for the beginning of autonomous phase. while (true) { GyroTask(g_Gyro);
nxtDisplayTextLine(5, "Step=%d", step); switch (step) { //*****************************Drive Back Parking Zone************************************* case 0: // step 0: go forward. SetDriveTarget(48.0); step++; break;
case 1: // step 1: wait for drive to complete. if (g_driveEnabled == false) { step++; } break;
case 2: // step 2: turn 90 left degrees. SetTurnTarget(90.0); step++; break;
case 3: // step 3: wait for drive to complete. if (g_turnEnabled == false) { step++; } break;
case 4: // step 2: Left Flap Out. #if 0 servoTarget[leftflap3] = 135; #endif SetDriveTarget(72.0); step++; break;
case 5: // step 3: wait for drive to complete. if (g_driveEnabled == false) { step++; } break;
case 6: // step 2: Left Flap In #if 0 servoTarget[leftflap3] = 0; #endif ClearTimer(T1); step++; break;
case 7: // step 3: wait for drive to complete. if (time1[T1] > 500) { step++; } break;
}
TurnTask(); DriveTask(); wait1Msec(10); } } |  |  |  |  |
|
| Wed Jan 11, 2012 6:38 am |
|
 |
|
Team2844
Novice
Joined: Mon Oct 18, 2010 9:31 pm Posts: 79
|
 Re: Nxt shut off in autonomous.
Thanks guys for helping here. I am going to try this out tommorow if I can, and see if it crashes or not, as I do not have the robot with me at this time.
|
| Thu Jan 12, 2012 1:41 am |
|
 |
|
Team2844
Novice
Joined: Mon Oct 18, 2010 9:31 pm Posts: 79
|
 Re: Nxt shut off in autonomous.
Ok, so I tryed to run them, and it still wont run for me. Are there any updateds of drivers from last year? Is that what may be causing the problems?
When I went to run this time, I turned on the audiable feedback, and it will beep a few times, before crashing the NXT. The NXT starts to click afterward, as if Im downloading fireware on to it.
Thanks
|
| Fri Jan 13, 2012 7:02 pm |
|
 |
|
MHTS
Guru
Joined: Sun Nov 15, 2009 5:46 am Posts: 1023
|
 Re: Nxt shut off in autonomous.
You should always download the latest RobotC (it is now version 3.05) from http://www.robotc.net/ftc and the corresponding NXT drivers. You also need to update the firmware on the NXT that matches the RobotC version. Please do that before we go further because with mismatching components, anything could happen.
|
| Fri Jan 13, 2012 7:07 pm |
|
 |
|
Team2844
Novice
Joined: Mon Oct 18, 2010 9:31 pm Posts: 79
|
 Re: Nxt shut off in autonomous.
..... Dont you just love these little things... haha. Updated everything, and what do you know, the autonomous works.. Now I just need to get the turning to stop..
Thanks
|
| Fri Jan 13, 2012 11:39 pm |
|
 |
|
Team2844
Novice
Joined: Mon Oct 18, 2010 9:31 pm Posts: 79
|
 Re: Nxt shut off in autonomous.
All good. Everything is fixed, Autonomous written. Thanks everyone.
|
| Fri Jan 13, 2012 11:56 pm |
|
|
Who is online |
Users browsing this forum: No registered users and 0 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
|
|