I have the DC Gear Motor 24V/5.1Kg-cm/588RPM 4.25:1 DC Gear Motor (version 3269_3) and the encoder HKT22. Now I want to create a Java application to rotate the motor by given degrees. The user can enter e.g. 60 degrees or e.g. -60 degrees.
I create my own example code and the motor is rotating for a given time (e.g. 5000 ms).
But I´m not sure how can I manage it to rotate the motor by given degrees. I think I have to calculate something.
In my later application I would have every second a other degree and I want do move the motor every second e.g. -10 degrees or +25 degrees.
I want to do something like autosteering. The motor should rotate the steering wheel.
With which classes can I manage this?
Code: Select all
DCMotor dcMotor0 = new DCMotor();
Encoder encoder0 = new Encoder();
dcMotor0.open(1000);
encoder0.open(5000);
dcMotor0.setTargetVelocity(0.2);
encoder0.addPositionChangeListener(new EncoderPositionChangeListener()
{
public void onPositionChange(EncoderPositionChangeEvent e)
System.out.println("PositionChange: " + e.getPositionChange());
System.out.println("TimeChange: " + e.getTimeChange());
System.out.println("IndexTriggered: " + e.getIndexTriggered());
System.out.println("----------");
}
});
Thread.sleep(5000);
dcMotor0.close();
encoder0.close();