make a motor going back to its initial position.

Hi,
i'm wirting this program to control a motor.
i wanna know if there is a way to make the motor always go back to its initial postion.
fo exemple: I push the joystick for 4 sec, it makes a certain rotation.What i wanna do is making the motor redo the exact same rotaion but in the opposite direction so it goes back to its intitial.
Thanks a lot

How does the system know what the original position is?

unfortunatly it doesnot

Fix that, and get back to us.

with hardware ?
i wanted to know is ther a way to do that just with softawre, if there is something that invert a mouvement or a timer ?

So is your question actually:

  • I want to record how long I went forward, then go back for the same time, in the hope that it might end up in the same place, or
  • I want to record the position it's at when I start moving, and then return to that exact spot?

evadne:
So is your question actually:

  • I want to record how long I went forward, then go back for the same time, in the hope that it might end up in the same place, or
  • I want to record the position it's at when I start moving, and then return to that exact spot?

the 1 yes,
is it possible ?

ayaaaa:
the 1 yes,
is it possible ?

Yes but it will be an act of faith to hope it gets close to the start position.

You will need to be able to recognise that the joystick has moved from its mid-point, and capture the time. Then recognise when it returns to the middle, and capture that time. Subtract, and use the difference to be how long it runs the other way.

Is it an analog joystick or just one with an on/off switch each way?

You will also need hardware like a h-bridge for the motor to reverse; if you just have a single transistor it can't be reversed.

Ideally of course you’d use a stepper motor…

Ideally of course you would use an encoder attached to the motor output thus avoiding the chance of a stepper missing a step.