PDA

View Full Version : Regrading Servo Direction


NAVNEET ACHARYA
05-07-04, 02:31 PM
Sir,

I am controlling 4 servo motors through Serial Communication .

I am sending Data (Motor Id and Amount ) on ISOPOD serial port.

Then Using following program I am controlling the servo motors.

I am able to move motor in one direction till Exterme position not

reached,Thereafter when I give Negative data motor not move in

opposite Direction.

I am using following Callibration:

Mid-position when I give amount 7100

Below 7100 it will move in one Direction,and above that amount

it will move in another direction.

DATA C@ 53 * 7100 + DROT !
(53 amount moves motor by one step DATA consists value which I am Receiving on Serial Port of ISOPOD .It Ranges in between -100 to +100 .)

Then I move motor by amount specified by DROT.

Here is Program:

DECIMAL 9600 SCI0 BAUD

VARIABLE BUFR DECIMAL 40 4 + ALLOT EEWORD
BUFR 40 4 + SCI0 RXBUFFER
VARIABLE BUFT DECIMAL 40 4 + ALLOT EEWORD
BUFT 40 4 + SCI0 TXBUFFER

DECIMAL 70 CONSTANT DLE EEWORD
DECIMAL 83 CONSTANT SERHEAD EEWORD
DECIMAL 126 CONSTANT ETX EEWORD
DECIMAL 7100 CONSTANT SERCTR EEWORD

VARIABLE DATA1 EEWORD
VARIABLE DATA2 EEWORD
VARIABLE DATA3 EEWORD
VARIABLE DATA4 EEWORD
VARIABLE DATA5 EEWORD
VARIABLE DATA6 EEWORD

VARIABLE SERID EEWORD
VARIABLE DVAL EEWORD
VARIABLE DROT1 EEWORD
VARIABLE DROT2 EEWORD
VARIABLE DROT3 EEWORD
VARIABLE DROT4 EEWORD

MACHINE SERVE4TEST EEWORD
ON-MACHINE SERVE4TEST
APPEND-STATE SER1 EEWORD
APPEND-STATE SER2 EEWORD
APPEND-STATE SER3 EEWORD
APPEND-STATE SER4 EEWORD
APPEND-STATE SER5 EEWORD
APPEND-STATE SER6 EEWORD
APPEND-STATE SER7 EEWORD

IN-STATE SER1
CONDITION
CAUSES 32767 PWMA0 PWM-PERIOD
SERCTR PWMA0 PWM-OUT
SERCTR PWMA1 PWM-OUT
SERCTR PWMA2 PWM-OUT
SERCTR PWMA3 PWM-OUT
THEN-STATE SER2 TO-HAPPEN IN-EE

IN-STATE SER2
CONDITION SCI0 RX?
CAUSES SCI0 RX DATA1 C!
SCI0 RX DATA2 C!
SCI0 RX DATA3 C!
SCI0 RX DATA4 C!
SCI0 RX DATA5 C!
SCI0 RX DATA6 C!
THEN-STATE SER3 TO-HAPPEN IN-EE

IN-STATE SER3
CONDITION DATA1 C@ DLE =
CAUSES DLE SCI0 TX GRNLED OFF
THEN-STATE SER4 TO-HAPPEN IN-EE

IN-STATE SER4
CONDITION DATA2 C@ SERHEAD =
CAUSES SERHEAD SCI0 TX REDLED OFF
THEN-STATE SER5 TO-HAPPEN IN-EE

IN-STATE SER5
CONDITION DATA5 C@ DLE =
CAUSES DLE SCI0 TX
THEN-STATE SER6 TO-HAPPEN IN-EE

IN-STATE SER6
CONDITION DATA6 C@ ETX =
CAUSES ETX SCI0 TX YELLED OFF
THEN-STATE SER7 TO-HAPPEN IN-EE

IN-STATE SER7
CONDITION DATA3 C@ 1 =
CAUSES 32767 PWMA0 PWM-PERIOD
DATA4 C@ 53 * 7100 + DROT1 !
DROT1 @ PWMA0 PWM-OUT
YELLED ON
THEN-STATE SER2 TO-HAPPEN IN-EE

IN-STATE SER7
CONDITION DATA3 C@ 2 =
CAUSES 32767 PWMA1 PWM-PERIOD
DATA4 C@ 53 * 7100 + DROT2 !
DROT2 @ PWMA1 PWM-OUT
GRNLED ON
THEN-STATE SER2 TO-HAPPEN IN-EE

IN-STATE SER7
CONDITION DATA3 C@ 3 =
CAUSES 32767 PWMA2 PWM-PERIOD
DATA4 C@ 53 * 7100 + DROT3 !
DROT3 @ PWMA2 PWM-OUT
REDLED ON
THEN-STATE SER2 TO-HAPPEN IN-EE

IN-STATE SER7
CONDITION DATA3 C@ 4 =
CAUSES 32767 PWMA3 PWM-PERIOD
DATA4 C@ 53 * 7100 + DROT4 !
DROT4 @ PWMA3 PWM-OUT
YELLED ON
GRNLED ON
REDLED ON
THEN-STATE SER2 TO-HAPPEN IN-EE


: HANG BEGIN PB0 OFF? UNTIL ; EEWORD

: STARTUP
ISOMAX-START
SER1 SET-STATE
INSTALL SERVE4TEST
HANG
; EEWORD

HEX 3C00 AUTOSTART STARTUP
SAVE-RAM


Please Give some suggestions Regarding this Program.

Please Reply as fast as possible.

Thanks.

Regards,

NAVNEET ACHARYA
05-08-04, 02:21 PM
Sir ,


The only problem in the previous program i am facing is

Reception of Negative Numbers.

When i send Negative Number at serial port like(-33)

Then I Receive only DF other's bits are lost ,That's why I am

having problem in Making Decision.

Please reply that Very Urgently.


Regards,

RMDumse
05-10-04, 03:14 PM
I am still trying to understand your whole program, but here are a couple small things I see already.

IN-STATE
SER1
CONDITION

CAUSES
32767 PWMA0 PWM-PERIOD
SERCTR PWMA0 PWM-OUT
SERCTR PWMA1 PWM-OUT
SERCTR PWMA2 PWM-OUT
SERCTR PWMA3 PWM-OUT
THEN-STATE
SER2
TO-HAPPEN IN-EE

I reformated the first state transition in my style above to point out, there is no boolean for the CAUSES. Failing to have a boolean will cause a stack imbalance, and threatens possible uncontrolled behavior. (i.e. it "steals" a value from the stack anyway, and no telling what that value might or might not cause to happen. First the transition will be unreliable, then, if something else is depending on the value what was stolen, there could be a crash later on.)

In the second transition,

IN-STATE
SER2
CONDITION
SCI0 RX?
CAUSES
SCI0 RX DATA1 C!
SCI0 RX DATA2 C!
SCI0 RX DATA3 C!
SCI0 RX DATA4 C!
SCI0 RX DATA5 C!
SCI0 RX DATA6 C!
THEN-STATE
SER3
TO-HAPPEN IN-EE

If a single character is available, the following action clause will happen. If there was only one character available for the first RX statement, the next RX statement will hand in PCC until a character does show up. This PCC will break the IsoStructure of the system, and nothing will run until the next character comes in. However, therer are a total of 6 RX's, so nothing else runs but this action cause until all six characters have come in. This is not a good IsoStructured design.

RMDumse
05-10-04, 03:49 PM
I'm still working through the program, not understanding your full intent yet, but have another suggestion about the style of intializing things.

When you create serial buffers while downloading with these lines:

VARIABLE BUFR DECIMAL 40 4 + ALLOT EEWORD
BUFR 40 4 + SCI0 RXBUFFER
VARIABLE BUFT DECIMAL 40 4 + ALLOT EEWORD
BUFT 40 4 + SCI0 TXBUFFER

The first line, VARIABLE... creates the variable and is only needed to be compiled once. The second line after the VARIABLE creation happens once during download. But it also needs to happen any time the system starts again after a power cycle. (The default after power cycle is to have no buffers.)

So you should add these second lines to your start up word like this:


: STARTUP
BUFR 40 4 + SCI0 RXBUFFER
BUFT 40 4 + SCI0 TXBUFFER
ISOMAX-START
SER1 SET-STATE
INSTALL SERVE4TEST
HANG
; EEWORD

HEX 3C00 AUTOSTART STARTUP
SAVE-RAM

RMDumse
05-10-04, 04:08 PM
Ah ha. I think I finally get your point.

While I still have some reservations about how the program is put together, I have figured out why you can't do negative values.

A character is typically not thought of as a signed value. A character is a max of 8 bits and runs from 0 - 255. IF you want to treat a character as a signed value, you have to extend the msb of the 8 bits across the remaining bits of the upper byte.

In other words, you have to test the incoming character for being above or below 80 hex (128 decimal) if it is below 80 hex (0 - 127 decimal), it has a zero in the top bit, and you treat it as positive. If it is equal or above 80 hex (128 - 255 decimal) you treat it as positive.

So here's an example of how to treat these characters:

DATA C@ 128 U< IF FF00 OR THEN 53 * 7100 + DROT !

or for example in your last transition:

DATA4 C@ 128 U< IF FF00 OR THEN 53 * 7100 + DROT4 !
DROT4 @ PWMA3 PWM-OUT

Try that and let me know if you can't do negative values then.

RMDumse
05-10-04, 04:20 PM
So here's an example of how to treat these characters:

DATA C@ 128 U< IF FF00 OR THEN 53 * 7100 + DROT !

or for example in your last transition:

DATA4 C@ 128 U< IF FF00 OR THEN 53 * 7100 + DROT4 !
DROT4 @ PWMA3 PWM-OUT


Darn. No. I mixed HEX and DECIMAL values there. That won't work. Let me convert FF00 to a decimal 65280 and it should work better.

DATA C@ 128 U< IF 65280 OR THEN 53 * 7100 + DROT !

or for example in your last transition:

DATA4 C@ 128 U< IF 65280 OR THEN 53 * 7100 + DROT4 !
DROT4 @ PWMA3 PWM-OUT

NAVNEET ACHARYA
05-11-04, 03:49 AM
Sir,

Now my code is working fine,Thanks for response.

Regards,