View unanswered posts | View active topics It is currently Wed Jan 24, 2018 5:59 am






Reply to topic  [ 5 posts ] 
Using HT Compass sensor to rotate 
Author Message
Rookie

Joined: Sun Nov 30, 2014 4:56 am
Posts: 14
Post Using HT Compass sensor to rotate
How can I use the compass sensor to make the robot rotate 90 degrees. I am not familiar with the information inside of the tHTCM struct (offset, heading, relativeHeading) what does each one stand for, and how can I calibrate the sensor? Thanks in advance, and if there's a link to anything related I don't mind it.


Tue Jan 27, 2015 7:52 pm
Profile
Site Admin
Site Admin
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Post Re: Using HT Compass sensor to rotate
Did you look at the examples that are shipped with the driver suite?
hitechnic-compass-test1.c, for example, there's a few of them.

= 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 28, 2015 2:03 pm
Profile WWW
Rookie

Joined: Sun Nov 30, 2014 4:56 am
Posts: 14
Post Re: Using HT Compass sensor to rotate
Hey Xander,

I already tried that but I get these errors:
**Error**:Undefined procedure 'HTMCsetTarget'.
**Error**:Undefined procedure 'HTMCreadHeading'.
**Error**:Undefined procedure 'HTMCreadRelativeHeading'.


Sat Jan 31, 2015 12:14 am
Profile
Rookie

Joined: Sun Nov 30, 2014 4:56 am
Posts: 14
Post Re: Using HT Compass sensor to rotate
It is working now, I moved the header file to the same folder where the test1.c is and it worked. Thank you again


Sat Jan 31, 2015 12:17 am
Profile
Rookie

Joined: Tue Nov 10, 2015 11:12 pm
Posts: 2
Post Re: Using HT Compass sensor to rotate
Below is code that should help you set-up the compass sensor and use it to turn a set amount. Good luck with your future programming endeavors :D .

Code:
#pragma config(Sensor, S1,     compassSensor,  sensorI2CHiTechnicCompass)

task main() {
// this will link Slot 1 a index named 'nCompass'.
tSensors nCompass = S1;

// this line will tell the program that nCompass is a HiTechnicCompass sensor.
// if you are using a different type of compass sensor than you will need to set it to that one.
SensorType[nCompass] = sensorI2CHiTechnicCompass;

//first create and integer that will store the compass sensor value before you begin to turn
int startingCompassValue;

//before you start the loop that will turn the robot run the below line to set startingCompassValue to the current compass vlaue
int startingCompassValue = SensorType[nCompass];

//this while loop will say that until the compass sensor is equal to the startingCompassValue+90, keep turning left
//you can change the number '90' to set how far you want to turn.
while(SensorType[nCompass] != startingCompanssValue+90)
{
//assuming your robots motors are set up with set-up this way (with motorA on the right side when robot is facing you)
motor[motorA] = 25;
motor[motorB] = -25
}

// if you want the robot to turn the other way this code is as follows (notice the value is now '-90' and the motors turn the other way
while(SensorType[nCompass] != startingCompanssValue-90)
{
//assuming your robots motors are set up with set-up this way (with motorA on the right side when robot is facing you)
motor[motorA] = -25;
motor[motorB] = 25
}
}



note that 'startingCompassValue will not update until it is told too so make sure to write it in before the while loop. It cannot be done within the while loop as the value will keep updating and the robot is turning.


Tue Nov 17, 2015 8:24 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 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.