Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Orientation Switch (http://www.chiefdelphi.com/forums/showthread.php?t=17377)

CyberWolf_22 04-02-2003 00:51

Orientation Switch
 
I am trying to write a program that when p4_sw_aux1 = 1 the robots orientation changes so that when joy1_y is 254 full reverse and when joy1_y is 0 then full foward same will go for the X axis.
I wish to do this in the single joystick drive code and can not get it to work write. Plz can anyone give me an example of how this might work.
Thanks in advance

CyberWolf_22,

Greg Ross 04-02-2003 01:24

My suggestion
 
Right after these lines:
Code:


drive_R = (((2000 + p1_y + p1_x - 127) Min 2000 Max 2254) - 2000)
drive_L = (((2000 + p1_y - p1_x + 127) Min 2000 Max 2254) - 2000)

Insert:
Code:


if p4_sw_aux1 = 1 then
    drive_R = 254 - drive_R
    drive_L = 254 - drive_L
endif


FotoPlasma 04-02-2003 01:33

If you're really planning on changing the orientation of the robot, forwards to backwards, you also have to swap the values of the PWM outputs, switching left for right, and vice versa, or else you'll be sending signals meant for the left side of the robot to the right, and signals meant for the right to the left.

I did this operation last year, for our roller/claw robot, first by doing what gwross already pointed out, which is inverting the PWM value around 127, then by XORing the values with eachother to swap them, without going through a third temp variable.

Code:

PWM1 = PWM1 ^ PWM2
PWM2 = PWM1 ^ PWM2
PWM1 = PWM1 ^ PWM2

or

Code:

drive_L = drive_L ^ drive_R
drive_R = drive_L ^ drive_R
drive_L = drive_L ^ drive_R

It worked like a dream, and was fun to implement.

Jnadke 04-02-2003 02:12

they easy way:

Code:

drive_L              var      byte
drive_R              var      byte
tempjoystick      var      byte


drive_R = (((2000 + p1_y + p1_x - 127) Min 2000 Max 2254) - 2000)
drive_L = (((2000 + p1_y - p1_x + 127) Min 2000 Max 2254) - 2000)
'single joystick drive code


if p4_sw_aux1 = 1 then
      tempdrive = drive_R
      drive_R = 254-drive_L
      drive_L = 254-tempjoystick
endif


Works like a charm. I used it last year on our robot.

Basically, you want to do the reverse code AFTER you figure out how fast you want each motor to go (assuming you're doing a 2 motor drivetrain, tank-style). It may not be pretty, or efficient, but it's guaranteed to work.

Not only do you have to reverse the drive speeds, but also you must remember to flip the left and right motor values, or you will find that the x-axis will be backwards.

rust710 04-02-2003 07:47

Quote:

Originally posted by Jnadke
they easy way:

Code:

drive_L              var      byte
drive_R              var      byte
tempjoystick      var      byte


drive_R = (((2000 + p1_y + p1_x - 127) Min 2000 Max 2254) - 2000)
drive_L = (((2000 + p1_y - p1_x + 127) Min 2000 Max 2254) - 2000)
'single joystick drive code


if p4_sw_aux1 = 1 then
      tempdrive = drive_R
      drive_R = 254-drive_L
      drive_L = 254-tempjoystick
endif


Your code is correct except for what is bolded. You are using two different Variables. Probably just an error when you typed it. Your code is similar to what I use on our robot.

Jferrante 04-02-2003 09:38

another way
 
drive_L = ((((2000 + p1_y - p1_x + 127) Min 2000 Max 2254) - 2000) * (1 - p1_sw_trig)) + (~(((2000 + p1_y - p1_x + 127) Min 2000 Max 2254) - 2000) * p1_sw_trig)
drive_R = ((((2000 + p1_y + p1_x - 127) Min 2000 Max 2254) - 2000) * (1 - p1_sw_trig)) + (~(((2000 + p1_y + p1_x - 127) Min 2000 Max 2254) - 2000) * p1_sw_trig)

If you want to avoid extra lines and extra variables you can do it this way. Its a bit long but we used it last year and it worked great.

Greg Ross 04-02-2003 10:42

Quote:

Originally posted by FotoPlasma
you also have to swap the values of the PWM outputs, switching left for right, and vice versa
Thanks. I just remembered about that this morning. You saved me having to post it.:)


All times are GMT -5. The time now is 04:27.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi