Trouble mapping output to unusual coordinate space

John J.A. Jannone's icon

I'm trying to control the motors of a Scribbler robot with a pictslider.

I've figured out what the x/y values of all the cardinal points need to be (see attached image)

but I'm having a heck of a time actually getting those values out in Max.

I've tried approaches using nodes, expr, table, and I'm just finding it mind-bending, although I suspect it's rather simple.

2830.trouble.tiff
tiff
laonikoss's icon

The way you have put the points around the [pictslider] (which works with linear 2-dimensional cartesian coordinates) is not going to work (to the best of my knowledge and understanding).

As far as I can see, the coordinates you have used seem to be entirely normal cartesian coordinates, rotated 45 degrees.

Maye I ask how you arrived at those coordinates? And do you ONLY want those points, or do you want the intermediate values as well? If you only want those points, then that's easy, but if you want the intermediate values then it's going to be very tricky..

John J.A. Jannone's icon

>May I ask how you arrived at those coordinates?

The scribbler robot has two wheels. So to control it in a "joystick" fashion, I need to drive the two motors so that the robot will behave naturalistically based on the motion of the controller. There are a couple of ways to do this, but I chose:

CTR CTR: stop
FWD CTR: forward
FWD RT/LFT: maximum turn right or left (all drive forward in one wheel)
RT/RT & LFT/LFT: turn in place (wheels move opposite, max)
And the same for reverse

>And do you ONLY want those points, or do you want the intermediate values as well?

Yes, intermediate -- that is what I'm struggling with!

>if you want the intermediate values then it's going to be very tricky..

This is what I discovered!

Thanks for any insights you might have.

laonikoss's icon

Basically you want to translate two joysticks into one..

I can't think of any way this could happen on one [pictslider]. Why not use two [pictslider]s on Max? That would be dead easy and very straightforward.

Samuel Freeman's icon
Max Patch
Copy patch and select New From Clipboard in Max.

this patch gives intermediate values along each radius

John J.A. Jannone's icon
Max Patch
Copy patch and select New From Clipboard in Max.

Thanks Samuel! This is excellent. I've commented the patch with my understanding of how you achieved it.

John J.A. Jannone's icon

Samuel's patch was definitely on the right track, and I could not have gotten to this more fully developed patch without it. The previous patch works from the center to any cardinal point, but has discontinuities if you move around in the 2d space of the pictslider. For continuity along any vector of motion within the control space, the pictslider needs to be divided into 16 wedges, and the interpolation becomes not based on amplitude but angle within the wedge. After this, amplitude is used to scale everything towards zero as it approaches the center. TRICKY!

There is still a small error I can't get at where I'm getting the result I should see at 270° when I am at 260° -- so "forward" is actually somewhat right of true forward. But basically it works!

Max Patch
Copy patch and select New From Clipboard in Max.

John

John J.A. Jannone's icon

Note however that the control area remains circular -- the corners of the pictslider are ignored. If anyone knows how to stretch the circular aspect to the whole square...

Tex's icon

I've made a solution to this problem in a different way using a pictslider to drive the scribbler around. The main problem that John was trying to solve out was how to incorporate making the robot turn in place having wheels turn in opposite directions at the same time. I was thinking that for all practical purposes you'd only ever want the wheels to turn in opposite directions each at the same rate so I thought you could easily just have some key commands that would trigger this to happen at different speeds [Fast Left, Slow Left, Stop, Fast Right, Slow Right mapped to keys QWERT]. My patch still allows you to fully turn the robot around using the pictslider control but one wheel moves around the other which is stationary. Note that this patch generates messages that can be sent to the scribbler robot over a serial connection. It has two wheels which each accept integers 0 - 200 with 100 = stop, 0 = reverse full, 200 = forward full.

Max Patch
Copy patch and select New From Clipboard in Max.

This was an interesting challenge. I'd love to hear how it could be done differently or better.