Recording the PS2 controller actions/movements to play it back automatically.

Hi there,

What I'm trying to achieve may or may not be possible witn an arduino but basically I've managed to install a PS2 controller to drive a robot, so far so good.

I d'like to ask the Arduino community if there's a way to record every move and every buttons I press with the delays inbetween each different actions in order to record X min of a specific movement and make the robot do it again later on by itself.

In other words, I d'like to do X min of movements/actions myself with the controller, save it and then make the robot do the exact same actions at the exact same time.

Do you think this is even remotely possible?

Any help on that matter would be much appreciated :)

Thanks

Sounds plausible. I’d be inclined to ignore the controller inputs and just record what instructions the arduino issued to the robot as a consequence of them, as well as a millis timestamp.

A likely issue will be finding space to store the data - you may need to consider sending it to an SD card.

Thanks for your answer,

Right, size may be an issue. I'll add a Raspberry Pi if needed.

Yes, ignoring the controller would be easier but for what I want, a controller is needed and in a sense ... easier ::)

In a sense, the serial.writing function is already allowing us to display every buttons/moves made with a PS2 controller in the serial monitor. That would be kinda similar to it I guess.

If anyone has any idea on how to do it, I would love to hear it :)

Hm I think I misread you, you said that it would be better to record the actions made by the robot issued by the controller rather than the controller itself? That's in fact what I'm trying to achieve. I don't really mind not having the "Pushed the PSB_X button" information as long as I have the result of the "action" recorded somewhere. Any ideas on how to implement it?

I think I'd keep a set of data that indicated the current state of the robot. i.e. the position of each servo and the state of each digital output. That data might as well be stored in a class or struct, but needn't be if preferred.

When recording the robot's actions, on each iteration of loop, calculate the desired new state of the robot and if it is different from the current state in the struct, record the changes and the time.

You could invent a little language to store that data and store an entry for each change in an array of structs. Each would need the value of millis when the change occurred,or at least how long into the recording it was. Then a couple of characters would suffice to describe the action required: character one to describe what component of the robot to operate on, character two to be the numeric data. In the case of the digital pins, whether HIGH or LOW, for the servos - degrees.

You might want to make a more human readable version of the data that you could read in from off the arduino.

For playback, you read through the array and check whether it's time to set the robot to a new state and then parse the two chars to tell you what to change.

There's no consideration given here to any sensors the robot might be using - looking at your existing code though, I don't see any.

Thanks for your answer.

I see, it's not gonna be easy knowing that my code knowledge is close de 0 but I'll see what I can do. Yes there's no sensors on that robot for the moment. Everything is controlled directly from the PS2 controller, and if I do things right, then it wouldn't need any sensors.

You should be able to do this if you can capture the raw data from the controller. How precise does this need to be, because you are going to be limited to your arduino's memory.

However if you record the data straight to an SD card, the memory usage will be quite minimal.

Added: you should set a time interval to record the data. ie read controller once per second, once every half second, quarter second ... and make sure if write the time interval to the arduino somewhere and same goes for the SD card.

Was this ever resolved?

I'm finding myself with a very similar situation. Although I also need to know if I can go into the code after recording and make minor edits as needed ( delete a specific action, bring together two separate recordings, or reduce the speed robot ).