I am trying to use an NXT Motor with EVShield to steer my robot car.
To do so I need to have the motor go to a specific rotation consistently.
My code is this:
in setup()
center_pos = evshield.bank_a.motorGetEncoderPosition(SH_Motor_2);
global functions:
void turn_left()
{
int32_t newPos = center_pos - 30;
evshield.bank_a.motorRunTachometer(SH_Motor_2, SH_Direction_Forward, 70, newPos, SH_Move_Absolute, SH_Completion_Dont_Wait, SH_Next_Action_Float);
}
void turn_right()
{
int32_t newPos = center_pos + 30;
evshield.bank_a.motorRunTachometer(SH_Motor_2, SH_Direction_Forward, 70, newPos, SH_Move_Absolute, SH_Completion_Dont_Wait, SH_Next_Action_Float);
}
void go_straight()
{
int32_t newPos = center_pos;
evshield.bank_a.motorRunTachometer(SH_Motor_2, SH_Direction_Forward, 70, newPos, SH_Move_Absolute, SH_Completion_Dont_Wait, SH_Next_Action_Float);
}
So, in loop() I am using a timer to call these functions after a few seconds:
turn_left();
// some time later
go_straight();
// later
turn_right();
// later
go_straight();
What I am finding is that the motor seems to almost turns a random amount. It does the first turn left fine, but the go straight call seems to wayyyy over rotate the motor. Then turn right does not go to the proper spot.
Is there something else I should be doing? Is this a driver bug?
I don't see the driver for EVShield source code anywhere, otherwise I would try tweaking it. Is it open source?
Thanks for any help that can be provided.