servo and motors problem
Vladimir Andrejev
Posts: 8
Hey guys.
I am just writing a code for an object avoidance. however i encountered a problem. Servos seems not to be holding long enough to make my turns. I already tryed everything that i can think of, but dumb mistakes are very hard to see. So maybe you can find something that is wrong with this code.
I· am using Servo32v3.
The way i want it is while the robot does not senses anything, it goes forward, as soon as it detects something reverse for 2 seconds, then make a right or left turn for 2-3 seconds·while going forward, and then straighten it self out. Can someone tell me maybe i am not holding them long enough, but how do i do it?
Thanks in advance·
I am just writing a code for an object avoidance. however i encountered a problem. Servos seems not to be holding long enough to make my turns. I already tryed everything that i can think of, but dumb mistakes are very hard to see. So maybe you can find something that is wrong with this code.
(CON _clkmode = xtal1 + pll16x ' use crystal x 16 _xinfreq = 5_000_000 ' Electronic Speed Control (ESC) 1 _esc1Forward = 1 ' forward direction _esc1Reverse = 0 ' reverse direction _esc1delayPerStep = 10 ' ms delay per % change in duty cycle _esc1Freq = 400 ' ESC 1 PWM Frequency _esc1In1 = 17 ' Input 1 (L298 In1 pin 5) _esc1In2 = 18 ' Input 2 (L298 In2 pin 7) _esc1EnA = 16 ' Enable A (L298 EnA pin 6) ULTRASONIC = 1 SERVOPIN = 23 SYRINGE = 22 OBJ motor[noparse][[/noparse]2] : "L298SetMotor" lcd : "ILM-216_LCD" num : "simple_numbers" PINGSens : "Ping" SMotor : "Servo32v3" gps : "GPS_SmartMode" text : "Serial_Lcd" VAR WORD pwServo1 ' pulse WORD pwServo2 long lonposi long latposi long homelon long homelat long finallon long finallat PUB main | dutyCycle1, direction1, direction2, delay1, tmp, lon, lat,index dira[noparse][[/noparse]SERVOPIN] := 1 motor[noparse][[/noparse]0].init(_esc1EnA, _esc1In1, _esc1In2, _esc1Freq, 0) ' initialize SetMotor.spin 0 SMotor.Set(SERVOPIN,1500) ' Start @ 90 degree position SMotor.Start dutyCycle1 := 25 direction1 := _esc1Forward direction2 := _esc1Reverse delay1 := _esc1delayPerStep if PINGSens.centimeters(ULTRASONIC) > 50 ''----------------Motor 1 Forward ----------------- SMotor.Set(SERVOPIN,1500) motor[noparse][[/noparse]0].setMotor(dutyCycle1, direction1, delay1) '' -----------------Motor 1 Avoidance -------------- elseif PINGSens.centimeters(ULTRASONIC) < 50 motor[noparse][[/noparse]0].setMotor(dutyCycle1, direction2, delay1) SMotor.Set(SERVOPIN, 1500) waitcnt(cnt + 200_000_000) if PINGSens.centimeters(ULTRASONIC) > 50 motor[noparse][[/noparse]0].setMotor(dutyCycle1, direction1, delay1) SMotor.Set(SERVOPIN, 2000) waitcnt(cnt+200_000_000) if PINGSens.centimeters(ULTRASONICC) > 50 motor[noparse][[/noparse]0].setMotor(dutyCycle1, direction2, delay1) SMotor.Set(SERVOPIN, 1500) waitcnt(cnt+200_000_000))
I· am using Servo32v3.
The way i want it is while the robot does not senses anything, it goes forward, as soon as it detects something reverse for 2 seconds, then make a right or left turn for 2-3 seconds·while going forward, and then straighten it self out. Can someone tell me maybe i am not holding them long enough, but how do i do it?
Thanks in advance·
Comments
Looking at this on the scope the Servo signal looks fine...· However your indentions and lack of a repeat causes the cog to terminate.
I made a few changes to the PINGSens section·that might help...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Can someone help?
Initialize the Servo motors before your motor routine instead...
...Also, you don't nee to set the DIR pins for the servo, the object already does that for you.
remove this line:
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Sort of related question so I hopefully I don't have to start a new thread:
I use Servo 32v3 and it seems like often only get about 90 degrees of motion out of servos (at most) whereas with a Parrallax servo controller (with a BS2) O could get more like 135 degrees (or more) of motion. I have tried different brands of servos (Futaba and Hitec) and the results are similar. Also, I get the same results with my code and the demo code. I think it is because the servos could take a wider range then 1000uS-2000uS but that is just a guess.
Does someone know why the servos might have a smaller response range then with a controller? Does anyone have a software solution?
Just wondering.
George Collins
I just set the initial position to a 1000 or 2000 and after that i start the servo. and when you set the servo again it should move 180 degreen. so if you would like to move 180 degrees.
Servo.set(SERVOPIN, 1000)
Servo.Start
Servo.Set(SERVOPIN, 2000)
waitcnt(cnt + xxxx+
Seems to work for me, but very very glitchy.
George Collins
"Seems to work for me, but very very glitchy" -
Can you describe what you mean by glitchy?
Can you post a schematic?
How long are the leads between the Propeller and the Servo?
Is a resistor used on the signal line?
Is a capacitor located near the Servo power?
The grounds are shared between the servo power supply and the Propeller Power supply correct?
Sorry for all of the questions, but this object was written awhile ago and has seemed to be stable.
I just want to make sure that I understand what might be causing an undesired servo behavior.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Would there be an easy (or relatively easy) way to modify your code to widen the range of the servo pulse? I am a fairly competent programmer, but completely new to the Prop and weak at assembly code.
By the way-- thank you for Servo32v3-- I use it on my Quadruped all the time now. You have made the prop chip useful for me and it is very cool.
George Collins
Absolutely... Inside of the Servo32 object there is a line that determines the limitations.· It is there to protect standard servos from going out of bounds from the 1ms to 2ms pulse width.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
I attached the schematic as an attachement.
I used 4.7 k resistors. The propstick uses a volateg regulator with a cap, schematic is in propstick manual. The whole thing is on the breadboard. No caps are located near it.
Just braging but we are making a robot that uses gps to navigate itself to a position that is programed through bluetooth. (Position is in water) So it goes on land and after that it goes in water(doesnt submerge). It also avoids all objects on the way.
I'm still not sure what you mean by glitchy...· what is the power supply for·the servo's?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
if PINGSens.centimeters(ULTRASONICC) > 50
motor[noparse][[/noparse]0].setMotor(dutyCycle1, direction2, delay1)
SMotor.Set(SERVOPIN, 1500)
waitcnt(cnt+200_000_000)
if i do the code like that the servo doesnt turn and it stop the motor. If i do the servo first and then the motor still does the same thing.
if i put
motor[noparse][[/noparse]0].setMotor(dutyCycle1, direction2, delay1)
waitcnt(xxx)
SMotor.Set(SERVOPIN, 2000)
waitcnt(xxx)
It starts working but switches of the motor at the same time as a servo. And it doesnt centre itself instantly.
I tried to do as you have said to Set the servo first and then switch of the motor but still doesnt work. you can hear it starts to switch the motor PWM but doesnt turn and switches both things off at once, without even spining the motor or turning servo.
Strange i know, but i checked all my wiring and all the voltages, its like it terminates both cogs.
What if i want to spin the motors for 20 seconds and turn servo only for 1 second. Is that possible?
What happens if you don't run the motors... just the servos?
What are the other motors you are running? .. and how are they being powered?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
I tried changing the range to 800- 2200 tonight after work. It worked great-- looks like roughly 45 more degrees. Thank you very much for your help!
George Collins