View unanswered posts | View active topics It is currently Thu Mar 21, 2019 3:33 am

 Page 1 of 1 [ 7 posts ]
 Print view Previous topic | Next topic
Fastest Code Execution
Author Message
Rookie

Joined: Wed Feb 09, 2011 7:28 pm
Posts: 14
Fastest Code Execution
Hello,
I am using the Hitechnic NXT gyro sensor to control our robot's turn degrees. Right now I am just testing the code on a Lego robot. I have found that the ability of the nxt to run through the code quickly seems to be inhibiting me. I have one task calculating the gyro average while having a function calculate the degrees turned. Basically, my problem is this, when the robot turns at a very slow speed, the robot stops precisely enough, but when it spins at a faster speed, it will overshoot the number of degrees I want it to spin. What is the quickest way to make the program execute?
Thanks for any help.

Here's the code: (Some things are in comments which I used to be using but am not using at the moment)

Wed Feb 09, 2011 7:58 pm
Guru

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
Re: Fastest Code Execution
I don't understand why you need to do all this complex averaging on a separate task. If you want to turn a given angle as fast as you can without overshooting, why can't you do PID controlled turn? i.e. You turn hard initially but when you are close to the target angle, the turn will slow down.

Wed Feb 09, 2011 10:03 pm
Rookie

Joined: Wed Feb 09, 2011 7:28 pm
Posts: 14
Re: Fastest Code Execution
Well, I am not all that familiar with PID, but I'm pretty that there is no way to read the angle directly off the gyro, so somehow I must use the speed and time to calculate the number of degrees I have turned. (unless there's something I don't know about) I do think that the idea of turning quickly and then slowing down sounds like a good one. Is that all you meant by PID control?

Thu Feb 10, 2011 1:15 pm
Guru

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
Re: Fastest Code Execution
Yes, that's integration. Integrating angular velocity against time gives you angle. Yes, PID control is about approaching your set target as quickly as possible but slowing down when you are almost there. But these are two separate problems. We have a gyro library module that does the integration and gives you the heading. If you want to take a look at how it is implemented, it is here:
http://proj.titanrobotics.net/hg/Frc/20 ... nxt/gyro.h
There are many articles on the Internet about PID control theory if you are interested in reading more about it:
http://en.wikipedia.org/wiki/PID_control

Thu Feb 10, 2011 1:26 pm
Rookie

Joined: Wed Feb 09, 2011 7:28 pm
Posts: 14
Re: Fastest Code Execution
 MHTS wrote:Yes, that's integration. Integrating angular velocity against time gives you angle. Yes, PID control is about approaching your set target as quickly as possible but slowing down when you are almost there. But these are two separate problems. We have a gyro library module that does the integration and gives you the heading. If you want to take a look at how it is implemented, it is here:http://proj.titanrobotics.net/hg/Frc/20 ... nxt/gyro.hThere are many articles on the Internet about PID control theory if you are interested in reading more about it:http://en.wikipedia.org/wiki/PID_control

Thanks

Thu Feb 10, 2011 1:40 pm
Rookie

Joined: Sat Jan 14, 2012 12:13 pm
Posts: 3
Re: Fastest Code Execution
 MHTS wrote:Yes, that's integration. Integrating angular velocity against time gives you angle. Yes, PID control is about approaching your set target as quickly as possible but slowing down when you are almost there. But these are two separate problems. We have a gyro library module that does the integration and gives you the heading. If you want to take a look at how it is implemented, it is here:http://proj.titanrobotics.net/hg/Frc/20 ... nxt/gyro.hThere are many articles on the Internet about PID control theory if you are interested in reading more about it:http://en.wikipedia.org/wiki/PID_control

The header file won't load in my robotc, I'm trying to understand the gyro better, but I can't seem to figure out how to time the calculations accurately. I get many errors when including the header file, gyro.h, example:

The small bit of code it starts out the errors with:

 Code:voidGyroCal(    __out GYRO &gyro,    __in  int numSamples,    __in  int calInterval    ){

File "demo.c" compiled on Mar 28 2012 20:04:55
*Warning*:Variable '__out' declaration must be qualified with type. Type 'short' used.
**Error**:Ummatched left parenthesis '('
**Error**:Expected->')'. Found 'GYRO'
**Error**:No body declared for procedure
**Error**:Expected->'}'. Found 'GYRO'
**Error**:Type mismatch with previous 'const' declaration for variable with same name
**Error**:Expected->';'. Found 'int'
**Error**:Duplicate variable declaration of '__in'
**Error**:Expected->';'. Found 'int'
**Error**:Missing ';' before ')'
**Error**:Unexpected scanner token-> ')'

 Code:#pragma config(Sensor, S1,     Touch,          sensorTouch)#pragma config(Sensor, S2,     gyro,           sensorI2CHiTechnicGyro)#pragma config(Sensor, S3,     Color,          sensorCOLORFULL)#pragma config(Motor,  motorB,          Right,         tmotorNormal, PIDControl, encoder)#pragma config(Motor,  motorC,          Left,          tmotorNormal, PIDControl, encoder)//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//# "gyro.h"

Wed Mar 28, 2012 9:19 pm
Guru

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
Re: Fastest Code Execution
Add the following lines before you include gyro.h, like this:
 Code:#define __in#define __out#define __inout#define TFuncName(s)#define TLevel(n)#define TEnter()#define TExit()#include "gyro.h"

That should take care of all the related errors.

Wed Mar 28, 2012 10:07 pm
Display posts from previous:  Sort by
 Page 1 of 1 [ 7 posts ]

#### Who is online

Users browsing this forum: No registered users and 1 guest

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

Search for:
 Jump to:  Select a forum ------------------ ROBOTC Applications    ROBOTC for LEGO MINDSTORMS       Third-party sensors    ROBOTC for CORTEX & PIC    ROBOTC for VEX IQ    ROBOTC for Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    Mini Urban Challenge    CS2N Robot Virtual Worlds Competitions       VEX Skyrise Competition 2014-2015       VEX Toss Up 2013-2014       FTC Block Party! 2013-2014    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions Virtual Brick Robotics Discussions    General Discussions    Project Discussions Off-Topic ROBOTC Forum & ROBOTC.net Suggestions/Feedback    ROBOTC Forums Suggestions/Comments    ROBOTC.net Suggestions/Comments       NXT Programming: Tips for Beginning with ROBOTC       VEX Programming: Tips for Beginning with ROBOTC    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    International Forums       Spanish Forums          ROBOTC for MINDSTORMS          ROBOTC for VEX       French Forums          ROBOTC pour Mindstorms          ROBOTC pour IFI VEX       Japanese Forums （日本語のフォーラム）       German Forums    2015 Spring Carnival Event    PLTW (Project Lead The Way)    Robotics Merit Badge    2014 Robotics Academy Summer of Learning