Compass: Motor Control Problem with NXC

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
mindcharlie1
Posts: 4
Joined: 17 Mar 2011, 08:12

Compass: Motor Control Problem with NXC

Post by mindcharlie1 »

I got problems as below, hope someone could help me, I really appreciate your time.

NXC Motor Control Problem, I have only put the main part of the program with problems:

#define compass IN_2
#define pointer OUT_A

ResetRotationCount(pointer);
heading1=SensorHTCompass(compass);
RotateMotor(pointer, 60, heading1);
Wait(200);

heading1=SensorHTCompass(compass);
Wait(600);
heading2=SensorHTCompass(compass);
heading_change=heading1-heading2;

while(true)
{
ResetRotationCount(pointer);
// The full speed of the motor is 170 RPM (rotation per minute), calculate the manually rotating

// speed according to the angle changes and the full rotation speed.
V_Ctrller=abs(((heading_change/0.1)*100)/(170*360/60));

if(abs(heading_change)!=0)
{
//RotateMotor(pointer, 20, heading_change); Wait(100);

if((heading2>=0)&&(heading2<=180))
{
RotateMotor(pointer, V_Ctrller, heading_change);
//RotateMotor(pointer, 20, heading_change);
Wait(60);
}
else if((heading2>=180)&&(heading2<=359))
{
RotateMotor(pointer, V_Ctrller, abs(heading_change));
//RotateMotor(pointer, 20, abs(heading_change));
Wait(60);
}

Purpose: I’m trying to make a mechanical compass, use the motor point north for all the time. However, it’s not functioning very well.
Problem 1: The motor will stop rotating after a short period time of running the program if I’m using the command below
RotateMotor(pointer, V_Ctrller, abs(heading_change));
However, if I replace variable “V_Ctrller” with value 20 (speed), the program will be running for all the time.
Problem 2: Some time the motor will not rotate with the set value “heading_change”, and it will be rotating and fluctuating for a very large degree.
Problem 3: I tried to reduce the sampling time between two heading detection with compass sensor, however, if I’m changing my heading of the compass sensor slowly, the motor will not rotate according to the changes.
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests