I created a 3 wheel drive Omni wheel robot, I followed the vector approach to manually control it using joystick,
I am using 3 DC motors for driving.
Now I want to automate it to follow a sine wave, but I don't know how to approach it. I also want to control the number of cycles and amplitude of the sine wave.
If anyone have an idea on how to approach please help me.
Are you still using the joy stick? How does your robot know where the objects are located? Are you just wanting the robot to weave from left to right as it travels? If that is what you call a sine wave, how will the robot know where the sine wave begins?
After nearing to the predefined obstacles. I will be pressing a button in the joystick so that it will automatically cross the obstacles in a sine wave pattern if viewed from above.
This is the condition. I hope you understand my situation.
MrAnand:
I will be pressing a button in the joystick so that it will automatically cross the obstacles in a sine wave pattern if viewed from above.
Unless there is a wide margin for error I reckon that will be difficult to achieve without some external position reference that the robot an use - for example using ultrasound to determine the distance to an obstacle.
If you don't believe me try making an obstacle course with 3 or 4 chairs and see if you can walk through it by counting steps with your eyes shut. And remember your brain power is a lot better than an Arduino.
I think the mathematical approach would use sin() and cos() functions. Honestly with no idea of how the wheels are arranged on the robot, it's impossible to suggest any solution.
Why does it have to be sine? Why not four quarter-circles? That will look like a sine wave to most people.
I would not even start with anything as complex as a part of a circle. I would implement a sine wave as a series of steps of a stairs. Start with large steps - maybe 3 or 5 steps from horizontal to vertical - and when that works nicely increase the number of steps gradually until you get a level of smoothness you are satisfied with.
The simplest way to implement a sine wave is with a look-up table. Use a spreadsheet to calculate the X and Y positions for (say) the 3 or 5 steps needed to move through 90°. Then put those values in an array in your Arduino program and move to them one after the other. For the other quarters of the sine wave just change the sign of the X or Y values as appropriate.
Calculating sine and cosine values on an Arduino is very slow and should be avoided if possible.
Also try to avoid using floating point values. You can get the effect of (say) 152.75 using integers by storing it as 15275.
...R
PS ... please make your image visible in your Post. See this Simple Image Guide
First issue, a Omni drive system would not need to turn.
It should be able to move sideways so instead of fun to calculate arc, you simply could do a “sawtooth” avoidance.
Read push button, change to +45degree offset from base heading and simply calculate distance C in the right angle triangle formula to know how long to keep that offset before switching to -45 degree offset from base heading for the same distance.
Unless you actually just want to stick a marker on this robot and draw curves with it.
Robin2:
The simplest way to implement a sine wave is with a look-up table.
I disagree. The sin() function is the simplest. It's not the best way for a lot of purposes but for something that needs to calculate sin() maybe 10 times per second, it's a lot more efficient in programmer time than trying to devise a lookup table when you've never heard of a lookup table before. I'll always get the simplest-to-program version working first and then optimise it later if it turns out to be too slow for the other requirements of the system.
So MrAnand, can you confirm that you have X and Y movements working on your robot (the first 4 diagrams in your image) and you want the robot to move along a sin wave aligned to X or Y? Are you going to need to change this axis in the future or will the human operator turn the robot so that X or Y is aligned with the object to be avoided? Does the step approximation (for small steps) sound like it's going to work for you?
MorganS:
I disagree. The sin() function is the simplest. It's not the best way for a lot of purposes but for something that needs to calculate sin() maybe 10 times per second, it's a lot more efficient in programmer time than trying to devise a lookup table when you've never heard of a lookup table before.
To my mind the concept of making the device follow a "steps of stairs" pattern will be easier for a beginner, even if they do have to do a little research to learn about a look-up table.