Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   NI LabVIEW (http://www.chiefdelphi.com/forums/forumdisplay.php?f=182)
-   -   Need help w/ moving Camera Servo motors. (http://www.chiefdelphi.com/forums/showthread.php?t=82273)

umangv620 09-02-2010 17:33

Need help w/ moving Camera Servo motors.
 
1 Attachment(s)
I am trying to move the Camera Servo Motor(Axis 2 - plugged into PWM 5 w/ Jumper) through Joystick 2(USB 2). I want it so when I press button 2, the camera should face down, and when I press button 3, the camera should face up.

I attached my current code for the Camera. Both the Joystick(Joystick 2) and the Servo(Camera Motor) are both initialized in the begin.vi, and both closed in finish.vi. The Camera.vi is being called in Robot Main.vi inside the giant while loop.

Right now, when I run the code, the Servo motor does not move at all, so i decided to debug it by running the code in light bulb mode. What I noticed was that the initial position was 0.00, and after subtracting 1(moving it down), the new position was still 0.00. I don't know why the position is not being updated for every time the loop executes and moves it down.

Ziaholic 09-02-2010 22:12

Re: Need help w/ moving Camera Servo motors.
 
That picture shows a different VI in the background that sets the servo to zero. That could be your problem.

Alan Anderson 09-02-2010 22:27

Re: Need help w/ moving Camera Servo motors.
 
Quote:

Originally Posted by umangv620 (Post 916575)
What I noticed was that the initial position was 0.00, and after subtracting 1(moving it down), the new position was still 0.00.

The valid range of values for Servo Set Position is from 0 to 1. If you try to set the servo position to something greater than 1, it will be coerced to 1. If you try to set it to something less than 0, it will be coerced to 0. Does that help explain what you're seeing?

umangv620 10-02-2010 00:06

Re: Need help w/ moving Camera Servo motors.
 
Sorry about the double post. Look below for my actual post.

umangv620 10-02-2010 00:09

Re: Need help w/ moving Camera Servo motors.
 
Quote:

Originally Posted by Ziaholic (Post 916774)
That picture shows a different VI in the background that sets the servo to zero. That could be your problem.

That is so weird. I think that is there because I might have copied the camera code directly into Robot Main because this is the first time I am using sub VIs. Even if it was something different, I am sure that the motor is only set to 0 when a button is pressed.I am pretty sure I didnt make a stupid mistake such as this, but I will look this up on thursday(snow day tmr).

Quote:

Originally Posted by Alan Anderson (Post 916793)
The valid range of values for Servo Set Position is from 0 to 1. If you try to set the servo position to something greater than 1, it will be coerced to 1. If you try to set it to something less than 0, it will be coerced to 0. Does that help explain what you're seeing?

So should I use Servo SetAngle instead? What range does that go from? 0 to 180 or -90 to 90?

Alan Anderson 10-02-2010 08:19

Re: Need help w/ moving Camera Servo motors.
 
Quote:

Originally Posted by umangv620 (Post 916889)
So should I use Servo SetAngle instead? What range does that go from? 0 to 180 or -90 to 90?

If you open up the SetAngle vi you can see how it works. It takes the angle and normalizes it to 0-359, then converts that to a number from 0 to 1 based on the angular range of the servo. The default range is 170 degrees.

What you should do is choose an appropriate increment. If you use 0.01 instead of 1, your servo will work as you expect with 100 steps of travel. (This assumes that the rest of your code is correct. Things are scrunched enough that I can't really read it well.)

umangv620 10-02-2010 15:53

Re: Need help w/ moving Camera Servo motors.
 
Quote:

Originally Posted by Alan Anderson (Post 916984)
If you open up the SetAngle vi you can see how it works. It takes the angle and normalizes it to 0-359, then converts that to a number from 0 to 1 based on the angular range of the servo. The default range is 170 degrees.

What you should do is choose an appropriate increment. If you use 0.01 instead of 1, your servo will work as you expect with 100 steps of travel. (This assumes that the rest of your code is correct. Things are scrunched enough that I can't really read it well.)

Sorry about the double post and sorry about the code. Maybe I should have kept the lightbulb mode off so everyone could read the code more clearly.

I will try changing the increment tomorrow, since school is closed today.

umangv620 12-02-2010 18:27

Re: Need help w/ moving Camera Servo motors.
 
1 Attachment(s)
The camera still wont move. With light bulb on, the motor shows its position as .5, and when i press button 2, it decreases to .49. After executing once, i still have button 2 pressed down, so the value is .48.

Here is my Robot Main code, and my Camera code. The camera code is being called in Teleop Enabled, but when it runs without light bulb, the Camera Sub VI is "waiting to run". Why is this error occurring and how can I fix it?

On a sidenote, for some reason when we deploy our code, the driver station reports that the robot is on Teleop enabled, then switches to "Watchdog not fed", then back to Teleop Enabled, and back to "Watchdog not fed", and then to Teleop Enabled, and back to "Watchdog not fed", and keeps following that loop. I am not sure why I am getting this error, and is interrupting our code execution.

Greg McKaskle 12-02-2010 18:58

Re: Need help w/ moving Camera Servo motors.
 
You've put the teleop code into RobotMain rather than into the Team Code Teleop function. While this isn't horrible, it does mean that the code in teleop, the drive code, and the camera update code are all running in parallel.

Far worse, the code to read the Joystick 1, Ope the Drive and read Joystick 2 are running in parallel with what I'm assuming is the Begin VI which is offscreen. This will likely mean that the joystick references are bad.

Anyway, before you write additional code, why not move the existing stuff into Teleop? Also, if you have errors due to multiple opens or referencing before opening, the Diagnostics tab should list those errors.

Greg McKaskle

umangv620 12-02-2010 20:59

Re: Need help w/ moving Camera Servo motors.
 
Quote:

Originally Posted by Greg McKaskle (Post 918853)
You've put the teleop code into RobotMain rather than into the Team Code Teleop function. While this isn't horrible, it does mean that the code in teleop, the drive code, and the camera update code are all running in parallel.

I tried moving the tank drive code into the teleop vi, and i experienced a very rapid burst of "teleop enabled" and "teleop disabled". This may be from the faulty wiring into the digital sidecar we discovered later. Should the tank drive code be inside the case structure that is true/false based on the Joystick Read.vi or should it be outside that loop, but inside the other case structure loop encasing most of the teleop code?

Quote:

Originally Posted by Greg McKaskle (Post 918853)
Far worse, the code to read the Joystick 1, Open the Drive and read Joystick 2 are running in parallel with what I'm assuming is the Begin VI which is offscreen. This will likely mean that the joystick references are bad.

how else am i supposed to get the joystick references? in the begin vi, i intialized the joysticks and set a reference to them. In Robot Main, i get the reference. If i am not supposed to get the reference, how will i run tank drive?

Greg McKaskle 13-02-2010 04:07

Re: Need help w/ moving Camera Servo motors.
 
If you get the reference inside the teleop VI, it is guaranteed that Begin has completed. If you get the references in Robot Main, how do you guarantee that Begin has set them?

If you need the refnum in Robot Main, you should just open it there rather than in Begin.

If you are carful, you can of course keep writing the code the way you are, but moving the code from teleop to Robot Main didn't fix any bugs you had, and in fact will likely introduce them. The big green comments to the left of the diagram describe the typical way of modifying the framework. They are of course only suggestions, but maybe something you should read before making big edits.

As for the location of the drive code. The easiest way to see how it should be done is to create a new project using the getting started window. Save it to a new location/name and inspect how it was originally done. You can also do this on a separate computer if you are unsure of where your current code is saved.

Greg McKaskle

umangv620 13-02-2010 18:03

Re: Need help w/ moving Camera Servo motors.
 
Quote:

Originally Posted by Greg McKaskle (Post 919085)
If you get the reference inside the teleop VI, it is guaranteed that Begin has completed. If you get the references in Robot Main, how do you guarantee that Begin has set them?

If you need the refnum in Robot Main, you should just open it there rather than in Begin.

If you are carful, you can of course keep writing the code the way you are, but moving the code from teleop to Robot Main didn't fix any bugs you had, and in fact will likely introduce them. The big green comments to the left of the diagram describe the typical way of modifying the framework. They are of course only suggestions, but maybe something you should read before making big edits.

As for the location of the drive code. The easiest way to see how it should be done is to create a new project using the getting started window. Save it to a new location/name and inspect how it was originally done. You can also do this on a separate computer if you are unsure of where your current code is saved.

Greg McKaskle

We are getting the weirdest errors. So after moving the drive code into Teleop.vi, we noticed that when we push Joystick 1 foward, both motors move in opposite directions(1 Jaguar green, 1 jaguar blinking red), and Joystick 2 randomly turns Jaguar 2 blinking red or green(depending on the direction). (now on known as MODE2)

Joystick 1 should move Jaguar 1 only, and Joystick 2 should move jaguar 2 only(now on known as MODE1). The problem we are having is that Joystick 1 controls both jaguars, and joystick 2 sometimes(like 1 sec per every 5 seconds, but its more random) sends a signal to the jaguar. The code is here: http://i48.tinypic.com/sqqe8n.jpg

So afterwards, we went back to our old code and tried to find out what was causing the error. And we have narrowed it down to two things. First, the references arent working properly. When I use a Joystick reference instead of opening a new joystick, the code goes into MODE2, and if we use open a new joystick instead of referencing it, the code goes into MODE1.

You can see our begin.vi here(disregard the Robot Main.vi because it no longer works like that): http://i49.tinypic.com/24uycr8.jpg
Although you can't fully see Begin.vi, the technique we used to reference the joysticks are the same.
Basically:
[USB1] --- [Joystick Open] ----[Joystick Set Ref.]====[error output array]
["Joystick 1"]-----------------/

Joystick 1 is the name of our reference, and I kinda drew out how our Joystick code in Begin.vi looks like.

SO, the problem: We want MODE1(but no errors in the diagnostic tab), but we are getting MODE2 with no errors in the diagnostic tab(besides watchdog). Can someone please post or PM me some screenshots or code, because we are having major trouble with this.

Greg McKaskle 13-02-2010 19:13

Re: Need help w/ moving Camera Servo motors.
 
When I look at the code Teleop code at : http://i48.tinypic.com/sqqe8n.jpg I see that each time it is called, 50 times a second, the joysticks are being closed, additionally, the drive is being opened and closed.

Move the Opens to Begin, the Closes to Finish, and see if that helps. By the way, you'll need to name and store the drive.

Greg McKaskle

umangv620 14-02-2010 00:19

Re: Need help w/ moving Camera Servo motors.
 
Quote:

Originally Posted by Greg McKaskle (Post 919548)
When I look at the code Teleop code at : http://i48.tinypic.com/sqqe8n.jpg I see that each time it is called, 50 times a second, the joysticks are being closed, additionally, the drive is being opened and closed.

Move the Opens to Begin, the Closes to Finish, and see if that helps. By the way, you'll need to name and store the drive.

Greg McKaskle

Thats what we had. We were getting errors, so we deleted that part and opened the joysticks and drive in now robot main(not teleop) and closed it in robot main as well. When we do this, our joysticks function correctly.

When we open the joysticks and the drive in begin.vi and reference them, the joysticks act funny and so does drive. Which is why i was wondering if anyone could post or PM any screenshots or code that could help us out.

ecnahc515 15-02-2010 02:31

Re: Need help w/ moving Camera Servo motors.
 
Quote:

Originally Posted by umangv620 (Post 919738)
Thats what we had. We were getting errors, so we deleted that part and opened the joysticks and drive in now robot main(not teleop) and closed it in robot main as well. When we do this, our joysticks function correctly.

When we open the joysticks and the drive in begin.vi and reference them, the joysticks act funny and so does drive. Which is why i was wondering if anyone could post or PM any screenshots or code that could help us out.

That probably means you opened up the same reference or something, more than once. It should work fine with the begin and finish VI's, while having your reference and settings in the teleop. If it isn't than you set something up wrong.


All times are GMT -5. The time now is 11:58.

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