PDA

View Full Version : R2D2 Build



Pages : [1] 2

ctx32
05-26-2008, 11:47 AM
I have posted some other threads concerning what I a trying to build.
I allmost have R2 complete except for the electronics and this is where I need help.
You can see R2 at: www.tomsr2.blogspot.com (http://www.tomsr2.blogspot.com)
I want to add an on board Mini ITX and use Phidgets to controll the servos and motor controllers. I also want to be able to drive and controll the servos using a Logitech Wireless remote.
There won't be any sensors, Just pure remote.
I'm sure this is very basic for you guys, But for me it's quite a task.
I've been told Visual Basic will be easy enough for me to get the job done, But it's all new.
Any help and tips will be GREATLY appreciated.
Thanks for the help
Calvin

LinuxGuy
05-26-2008, 12:29 PM
I have posted some other threads concerning what I a trying to build.
You don't have to post multiple threads about the same thing. One thread will do the trick. :veryhappy:

8-Dale

Adrenalynn
05-26-2008, 12:40 PM
In this case, it's a specific project versus a general language discussion. I think a new thread is appropriate...

Nice fab work, CTX! Very nice indeed!

Did you see the R2 article in this month's Servo Magazine? Are you a member of the R2 builder's "club"?

Anyway -

How many and what kind of servos are you looking to drive? And another two drive motors?

What kind of Logitec Wireless Remote? (IR or RF or ???) Is it USB or PS/2?

Your basic requirements are pretty trivial. I'm sure we could help you out...

Do plan for sensors later. I'm betting you're going to want them. How about a wireless camera and the ability to drive it from a PC, or even over the Internet? That's not terribly tough either. Sky's the limit - go big! :) Something that pretty certainly deserves it, IMHO.

ctx32
05-26-2008, 01:32 PM
Thank you for the comments and yes I am a 2-1/2 member of the R2 Builders Club.
No I did'nt see the article, I missed it :o(
I have been reading about the servo controllers and it looks like I will need:
2- 4 Servo Boards - For 2 doors and 2 moving arms and 2 top arms and 1 bay door and 1 probe
Thats 8 servos.

I'll need:
1- 4 Servo Board - For 1 dome drive (Head) and 2 foot motors (These are 24v. motors that will be connected to 1 Sabertooth motor controller) This should leave me with 1 open servo plug.

The Logitech (http://www.logitech.com/index.cfm/gaming/pc_gaming/gamepads/devices/287&cl=us,en) is USB and I think it was used in the video of the 4 wheeled robot here.

I would like to oneday add a wireless camera behind the eye. Which I bought in the past just for R2.
Looks like to me the only programming I need is for the Logitech to communicate with the Phidgets through the computer.
Thanks again.
Calvin

4mem8
05-26-2008, 01:52 PM
ctx32, Very very nice R2D2, well put together. An ITX M/B would be ideal in this robot, I can't offer to much in the way of help here as I am only just in the process of using an ITX system, give me another month or so and I may be able to help you out.

Adrenalynn
05-26-2008, 02:17 PM
What we need to know now is - does it pretend to be a joystick(s), or is it an HID only device. I imagine it emulates joysticks for games instead of requiring specific drivers written to the games themselves.

ctx32
05-26-2008, 03:05 PM
Thanks 4mem.
Adren.
Hum, How can I find that out?
I can tell you that the Microsoft Robotic software has a program that came up and shows the functions of the remote.
As I worked the buttons you could see the software responding.
At this link, I see them using the remote.
http://www.trossenrobotics.com/tutorials/tutorialshome.aspx
It's the last video, I don't know if this helps.
Calvin

Adrenalynn
05-26-2008, 03:49 PM
Well, you see, that makes it really simple. That would likely be Alex's work, possibly Dave's. When they're back from the holiday, you'll learn exactly how they did it. They're awesome that way.

Droid Works
05-26-2008, 05:24 PM
When I built mine I got almost all the info and links to parts like the dome for example from: http://www.robotbuilders.net/r2/

ctx32
05-26-2008, 05:49 PM
Awesome D.W.,
So have you completed a droid?
The R2 Builders are a Yahoo group if anyone is interested or you can go to www.astromech.net (http://www.astromech.net).

Adren.,
I'm so glad your helping me with this project, You're allot of help.
I hope to catch one of them.
Thanks Everyone.
Calvin

Droid Works
05-26-2008, 07:57 PM
Awesome D.W.,
So have you completed a droid?
The R2 Builders are a Yahoo group if anyone is interested or you can go to www.astromech.net (http://www.astromech.net).

Adren.,
I'm so glad your helping me with this project, You're allot of help.
I hope to catch one of them.
Thanks Everyone.
Calvin
wow astomech.net is a cool site. I built mine about a year and a half ago. I wish I knew about that site back then.

ctx32
05-26-2008, 09:17 PM
There's a nice group of people on Astromech. Lots of help building and getting parts.
It's a long journey to get to where I am now and so far the build has costed about $6500.00
My wife went another route with her R3, She built her's in about 6 months and only about $600.00
Mine is aluminum and her's is polystyrene. WE can't wait to finish and visit the Children's Hospital
so the kids can enjoy R2 and R3.
I really do appreciate everyone's help, Not just to finish R2 but for the kids too.
Calvin

ctx32
05-27-2008, 06:13 AM
Adren.
You asked about the Gamepad, So I emailed Logitech and is what they said:

I understand that you would like to know if your gamepad is a HID device or a device that has special features to emulate other devices.

Calvin, without the Logitech Gaming software , the gamepad will function as a HID device.

With the Logitech Gaming software , you will be able to customize the gamepad buttons and also emulate the mouse and keyboard.

I hope this is the answer we're looking for.
Calvin

Adrenalynn
05-27-2008, 11:29 AM
Hi Calvin,

I'm going to semi-punt on this one and wait for Alex to return and get caught-up. If they're using that device to control their 'bot (and it sure looks like they were) - he's already solved these questions and will be able to give us a quick answer. (I have a Chinese knock-off that I picked-up last time I was in China. It's still new, sealed in the package. So I'd also like to know the answer without digging in to it... ;))

If he doesn't have an easy answer, I'll rip-open the packaging on this one. I'm crazy busy right now and have a lot of stuff I "owe" - a white paper, a bunch of stuff for work, etc. I need to put a few projects to bed (I'm in the middle of packing to move) before I take on new ones. :(

ctx32
05-27-2008, 02:15 PM
No problem Adren,
Just to keep info flowing, I did play around with the software the comes with the Gamepad.
I assume it's a emulator program, Because I got it running as my mouse and using it with Internet explorer.
That's would be great if I could see the monitor that will be in R2, But I can't.
Seems like if it can be used with IE. it could be used for about anything.
Calvin

Alex
05-27-2008, 05:34 PM
Well, you see, that makes it really simple. That would likely be Alex's work, possibly Dave's. When they're back from the holiday, you'll learn exactly how they did it. They're awesome that way.

That was my work;)

I replied to your other thread:

http://forums.trossenrobotics.com/showthread.php?t=1807

I had to close that thread though. Please do not double post. Post in this thread if you have more questions.

ctx32
05-27-2008, 06:16 PM
Sorry about the other post, I started this one to keep everything together.
I have so many questions, But I'm going to start with the files you sent me.
Thanks for helping

ctx32
05-28-2008, 06:36 AM
I downloaded the C# and starting on the tutorials. I hope I can learn this so I can get
something working.
I tried the joystick app you sent and it works great. I can see all the movement and the buttons
as they're being worked.
Something I noticed also, I can press 2 buttons and they both show on the app.
If coded correctly, Can I use this to alter the functions of the button?
Say if I: press button 1 and hold it down can I make it so all the other buttons do something
different than the original function?
This would allow me to have more button actions than I really have buttons.
Calvin

Alex
05-28-2008, 09:19 AM
theoretically, yes, I believe that is possible but I'd have to really sit down and go through my code again to be sure.

But, I would start off really basic and take small steps. Don't get ahead of yourself. Look how the polling works (it's what allows the joystick to be read by the computer). Look at how to retrieve physical values from the joystick. Basically, just take small steps to learn the program and how it works. There are a LOT of different areas to learn about in this program. I was only a novice programmer (not quite a newbie) when I wrote that program, but it took me a couple of weeks just to figure out Direct X DirectInput class alone.

But, don't let any of this hinder your creativity. Any time you come up with cool ideas like pressing 2 buttons at the same time, just write it down on an ongoing list of "things to look into eventually". Otherwise, you'll find yourself still at step 1 because you've gotten so distracted. Trust me, I used to do this same thing all the time when I first started learning programming;)

If you'd like, create a new thread in the Software and Programming (http://forums.trossenrobotics.com/forumdisplay.php?f=21) forum dedicated to that program so that you can ask ongoing questions about it:)


EDIT: FYI to everyone. I just uploaded this joystick app to the downloads section:

http://forums.trossenrobotics.com/downloads.php?do=file&id=43

Adrenalynn
05-28-2008, 12:05 PM
Thanks, Alex! Save me some time!

What you're asking about is called "Chording", CTX. If the device can register two simultaneous pressesthen yes, you can Chord.

ctx32
05-28-2008, 12:45 PM
Thanks Alex,
I know I have alot to learn and at my age learning can be troublesome sometimes.
But R2 is so important to me that I will work as hard as possible.
Hope you guys don't mind all the questions I'll have :o)

Adren,
Chording, it did register 2 at a time.
This will be GREAT!!!, I was using Vex in my R2 and was just running out of controls very quick.
I had found ways around this problem, But it meant carrying small 12ch remotes I bought on Ebay.
So, If this Chording works then I can run what I need from less remotes.
Calvin

Adrenalynn
05-28-2008, 12:56 PM
Yuppers! That's the idea with Chording. I used to have a "chord keyboard" - five keys, one for each finger. When you learned it, it was amazingly fast. I got up to about 35WPM (I type about 105 on a regular keyboard) with just one hand unsupported...

Alex
05-28-2008, 04:43 PM
I know I have alot to learn and at my age learning can be troublesome sometimes.
But R2 is so important to me that I will work as hard as possible.
Hope you guys don't mind all the questions I'll have :o)

Everyone here loves to help each other out. We're always stoked to see people join the TRC who are enthusiastic about robotics AND willing to learn;)

4mem8
05-28-2008, 07:05 PM
I have to second that remark Alex, Such a friendly site, and very helpful.

ctx32
05-29-2008, 06:51 PM
I started the tutorials for C#, But I wasn't getting the whole picture.
So believe it or not, I started on the kiddy korner for C#.
Now that's embarrassing. But I want to learn what I'm doing and not
bluff my way through C#.
So I may be on the back burner for a while, But I'm coming guys.
Calvin

Adrenalynn
05-29-2008, 07:02 PM
Everyone starts somewhere. The important thing isn't where, but that you have!

Alex
05-30-2008, 09:28 AM
I started the tutorials for C#, But I wasn't getting the whole picture.
So believe it or not, I started on the kiddy korner for C#.
Now that's embarrassing. But I want to learn what I'm doing and not
bluff my way through C#.
So I may be on the back burner for a while, But I'm coming guys.

There was a thread that I replied to a while back that I included a crap ton of good links to help you learn C#:

http://forums.trossenrobotics.com/showthread.php?t=1332&highlight=C%23

Also, there's an awesome thread in the MSDN forums that gives you a TON of book recommendations for learning C#:

http://forums.msdn.microsoft.com/en-US/csharpgeneral/thread/203b575e-05bd-4ce3-8bac-43cdbf0de29f/

A book that I absolutely LOVE and would recommend to anyone wanting to learn C# would be "Pro C# 2005 and the .NET 2.0 Platform" by Andrew Troelsen (publisher Apress). I'm sure you can find an ebook version of this somewhere online. Any questions at all with C# (even totally not robot related), I'm happy to help. Just post in the Software and Programming forum (http://forums.trossenrobotics.com/forumdisplay.php?f=21).

ctx32
06-03-2008, 06:11 PM
Thanks for the vote of confidence guys :o)
I'm still reading about C#, But I was playing around with that Microsoft Robotics and did a tutorial
on joysticks. On the 1st few tries the program messed up and I reloaded Direct X 9 and it works fine.
I got the Logitech controller to work with the onscreen IRobot and that was COOL!!!!
I hope to get the controller setup oneday and run R2 all over the place.
I'm going to order my 1st Phidget this weekend and I'm going to get the 4 servo controller.
I've downloaded the Phidgets Library and hope to get it figured out.
Thanks for the help everyone :o)
Calvin

Alex
06-04-2008, 09:31 AM
good luck! I'm very curious to know how far Robotics Studio is along. When I was alpha testing it, it seemed to have a TON of potential, but wasn't anywhere close to being for beginners. I know that they've added a lot to it since then and made a lot of changes, focuses more on the UI and stuff, so I'd definitely love to hear your experience with it once you get a chance to work with it for a while:)

Adrenalynn
06-04-2008, 10:36 AM
I played with it for two weeks, threw my hands in the air, and walked away from it. Lots of power [apparently], so terribly obfuscated that I'll likely never know.

LinuxGuy
06-04-2008, 10:41 AM
I played with it for two weeks, threw my hands in the air, and walked away from it. Lots of power [apparently], so terribly obfuscated that I'll likely never know.
I have pretty much the same opinion about MSRS at present. However, with the April CTP, I am starting to see some possibilities. I wish there was something similar, but of course better, available for *NIX/Linux.

Well, OK, we have things like PyRo (http://pyrorobotics.org)/Player/Stage/Gazebo. If I can figure out how to separate the PyRo (http://pyrorobotics.org/) parts that seem to require from Player/Stage, I'll use it on W.A.L.T.E.R. and see what I can do with it.

8-Dale

Adrenalynn
06-04-2008, 11:14 AM
Can you check your Pyro links?

LinuxGuy
06-04-2008, 11:19 AM
Can you check your Pyro links?
All fixed! Thanks for letting me know. :happy:

8-Dale

Adrenalynn
06-04-2008, 11:25 AM
Much happier, thanks! :D

ctx32
06-04-2008, 01:59 PM
That Microsoft Robotics reminds me of the Vex Easy C. It's a graphic setup.
But, I was'nt very good with it either. I could setup some code but Marko had to
give me some tips on what I was doing wrong. We had R2's dome turning by sensors.
So if someone walked up to R2, He would turn and look at them, Pause, then return the
head forward.
I read in the M.R., That you could program so that your robot would follow a certain color
and that would be cool for R2 to do something like that.
Calvin

Adrenalynn
06-04-2008, 02:17 PM
Also have a look at Roborealm (roborealm.com) for things like color following, following human skin-tone, etc. It's the height of "simple" but can be made as complex as you like by using the dll and osc plugin interfaces.

ctx32
06-05-2008, 07:03 PM
Alex,
I was looking through the: Reading values from a joystick.
Wow, What a lot of code that was to write.
As I'm learnig from the tutorials, I've learned how to open and read some of the code.
But I still have a long way to go to understand alot of the code.
At least now I can see how it was written.
Back to my tutorials I go
Calvin

Adrenalynn
06-06-2008, 01:48 AM
Yeah, that's like a mini-direct-x class right there. Really great learning stuff!

Alex
06-06-2008, 08:18 AM
I think I commented all the code too, so that should help you out a lot to understand what's going on. If I didn't comment it, let me know, and I'll get on that as quick as I can.

ctx32
06-08-2008, 09:48 AM
I ordered my 1st Phidget product today. I bought the 4 servo kit.
I don't really need the servos that come with the kit, But I figured I'd use them somewhere
along the way. Anyway as soon as it arrives, I'll have more questions to ask.
Thanks
Calvin

LinuxGuy
06-08-2008, 04:39 PM
I bet I can find one of those R2D2 shells that would fit over W.A.L.T.E.R.. Then I just need some appropriate noises.. Hmmmmm.. :veryhappy::veryhappy:

8-Dale

Adrenalynn
06-08-2008, 05:00 PM
Have a read through this month's Servo magazine. I think "one of those shells" isn't what you think it is. Generally people spend a good year of machining to build one. You don't just run out and buy one - if you could, Lucas already would have sued them out of existance...

LinuxGuy
06-08-2008, 05:53 PM
Have a read through this month's Servo magazine. I think "one of those shells" isn't what you think it is. Generally people spend a good year of machining to build one. You don't just run out and buy one - if you could, Lucas already would have sued them out of existance...
I was referring mainly to the large plastic type kids toys I've seen in stores. W.A.L.T.E.R. isn't all that big. :veryhappy::veryhappy:

8-Dale

ctx32
06-08-2008, 05:58 PM
I've been building R2 for 2-1/2 years. He's all aluminum except for the frame and legs.
You can build a Polystyrene R2 and leave the inside fairly open, So you'll just have the skins.
My wife has been building for 7 months and allmost has her R3-T7 complete.
You can see her's at: http://www.r3t7.blogspot.com/
We will be building 1 more after we finish these 2 droids.
Allways glad to see someone else interested in building a droid.
Calvin

Wingzero01w
06-08-2008, 06:23 PM
Wow, you 2 have real good design/building talents.

ctx32
06-09-2008, 02:09 PM
We both Thank You allot!!
It's been a long haul and now to figure out V.B. and Phidgets.
Once this is done, I can complete R2.
Thanks
Calvin

ctx32
06-09-2008, 03:36 PM
Alex,
How do you tie your Joystick code to a Phidgets?
Can it be done?
Calvin

ctx32
06-09-2008, 03:40 PM
Adren,
I'm still trying to figure this stuff out and I'm doing the tutorials.
But I'm not sure if I'll ever get this figured out.
The Phidgets when they're connected to the computer,
Does a gui come up and you can control the phidgets?
What happens, I've never had a Phidget.
Calvin

Adrenalynn
06-09-2008, 04:06 PM
You're in luck!

Go here: http://forums.trossenrobotics.com/showthread.php?t=1287&page=2

And look down the page for the code that Indy007 just uploaded (supplementing Alex's code) - it's called "motion.zip" - I've only had a chance to go through it in a quickie skim sorta way, but between his and Alex's code, there's a ton of well commented information for controlling servos via a joystick from Phidgets.

Alex
06-09-2008, 04:27 PM
How do you tie your Joystick code to a Phidgets?
Can it be done?Ironically enough, there's a thread going on about this right now! Check out the link in Adrenalynn's post.



I'm still trying to figure this stuff out and I'm doing the tutorials.
But I'm not sure if I'll ever get this figured out.
The Phidgets when they're connected to the computer,
Does a gui come up and you can control the phidgets?
What happens, I've never had a Phidget.There is a TON of documents to help get you started using Phidgets. I can definitely help you out with any questions you have, but reading through all of the docs beforehand will provide you with a better understanding on how everything works. The manuals do a great job at answering the "Where the hell do I start??" question:)

I just checked out Phidgets Documentation page (http://www.phidgets.com/information.php) and noticed that they have a new "Programming Manual (http://www.phidgets.com/documentation/Programming_Manual.pdf)". They say that this should be the first manual you read when using Phidgets. I'm reading through it right now, and it covers all the major concepts when programming (not the code) with Phidgets. I'm really digging it so far. Something that I'm going to be recommending to many others from here on out. This is awesome that Phidgets put this together for their customers!

Now, if you only want to see Phidgets in action via a GUI, but not neccesarily do anything with them, then download and install/run the Phidget.msi (http://www.phidgets.com/downloads.php?os_id=1) (assuming your on Windows). Once you install the msi, you should see a little icon with the letters "Ph" on it, pop up in your system tray down by your clock (lower right hand corner of screen). Double click on this icon and a window will pop up:

321


When you see this window, if not already, plug in your Phidget device. Once you see your Phidget device in the list, double click on that item and a UI will pop up. There ya go:D

ctx32
06-12-2008, 01:06 PM
Adren,
I was looking at that code, But it still looks foriegn to me.
I don't know enough yet. I really want to learn though.
I've just got to get the joystick part going so I can use it in R2.

Alex,
Hehe, I was reading that As you were posting, But here again I still
have allot of learning to do.

I had the Phidgets.msi Allready loaded into my comp just did'nt know what to do with it.
I also got my 4 Servo controller in today and plugged it in and it works.
I was expecting it to have extra sliders instead of just 1, So you could controll each servo
without having to switch for 0-3 on the servo choice.
Hopefully I'll learn enough soon to get things moving in R2.
Thanks Guys :o)
Calvin

Adrenalynn
06-12-2008, 01:43 PM
Two books you want to buy stat:

.NET 2.0 Networking Projects by Wei-Meng Lee ISBN-13: 978-1-59059-790-3

Pro C# 2008 and the .NET 3.5 Platform by Andrew Troelsen [Fourth Edition]ISBN-13: 978-1-59059-884-9

One way or another, you're going to have to learn some programming. If you can get the sample code working - super! But at some point you're going to need to tweak it to make it do what it is you want to do...

ctx32
06-12-2008, 02:38 PM
I'll purchase those books as soon as possible.
I'm currently on Tutorial 6 which is 2 parts.
I'm following the tuts. very close although some of it I'm still lost at.
But the tuts. say it will be explained later.
Thanks for the heads up on the books.
Calvin

ctx32
06-12-2008, 04:23 PM
Adren,
I was trying out that Motion.zip and I can't seem to get anything from it.
It is the motion.csproj file that opens the program?
I have my joystick and phidget connected but I can't get the run button to light up.
Calvin

Alex
06-19-2008, 03:03 PM
I'm following the tuts. very close although some of it I'm still lost at.

If you're stuck on anything with programming and can't quite figure it out, just post your question in the "Software and Programming (http://forums.trossenrobotics.com/forumdisplay.php?f=21)" forum. It doesn't neccisarily have to deal with robotics. It can be a general programming question. I'm a fairly experienced high-level (.NET, Java, etc.) programmer (after all, that's what my degree is in;)). C# is probably the language I'm most proficient in too.

ctx32
06-20-2008, 02:57 PM
Thanks Alex,
I have been reading everything I can get my hands on ( C# for Dummies, C# by Deitel and the online tutorials ). I've also been working with Indy ( actual Indy's done the work while I stare and drool ).
I am really trying to understand C# and I am learning some, But I've still along way to go.
Calvin

ctx32
06-21-2008, 08:12 AM
Can someone tell me what I'm doing wrong with this code?
Calvin

Adrenalynn
06-21-2008, 11:32 AM
What's the expected behavior and the behavior you're actually observing? (I just dl'd the code from your link, but knowing what you want and what it's not doing can be helpful. ;) )

ctx32
06-21-2008, 02:19 PM
It runs the code and when it gets to - private Servo servo;
It says servo is null, Something about the servo is not declared?
What I did was take the example Indy helped me with and tried to do
away with some extra code and this is how far I got.

I'm not sure if it will even work, But if it does it should connect my Logitech gamepad
to the 4-servo controller.
Thanks
Calvin

ctx32
06-22-2008, 08:56 AM
Here's where I stand now with the code.
The original code was the Servo_Full and Indy added his code to it so the Logitech Gamepad
would work 2 servos on my 4 servo Phidget.
I still wanted a more basic code, So I started butchering the code and this is what I have now.
All the extra text and text boxes I deleted, I also reduced the size of the Form.
The code is working GREAT!!!, Although I know it probly has some bugs in the code.
I still don't know enough to have written the code alone and I really appreciate the help
Indy and everyone has given.
Now all I need to do is add more servos to the code and when I get more Phidgets add them into the code.
This will be quite a task for me, But I'm not giving up.
This maybe a program that will help other beginners like me achieve servo motion.
Thanks guys
Calvin

ctx32
06-22-2008, 11:46 AM
I guess I'm learning something, I just got the other 2 servos working.
I'll upload the code later for anyone that's interested.
Calvin

Adrenalynn
06-22-2008, 05:06 PM
Grats, CTX! Great progress, short time!

ctx32
06-23-2008, 01:35 PM
Thanks Adren,
I would not been able to get this far without Indy's help.
I do have 1 problem that I can't figure out on the code:
When I start up the code it runs a error at the 1st servo everytime.
If I run the Phidgets Manager and move each of the 4 servo's with that program
and then return and run my code, It works Great.

It's like my code can't find the start position of the 4 servo's by itself.
Calvin

Adrenalynn
06-23-2008, 02:18 PM
Try resetting them (ordering them to position 1500) in your code?

I know I have to do that most of the time to get my SSC32 to behave.

LinuxGuy
06-23-2008, 02:26 PM
I know I have to do that most of the time to get my SSC32 to behave.
You always have to initialize servo positions with the SSC-32. Otherwise it won't know where they all are and you won't be able to use the "T" and "S" modifiers for group moves. :veryhappy:

8-Dale

Adrenalynn
06-23-2008, 02:28 PM
Sometimes it just "gets lucky" ;)

ctx32
06-23-2008, 03:09 PM
Resetting the Servo's?
What's an ssc32?
Sorry still learning, But here's what I have so far and I think I'll have some new problems
coming soon.
If I add another 4 Servo Phidget to the computer, The code is going to need away to
tell there is more than 1 Phidget attached. I was trying to add the Serial code to my code
to tell the program that there's more Phidgets attached.
I will need a total of 4- 4 servo controllers and all run by the same Logitech Gamepad.

I guess I'll need to reset all the servos when I start the program.
Sorry I'm getting lost again:rolleyes:
Calvin

Alex
06-23-2008, 03:59 PM
It's easy stuff to use more than one of the same Phidget device in the same application, at least once you get the hang of it:)

sorry, I didn't look at your app, I just whipped together a quick app demonstrating how to use more than one of the same Phidget device in the same app.

basically, what you do is:



Define your Phidgets.Servo objects (in this app, I'll use three servo objects)
Call .open() method, but be sure to pass a parameter (the unique serial number of each Phidget Servo object) to each one.
Immediately after calling .open() method, call WaitForAttachment
Move positions of each servo independently.

In the attached .zip file, you'll see a C# 2005 project (if you're running 2008, just run the upgrade). It's fairly simply and straight forward. Basically, all I did was add three Trackbar controls to the form (one for each Phidget.Servo object, not for each port on each controller). Each of the Trackbars are tied to port #0 of each Phidget.Servo object.

I put in a little bit of documentation, just let me know if you're confused on anything:)

ctx32
06-23-2008, 07:06 PM
Alex,
Can I send you my code, So you can see what I've added from your example?
I think I added the correct lines for the other 4-Servo phidgets.
I also have some question comments in the code and don't know what they do.
Calvin

Alex
06-24-2008, 09:11 AM
no problem calvin, go ahead and send it my way:)

I won't be able to get to it till probably Thursday or Friday though. I have some pretty big projects going on right now.

ctx32
06-24-2008, 11:30 AM
Alex,
Here's the code I wanted you to look at.
Thanks for helping me figure out this code.
Calvin

ctx32
06-24-2008, 02:42 PM
I have connected the 4 servo Phidget (Serov 0) to a Syren motor controller.
The 1st time I ran my code the motor would keep running to the right,
I adjusted the servo1.servo[0].position = ((111 +js.state.X) * ServoStep);
I adjusted the 111 to 80 and the motor stopped turning.
I also checked the Syren with a multi-meter to make sure no power was still running.
I guess this 111 to 80 adjustment controls the center point of a servo?
If I reduce the number more the motor starts turning in the other direction.
So, I guess I'm right?
Calvin

Adrenalynn
06-24-2008, 09:33 PM
Yup! You're right!

128 is about stop on my Sabertooths (teeth?) plugged into an SSC32.

LinuxGuy
06-24-2008, 09:53 PM
Yup! You're right!

128 is about stop on my Sabertooths (teeth?) plugged into an SSC32.
Huh? Where are you getting this? You use the same P command range with the Sabertooth plugged into an SSC-32 as you would for any servo. The range is the same: 500uS - 2500uS. 1500uS is still center (stop for a Sabertooth).

8-Dale

Adrenalynn
06-25-2008, 10:52 AM
First of all, center is never really. For any device. 1500uS will run my Sabertooths at about 1/8th speed.

Second: I generally use a similar kind of stepping to the code above. Which was the reason I was responding to this thread. Something like a Sabertooth can't do squat with a 1uS change. Or even a 10uS delta. Their resolution isn't that high. Ergo, the reason for stepping in the code.

ctx32
06-25-2008, 03:33 PM
Hey Everyone,
I have reworked some of the code by comparing the last code Alex sent me.
I think I have it nicer than it was before. I'm sure there was some code that
was kinda just duplicates of each other.

As I work my code, Is it a problem for anyone if I keep adding the updated
code here as attachments?
I don't want to over add stuff to the forum, Just like for everyone to see
what I have done with the code.
Calvin

Alex
06-25-2008, 03:44 PM
To avoid confusion, what I would do is add your project to the Downloads section (http://forums.trossenrobotics.com/downloads.php). This way, you have one central area that everyone can go to, to check out the code. Everytime you make a change to it, you can just edit your Download content with a "changelog", and reupload the new zip file.

Then, you can just add a quick "hey I updated the software, check it out (with link to your download)" to this thread:)

Make sense? If not, let me know. I know sometimes I can bit a little confusing:)

ctx32
06-25-2008, 04:58 PM
Cool, I'll do that.
I didn't know we were allowed to add to that area.
I just wanted the flow of the forum to not get interrupted by my attachments.
I just hope my little messy code isn't too embarrassing.
It's no big thing, But it's growing.
Calvin

Alex
06-25-2008, 10:03 PM
I didn't know we were allowed to add to that area.

Really? Maybe I should rename it to "Member Downloads"? Thoughts? Better Suggestions? (please open a new thread in the Feedback and Suggestions forum).




I just hope my little messy code isn't too embarrassing.
It's no big thing, But it's growing.

No worries! For the longest time, my code in programs/software that I develop used to always looks like crap the first several versions. Even now, I have to go through my code at least two or three times to clean it up a bit.

Adrenalynn
06-25-2008, 11:37 PM
How about "Member Uploads"? "Member Downloads" still sounds like a place where members can come to fetch stuff, not drop stuff.

LinuxGuy
06-26-2008, 02:01 AM
Sometimes it just "gets lucky" ;)
You can't depend on getting lucky. :P This is how weird bugs creep into software.

Always do proper initialization. :D

8-Dale

Adrenalynn
06-26-2008, 03:14 AM
Depends on the application. If it weren't for getting lucky, ... There was a joke in there somewhere, probably in poor taste, but I'm just gonna let it go now.

Adrenalynn
06-26-2008, 03:15 AM
Oh - incidentally, the center point on both the phidgets motor controller and the sabertooth (and the polou I was looking at earlier) are all 128. 0 is break or coast, depending upon the controller, 256 is full speed.

JonHylands
06-26-2008, 08:28 AM
Oh - incidentally, the center point on both the phidgets motor controller and the sabertooth (and the polou I was looking at earlier) are all 128. 0 is break or coast, depending upon the controller, 256 is full speed.

The Sabertooth I have (2x10), non R/C version, uses locked anti-phase PWM, which means 128 is stopped, 0 is full speed reverse, and 255 is full speed forwards.

If you shift the scale back by 128, it works out better in your mind:

127 - full speed forward
0 - stopped
-127 - full speed reverse

- Jon

Adrenalynn
06-26-2008, 10:49 AM
That's interesting, Jon. I was basing mine off the 2x10 R/C (I have two of them).

Thanks for that! I'll file it away in my memory so that I'm not fighting with it if it ever comes time to write code to it. :)

ctx32
06-26-2008, 06:16 PM
I need alittle help on a part of my code.
I want to use a text box that shows the serial number for that Phidget.
Each Phidget will have this box and will have the servo and joystick info also.

I put the label (serial no.) and beside it I put a text box for the serial number to show
on the form.
In the code I put int serialNum1 = 20783, which is my 4 servo phidget.
Later in the code it shows the code for the text box and I've tried to code

serialTxt.Txt = serialNum1(); To show the serial number, But it errors on me.
I don't know what to do. I tried someother ways and it told me something about method
or it said could'nt convert int to string.
I'm lost again
Calvin

Alex
06-27-2008, 08:37 AM
You're using C# 2008, right? I ask, because you mentioned "serialTxt.Txt" and in C#, it'd be "serialTxt.Text". Plus, I'm confused about something. If you have "int serialNum1 = 20783", how could you have "serialNum1();" (with the brackets) in your code? Having the brackets like that specifies some sort of method/function, not a variable such as "int".

I'm almost positive I know what the problems are, but It'd help greatly if you were to paste the exact errors that you are receiving.

ctx32
06-27-2008, 11:28 AM
I'm using Visual C# 2008 and the int serialNum = 20783 is in the public partial class Form1 :Form.
It's suppose to be there, right? I think this means declare the number 20783 as a Interger to save in memory?

When I made the textbox, I think it added the code area for the box.
I was trying to make that box get the serial number from the phidget so I would have a visual
of which servo reading i'm looking at.
Servo-Multi has a box like this and it shows which serial is woking at a time.
I'll try it again.
Calvin

Alex
06-27-2008, 12:10 PM
First of all, forgive me for the lengthy explanation. I don't like to simply give people the answers. I would much rather help you understand the reasons and explanations behind the answers:D


I'm using Visual C# 2008 and the int serialNum = 20783 is in the public partial class Form1 :Form.
It's suppose to be there, right? I think this means declare the number 20783 as a Interger to save in memory?It depends. By declaring it in "public partial class Form1:Form", you're stating that you want it defined as a Global Variable. A Global Variable basically means that you can use that variable anywhere within that class (Form1:Form). Good programming practice is to minimize the amount of Global Variables you have in your code, so if you can find a way of using that variable as a non-global, then it'd be better. Without looking at your code, I can't really say whether or not there is a way to make this Variable non-global.


About saving in memory, yes, in a sense, Global Variables are saved in memory. At least until an instance of that class (which is an Object) is removed from memory (in your case, when you close your Form).


If what you are trying to do is add the contents of the serialNum1 Variable to your textbox, then there are a couple of errors in your code.

First, and yes, I'm repeating myself a bit above because I may have came across the wrong way, you are trying to use "serialNum1()", instead of "serialNum1" (notice no brackets). By trying to use "serialNum1()", you are basically saying that, somewhere within "Form1:Form", there is a method called "serialNum1":


private void serialNum1()
{
throw new NotImplementedException();
}Which, I'm assuming there isn't, as I understand, you have:


int serialNum1 = 20783;Defined as a Global Variable?

Ok, so now we are down to removing the brackets "()" from the statement "serialText.Text = serialNum1();" and am now left with:


serialText.Text = serialNum1;Which this is "almost" correct. In your code, you have the serialNum1; variable defined as an Integer (int serialNum1). However, if you type in your code "serialText" and the click dot ".", an Intellisense window will pop up giving you options to choose from. If you scroll down to the "Text" property, you'll notice a small window pop up to the right of the Intellisense window. This provides some more information to you about the "Text" property of the Textbox Object. You'll notice on the first line it says, "string Textbox.Text". What this tells you is that the "Text" property accepts only String Type variables, which is not what "serialNum1" is, it's an Integer. So, what you need is to convert this Integer into a String. There are many different ways of converting variables, but I'll show you the easiest way using the "Convert" class.


serialText.Text = Convert.ToString(serialNum1);You can use the Convert class to convert many variables, as soon as you type "Convert", you'll see the different types of conversions you can do.

That's it:) That should wipe out your errors.

I absolutely love helping people with programming ( I always said that I'd love to be a programming teacher), but if you're anything like me, I like to look for answers. I learn waay more about programming when I do that. But, you need a starting place for where/how to look for answers, otherwise you're just lost. The Error List at the bottom of your screen is absolutely priceless. If it wasn't for that, we'd still be stuck in the Stoneage of programming. For future reference, if you get errors, look at what is in that Error List, copy and paste it in Google. You usually find tons of references and ways to fix your error:D

EDIT: I hope all that made sense, if you need anything cleared up, just ask!

ctx32
06-27-2008, 12:40 PM
I knew in the back of my head there was away to convert the Integer to a String,
But I didn't know how.
It kept telling me it couldn't convert the 2 and I tried the other way with the () and it was
asking me for a Method.
A method is telling the code how to perform a certain task, Right?
Thank you Alex for not just giving me the answer, I'm learning from examples like this one.
I'm learning as I go and I've picked up quite allot since I first started.
I added this to my code and it works perfect.

When I run: Start without Debugging the program works correct,
But when I run with Debugging it has an exception:

LoaderLock was detected
Message: DLL 'C:\WINDOWS\assembly\GAC\Microsoft.DirectX.DirectI nput\1.0.2902.0__31bf3856ad364e35\Microsoft.Direct X.DirectInput.dll' is attempting managed execution inside OS Loader lock. Do not attempt to run managed code inside a DllMain or image initialization function since doing so can cause the application to hang.

I've had this problem from the beginning and I have no idea what it means.
Calvin

Adrenalynn
06-27-2008, 01:08 PM
I won't rant about not running spurious stuff on a development machine since this is a hobby and all. ;)

Bet you have iTunes installed on that machine, huh?

Open the Debug/Exceptions window (ctrl-alt-E), Open the Managed Debugging Assistants node and uncheck the LoaderLock checkbox. This is a per-solution setting, so you'll need to do it whenever you create a new solution.

Let us know how that works out, please?

ctx32
06-27-2008, 01:34 PM
How did you know that Adren?
Cool it works GREAT now!!!
Is there something about iTunes that will interfere with Debug?
I thought I had some code messed up.
Calvin

Adrenalynn
06-27-2008, 01:40 PM
It's not interfering with Debug, but rather production. iTunes overwrites something, I haven't figured out if it's registry or something within DirectX, but it hoses production compiles. We first started seeing it with iTunes7.1, I believe, I'd have to check the versioning system. We figured it out and then I threw a hissyfit that developers would install [whatever the heck they wanted] on development machines. Grrr. I had them all wiped clean and freshly imaged, then subnetted them all so they can't get to the Internet, or pretty much anywhere but to the versioning and source-control servers. Devs need admin, so policy control doesn't work well. I still find junk installed now and again and have to write people up for it.

Anyway - sorry - off in the weeds. The most common culprit for that error that we've found is iTunes...

Alex
06-27-2008, 01:50 PM
Ah yes.... the classic "loader lock". People have tried many times, but no person was ever able to explain to me what the f$#k loader lock is, in plain English. Sorry for the "language", but there was a time long ago when I got that error, and I spent 4 freakin days trying to figure out what I was supposed to do. I looked all around the web and didn't find any real answers, just more questions. Someone did finally tell me what I needed to do to get rid of the error (just as Adrenalynn pointed out), but no one ever was able to explain to me why it's there, what it is, what it is for, etc.

Anyway, rant is over, haha. Adrenalynn... care to take a stab at explaining to me what loader lock is about?:D

Adrenalynn
06-27-2008, 02:05 PM
Not really... :P

LoaderLock is a check inside the Windows OS to try to prevent threads from deadlocking. Deadlocking commonly occurs when one thread tries to call a process or another thread that hasn't finished initializing yet.

When a thread starts or finishes running, it has to acquire the OS' loaderlock in order to deliver its payload to other threads. It's preventing entry until it finishes its job, and is warning the OS not to let that happen. The most common deadlock I'm aware of happens in garbage collection threads that are attempting to pick-up after threads that haven't finished making their mess yet.

The error its throwing is actually fairly important and it's a bummer that it works out this way with iTunes, destroying a perfectly valid debugging tool. In fact, that's probably a clue - iTunes probably drops some dll that isn't reentrant into DX9 and the OS is requiring it to finish before it releases the lock. Effectively, DirectX is now making calls into a broken thread...

ctx32
06-27-2008, 02:53 PM
Guys,
I looked through the forums to hopefully find my own answer to a problem.
(I'm getting to be a pain in the hiney) :o)
When I start my code from a fresh reboot of the comp, If I don't open Phidgets Manager and set
each servo on my controller the code I am working on will not set the start position of the servos.
And Debug says something like this too.
I assume I need to add some code not to initialize the controller, But to set the start position for all 4 servos.
I have searched through Servo_Multi as it sets the servos when the code runs, But I can't find how it does it.
Any tips?
Calvin

ctx32
06-28-2008, 01:28 PM
Hey Guys,
I was searching the web for a solution to my code problem of not setting the 4 servos when I
start the program. And I bumped into this site:
http://grouplab.cpsc.ucalgary.ca/software/phidgets/PhidgetTutorial-v6.pdf
What happened to the Phidget toolbox like it shows on the site?

I also noticed something called: Servo_1Attach.
Is this something I need in my code for it to set the 4 servos when I start the program?
On the site it says to randomly set the servos, But I bet it can be set to a certain position
when you start the code.
Calvin

ctx32
06-29-2008, 10:10 AM
I've been studying 1 of the phidgets manual and it tells me about getting the serial number from the phidget
(int SerialNumber [get], But in my code I have declared the serial as a Interger because I want it to use a specific
controller. So I think this part is correct.

I also read about Attachment, But since my controllers will not be unplugged inside R2, Do I need a attach/detach code?

It says open is instant and I have this in my code so it will open the set serial number controller and I have wait for attachment, Which gives time for the controller to be attached if I were to unplug it.

I've read everything I could find and I still can't get the servo controller to set the servos by itself.
Servo_multi has something in the code that sets the 4 servos, But I can't find it.
It also sets the servos to a position I can't use, I will need a code that keeps the servos set at a certain position each time I start the program so it does'nt tear off the arms of R2.

Does publish mean to make the program an exe.?
Calvin

ctx32
06-29-2008, 07:36 PM
It's me again,
I had some improvement today, I added the attach and detach and error and position change handlers to my code and it can find my servos now.
It's having and error, But at least it's working without having to start the Phidgets Manager first.
I'll post more tommorrow and maybe I'll figure out the error.
Calvin

Alex
06-30-2008, 10:42 AM
I have searched through Servo_Multi as it sets the servos when the code runs, But I can't find how it does it.I couldn't find Servo_Multi. Is this something that you built, or is it in the Phidgets Library?

Servo_1Attach is what they call an Event Handler. Events and Event Handlers confused the hell out of me when I started learning about them, mainly because there was just an overload of information about them. So, I'll just give you the brief introduction. If you or anyone else would like to look through the official docs on Events, here's the MSDN intro to Events (http://msdn.microsoft.com/en-us/library/awbftdfh.aspx).

What an Event basically is, is a way to notify you that something had happened in your application. For example, say you pressed a button on your form, well there is an event that is called "Click". Also, when text changes in any control on your form (label, textbox, etc.), there is an event for that as well.

Now, an Event Handler is basically a way for you to "hook" onto that event to allow you to do something when the event happens. That's where Servo1_Attach comes in. Servo1_Attach is an Event Handler for the Event "Attach". So, this allows you to do something when your application gets notified that the Servo Controller has been attached to your application. This would be the ideal place to initialize the start positions of your servos on that particular controller. Keep in mind, for each PhidgetServo object you create, you'll have an Attach Event Handler.

EDIT: BTW, that Calgary link is very old (in addition to the C# and Phidgets programming reference guide on that page). I'd recommend not referring to that manual because many things have changed since that was written and is no longer valid. Calgary is where Phidgets came from and hence is where that manual and the controls to drag and drop came from.

ctx32
06-30-2008, 03:51 PM
I'm pretty sure I got Servo_Multi form the Phidgets Library,
But here's a copy. Hopefully it zipped the entire file.

Alex can you tell me what this error means:

See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
at System.Collections.ArrayList.get_Item(Int32 index)
at Phidgets.ServoServoCollection.get_Item(Int32 index)
at Servo_full.Form1.timer1_Tick(Object sender, EventArgs e) in C:\Documents and Settings\Calvin Thomas\My Documents\C# Samples\Fixed Code\Form1.cs:line 99
at System.Windows.Forms.Timer.OnTick(EventArgs e)
at System.Windows.Forms.Timer.TimerNativeWindow.WndPr oc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
Servo-full
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/Documents%20and%20Settings/Calvin%20Thomas/My%20Documents/C%23%20Samples/Fixed%20Code/bin/Release/Servo-full.exe
----------------------------------------
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
Microsoft.DirectX.DirectInput
Assembly Version: 1.0.2902.0
Win32 Version: 5.04.00.2904
CodeBase: file:///C:/WINDOWS/assembly/GAC/Microsoft.DirectX.DirectInput/1.0.2902.0__31bf3856ad364e35/Microsoft.DirectX.DirectInput.dll
----------------------------------------
Microsoft.DirectX
Assembly Version: 1.0.2902.0
Win32 Version: 5.04.00.2904
CodeBase: file:///C:/WINDOWS/assembly/GAC/Microsoft.DirectX/1.0.2902.0__31bf3856ad364e35/Microsoft.DirectX.dll
----------------------------------------
Phidget21.NET
Assembly Version: 2.1.4.20
Win32 Version: 2.1.4.20
CodeBase: file:///C:/WINDOWS/assembly/GAC_32/Phidget21.NET/2.1.4.20__c2b1f2a3594bce52/Phidget21.NET.dll
----------------------------------------
************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.
For example:
<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>
When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.


What is Jit?
Is this something I have wrong in my code?
I can hit continue when this comes up and the program runs on and runs correctly.
Since I have this working so far, I need to find the code that moves the servos when the code
starts. Because I don't want them to move when the code starts, Just to reconize the controller is attached.
Calvin

Adrenalynn
06-30-2008, 04:36 PM
JIT = Just In Time. It's a debugging and/or compiling method.

Yes, this is a problem in your code. You're initializing something out of the expected range of values, or you're calling something without initializing it first. Without seeing where it's dying, it's probably not possible to debug.

The servos probably should move - at least to center.

Alex
06-30-2008, 04:52 PM
It looks like you're trying to access an index of an Array that is outside of the bounds of that Array.

I take it you're using the PhidgetServo object right:

Phidgets.Servo s = new Phidgets.Servo();


Then, you're trying to access the individual port numbers right? Is it safe to assume that you are also using a PhidgetServo 4-motor controller? If so, then, you need to make sure that the range that you are giving the servos[] array is between 0 and 3.

ie.

s.servos[0].position = X;
s.servos[1].position = X;
s.servos[2].position = X;
s.servos[3].position = X;


It cannot be higher than that number.

Alex
06-30-2008, 04:54 PM
If that didn't answer your question, could you paste the line of code your application is crashing at? Anytime you are running a C# app in debug mode, it'll show you just where your code crashed.

Adrenalynn
06-30-2008, 04:55 PM
Yup - looks like Line #99. It should highlight the line for you.

Adrenalynn
06-30-2008, 05:00 PM
for (int i = 0; i < attached.servos.Count; i++)
{
servoNumCombo.Items.Add(i);
try
{
attached.servos[i].Position = 0.0;
}
catch (PhidgetException ex)
{
MessageBox.Show(ex.StackTrace);
}
}

servoNumCombo.SelectedIndex = 0;

Alex
07-01-2008, 04:30 PM
:confused:

I just dived in this thread to help ya out, but I see you deleted your last post... Whenever ya find something out, and/or need some help, let us know:)

ctx32
07-01-2008, 04:53 PM
Hey guys,
I deleted my last post because I was getting depressed about my knowledge in C#.
But I know I'm learning as I go and I will make 100's of mistakes along the way.
So guys, Please be patient with me. And I really do appreiciate the help, I could'nt have
gotten this far without everyone's help.

I'm still having the exception (Index out of range)
I have checked everything I can think of and also the servo array is 0-3, Which should be correct because I am using a 4 servo Phidget.
It also notes about the timer and about the timer_tick.
The timer was added by Indy and I really don't know exactly what it does, But I think it has something to do with polling the remote?
Adren,
That code of mine you posted, I got it from Servo_Multi and I'm not sure about what it does.
But without it the code will not start the servos on the controller.
SeeYa
Calvin

ctx32
07-01-2008, 05:16 PM
I updated the Members upload of my code.
There's allot of changes to the form and I added the Form close code.
Still got bugs, But it's better I think.
Calvin

Alex
07-02-2008, 08:41 AM
It definitely takes time to learn something like C#, so no worries. I hope I wasn't showing any type of impatience, cause I want to help you out in any way I can:D

At any rate, I just downloaded your project and am going to go through it now. However, when I opened your project, I received this:


375

I also noticed in your root, there is a file called "Servo-full_TemporaryKey.pfx" and "MyTemplate.vstemplate". Is this something that you added, or is it something new that's built into C# 2008?

Alex
07-02-2008, 08:50 AM
Is the error that you're getting the one still the same exact one that you posted here (http://forums.trossenrobotics.com/showpost.php?p=13069&postcount=101)? If not, could you please post the error you are getting?

Adrenalynn
07-02-2008, 09:56 AM
What that box is saying is that it's going to make directories that effectively belong to another user. So it doesn't trust them.

It's not that big a deal, really, assuming that there isn't any group policy preventing it.

You could extract them to another directory structure then re-index them in VS. It's a pretty small project - and that's what I do when I download his code. Alas I don't have a phidgets servo controller yet, so I can't get it to do much, I can only figure out where it thinks it's failing pre-initialization.

Adrenalynn
07-02-2008, 10:00 AM
CTX -

Don't get too frustrated. I've been programming for 30 years and there are still bugs in my code and garbage I forgot to do and ... There's a reason that Visual Studio can automatically insert ;, }, `', ... that you forgot. ;)

Do you know how you become a Software Engineer from a Jnr Programmer?

Take a pocket full of marbles. Every time you shoot a crashing bug, take a marble out of your pocket and drop it on the floor.

.

.

.

.

.

.

.

When you've lost all your marbles, you're a software engineer...

.

.

.

.

Alex
07-02-2008, 10:00 AM
Ah, I figured it out:) Your Timer wasn't set properly. You should always set the Timer.Enabled Property to false, until you are ready for the Tick event to start firing. In your case, the Servo Controller wasn't finished initializing and the Timer.Tick event started to occur and access the Phidget.Servo object.


Before I get into the fix though, I noticed a couple of other things:


In your Servo Attach/Detach event handlers, you have:



void Servo1_Detach(object sender, DetachEventArgs e)
{
Servo detached = (Servo)sender;
}
and



void Servo1_Attach(object sender, AttachEventArgs e)
{
Servo attached = (Servo)sender;

for (int i = 0; i < attached.servos.Count; i++)
{
try
{
attached.servos[i].Position = 0.0;
}
catch (PhidgetException)
{

}
}
}Notice the areas that I bolded above. As the end result, do you just want to display the Attached status on your form label, "labelAttachStatus"? If so, then all you'll need is to replace the bolded lines for:



labelAttachStatus.Text = Convert.ToString(e.Device.Attached);There's no reason to create new Servo objects, only to have them destroyed (and cleaned up by the Garbage Collector) at the end of the Event Handler. Sorry, I know, geek talk, hehe.


Anywoo, The other thing I wanted to mention before I get into the fix is in your Attach Event Handler. If you try and apply the fix I gave above, you'll notice quickly that you're getting errors in your attach event when compiling. Here's a little quicky that will save you a little time when you are in most Phidget Events.

That other parameter in the Attach/Detach event handlers, "AttachEventArgs e", is very useful. Why? because if, inside either one of these event handlers (or even some other Phidget Event Handlers), you type "e.Device", you are now accessing the original Servo object that you created for that particular event. There's also a bit easier way of doing your try... catch statement:




void Servo1_Attach(object sender, AttachEventArgs e)
{
labelAttachStatus.Text = Convert.ToString(e.Device.Attached);

try
{
for (int i = 0; i < ((Servo)sender).servos.Count; i++)
{
((Servo)sender).servos[i].Position = 0.0;
}
}
catch (PhidgetException ex)
{
throw;
}
timer1.Enabled = true;
}Notice the two bolded areas. The first one, "throw ex;" is something that you should generally put in a catch statement while you're debugging an application. This allows your program to physically crash, telling you, "whoops, something is jacked up at this try.. catch statement". There are other ways of Exception Handling, way too many to count. You by no means need to be an expert in Exception Handling, but you should definitely get an idea on what it's about and how to use it (http://www.google.com/search?hl=en&safe=off&client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&hs=Ri3&q=Exception+Handling+.NET&btnG=Search).

To finally get to the answer (hey, I told you that I like teaching :p), if you look at the last bolded line, "timer1.Enabled = true", this is what I was starting to talk about at the top of this post.

What you need to do is in your application in Form Design View, select "timer1" (below your form), right click on it and select "Properties". Set the "Enabled" property to "False". What this basically does, is what it sounds like, it disables your timer until you specify otherwise.

Now, in your Attach and Detach Event Handlers, you need to set the Enabled Properties (the new attach handler code is already show for you above):



void Servo1_Detach(object sender, DetachEventArgs e)
{
labelAttachStatus.Text = Convert.ToString(e.Device.Attached);

timer1.Enabled = false;
}

Adrenalynn
07-02-2008, 10:04 AM
See? Alex gets to drop another marble! (I edited my post, see above Alex...)

ctx32
07-02-2008, 03:40 PM
Geez guys, I'm almost in tears about this code.
It works PERFECT now!!!!

Both of you are worth GOLD to me and you have been really patient with me.
I know you have your own projects and others on the forum to help and that's why I
try to fix my code, But sometimes I make it worse.

Alot of my own code I don't understand, But I try other codes for the servos and watch
how they work and add pieces of it to my code. (I'm a code bandit I guess.)

The timer was added by Indy and I was trying to figure out how it works.
I knew something was wrong when the exception kept saying something about the timer.

Thank you Alex for the correct answer to my code
Thank you Adren for all your help you've been beside me the whole time.
And soon I hope to drop a marble!
I have 1 more post to make and I'll be OK for awhile.
Calvin

ctx32
07-02-2008, 03:46 PM
Guys,
Can you answer this:

My R2 will have an onboard Mini ITX comp and phidgets will controll all of R2's functions.
The question I have is:
Will C# coding be able to controll all the Phidgets and will I be able
to controll the computers sound through the gamepad to make R2 sounds?
And if so, Can I mix my gamepads buttons to assign different sounds?

This is all along way off from right now, But this is part of my R2 dream.
Thanks Guys!!!!
Calvin

Adrenalynn
07-02-2008, 03:53 PM
In reply to your second post: Yes and Yes.

Phidgets are universally supported in C# libraries (that I'm aware of).
Yup - you can make those game pad buttons do anything that Direct X is capable of doing. Absolutely sound is one of them. In fact, it's in the Direct Sound layer.

Think about video games. You press the fire button and you hear "BANG!", there ya go. R2 sounds or BANG! Same thing...

Can you have different buttons do different sound effects? Think about video games again: Press this button and you hear the door open, press that button and hear your head explode. Don't press _that_ button. :) But you get the point - absolutely.

And on the first post - you're welcome, but Alex has been doing the heavy lifting here!

Alex
07-02-2008, 05:16 PM
Yup - you can make those game pad buttons do anything that Direct X is capable of doing. Absolutely sound is one of them. In fact, it's in the Direct Sound layer.

You might even want to take the easy way out, skip direct sound and simply put if/else statements in your timer event and load up the sound object in .NET. I'm not too sure on exactly what object it is off hand, but I know there is an object that you can use to basically play a premade sound (like a mp3). Direct Sound may be much more efficient and I'm sure there are ways to tie buttons to sound directly, but I haven't done it. I always just used the if/else statements. I tell ya though, if you're running an ITX, I'm sure VIA will want to talk to you once this is all running:D

Adrenalynn
07-02-2008, 05:23 PM
The Sound event is actually calling Direct Sound for you...

From MSDN:



public class Sound{ private byte[] m_soundBytes; private string m_fileName; private enum Flags { SND_SYNC = 0x0000, /* play synchronously (default) */ SND_ASYNC = 0x0001, /* play asynchronously */ SND_NODEFAULT = 0x0002, /* silence (!default) if sound not found */ SND_MEMORY = 0x0004, /* pszSound points to a memory file */ SND_LOOP = 0x0008, /* loop the sound until next sndPlaySound */ SND_NOSTOP = 0x0010, /* don't stop any currently playing sound */ SND_NOWAIT = 0x00002000, /* don't wait if the driver is busy */ SND_ALIAS = 0x00010000, /* name is a registry alias */ SND_ALIAS_ID = 0x00110000, /* alias is a predefined ID */ SND_FILENAME = 0x00020000, /* name is file name */ SND_RESOURCE = 0x00040004 /* name is resource name or atom */ } [DllImport("CoreDll.DLL", EntryPoint="PlaySound", SetLastError=true)] private extern static int WCE_PlaySound(string szSound, IntPtr hMod, int flags); [DllImport("CoreDll.DLL", EntryPoint="PlaySound", SetLastError=true)] private extern static int WCE_PlaySoundBytes (byte[] szSound, IntPtr hMod, int flags); /// <summary> /// Construct the Sound object to play sound data from the specified file. /// </summary> public Sound (string fileName) { m_fileName = fileName; } /// <summary> /// Construct the Sound object to play sound data from the specified stream. /// </summary> public Sound(Stream stream) { // read the data from the stream m_soundBytes = new byte [stream.Length]; stream.Read(m_soundBytes, 0,(int)stream.Length); } /// <summary> /// Play the sound /// </summary> public void Play () { // if a file name has been registered, call WCE_PlaySound, // otherwise call WCE_PlaySoundBytes if (m_fileName != null) WCE_PlaySound(m_fileName, IntPtr.Zero, (int) (Flags.SND_ASYNC | Flags.SND_FILENAME)); else WCE_PlaySoundBytes (m_soundBytes, IntPtr.Zero, (int) (Flags.SND_ASYNC | Flags.SND_MEMORY)); }}
// To return a Stream object associated with an embedded// resource, you must prepend the namespace to the original// name of the file in the project.private void btnEmbedded_Click(object sender, System.EventArgs e) { Sound sound = new Sound (Assembly.GetExecutingAssembly().GetManifestResour ceStream("SoundSample.chimes.wav")); sound.Play();}private void btnFile_Click(object sender, System.EventArgs e) { Sound sound = new Sound ("Program Files\\SoundSample\\chord.wav"); sound.Play();}// To return a Stream object associated with an embedded// resource, you must prepend the namespace to the original// name of the file in the project.private void btnEmbedded_Click(object sender, System.EventArgs e) { Sound sound = new Sound (Assembly.GetExecutingAssembly().GetManifestResour ceStream("SoundSample.chimes.wav")); sound.Play();}private void btnFile_Click(object sender, System.EventArgs e) { Sound sound = new Sound ("Program Files\\SoundSample\\chord.wav"); sound.Play();}

Alex
07-03-2008, 08:30 AM
Ok, I dug up my old Pan and Tilt Shooting Gallery project from Maker Faire '07 and found what I was using to load & play mp3's:


Global:

System.Media.SoundPlayer soundPlayer;

I put this in my Form_Load Event Handler:

soundPlayer = new System.Media.SoundPlayer();
soundPlayer.SoundLocation = Application.StartupPath + @"\crowdCheer.wav";

I believe the Application.StartupPath is "\bin\Debug\" folder

Then, all you have to do in your application is wherever you want to play the sound use this single line of code:


soundPlayer.Play();

If you have multiple sounds that you'd like to play, you can do one of two things, A) use the same object for all of your sounds and just reload the correct file into the SoundLocation Property as you need to, Or B) Create a seperate SoundPlayer object for each sound you'd like to play.

You'll probably have to test out both to see what works best for you.

WAY easy stuff:)

Adrenalynn
07-03-2008, 09:32 AM
Ok, I dug up my old Pan and Tilt Shooting Gallery project from Maker Faire '07 and found what I was using to load & play mp3's:



Can we hear more about your PT shooting gallery [in another thread], Alex?

A couple of us here (Lamont and myself, at least) are working on DefConBots, which are precisely that - Pan/Tilt Shooting bots.

Donkey Shin!

ctx32
07-03-2008, 04:54 PM
COOL!!!
I will have maybe 6 different sounds I would like to key by the remote.
The other sounds I'd like to have them play say every 5 minutes.
So that R2 is not just standing there doing nothing.
If possible key the remote to play the Star Wars theme also.

Here's another idea, But much later down the line.
Is to have my Logitech Quickcam mounted behind R2's main eye
and code it so R2 will follow me around. I guess I would have to code
it to follow a certain color or something I could wear on my back.
But this will be way down the line.
Can the sound code be added like alex's joystick code?
His code is a seperate cs and then blended into my code.
Calvin

ctx32
07-04-2008, 08:11 AM
I need to order another 4 servo phidget controller soon,
So I can start working on the rest of my code.
I've got to study the functions of the push buttons on my gamepad.
I assume the joysticks are analog and the push buttons are digital.
If digital, I guess they send a signal of 0 or 1. Where 1 is the pushed setting.
Each button will control a servo and I will have to code each servo so it moves in the
correct direction.
I also hope to figure out how to control the speed of the servo.
I'll let you know what I come up with.
Calvin

ctx32
07-04-2008, 12:20 PM
This is what I know so far:
byte[] buttons = js.State.GetButtons();
string strText = "";
for (int x = 1; x <= 50; x++)
{
if (js.ButtonPressed(x) == true)
{
strText += x + " ";
}
}
ButtonPressedLabel.Text = strText;

This code above gets the state of my buttons being pushed/unpushed and sends the text number to my form
to be read as 1,2,3,4 etc button.

double ServoStep = 0.2;
Servo1.servos[0].Position = ((80 + js.State.X) * ServoStep);
Servo1.servos[1].Position = ((80 + js.State.Y) * ServoStep);
Servo1.servos[2].Position = ((111 + js.State.Z) * ServoStep);
Servo1.servos[3].Position = ((119 + js.State.Rz) * ServoStep);

The above code is for my Servo1 controller to control each servo on this controller by the joysticks.

I assume the new code to be added would be something like this for the second controller.
Servo2.servos[0].Position =((80 +js.State.?)*ServoStep);
The question mark is my problem.
I don't know which mark to add here, Because I have no idea how to find out the sign for each button.
Any ideas?
Calvin

Adrenalynn
07-04-2008, 04:28 PM
I guess I would have to code
it to follow a certain color or something I could wear on my back.
But this will be way down the line.

This can be done a few different ways. The camera is one of those, but not what I'd advise "in the wild". It's amazing how things we inherently think are "unique" aren't so unique in the nasty big bad world.

I'd suggest another way to do it would be a modified bicycle clip-on light. Pull it apart, solder IR LEDs in place of the regular LEDs, and reassemble. Then you would have either the camera (if it's sensitive to IR) or a dedicated IR photoresistor looking for a _specific_ flashing pattern. Of course, you can be even more confident in this "beacon" if you scratch-build it and program the receiver to look for an even more unique flash-code.

I've been having my beacons flash my ham radio call sign / the beacon number in CW (morse code) for awhile now. Practically guaranteed to be unique, and with the advantage of being human-readable.

indy007
07-05-2008, 02:19 PM
This is what I know so far:
byte[] buttons = js.State.GetButtons();
string strText = "";
for (int x = 1; x <= 50; x++)
{
if (js.ButtonPressed(x) == true)
{
strText += x + " ";
}
}
ButtonPressedLabel.Text = strText;

This code above gets the state of my buttons being pushed/unpushed and sends the text number to my form
to be read as 1,2,3,4 etc button.

double ServoStep = 0.2;
Servo1.servos[0].Position = ((80 + js.State.X) * ServoStep);
Servo1.servos[1].Position = ((80 + js.State.Y) * ServoStep);
Servo1.servos[2].Position = ((111 + js.State.Z) * ServoStep);
Servo1.servos[3].Position = ((119 + js.State.Rz) * ServoStep);

The above code is for my Servo1 controller to control each servo on this controller by the joysticks.

I assume the new code to be added would be something like this for the second controller.
Servo2.servos[0].Position =((80 +js.State.?)*ServoStep);
The question mark is my problem.
I don't know which mark to add here, Because I have no idea how to find out the sign for each button.
Any ideas?
Calvin



Sorry about the timer problem. I'm not sure why it didn't show up on my build. :(
You're looking at handling the button presses. I'm sure there's a fancy way to do it with joystick events, but I don't know anything about that. Here's how I did it:

Say I want button 3 to play a sound.

Now, what happens is the main timer reads the button every 100ms. If you press button 3 for 1 full second, it will run the assigned function 10 times. To prevent this, create a simple textbox, lets call it "Button3InUse", and add a label to say it's for button 3. Go ahead and give the textbox a default value of "NO".


if (js.ButtonPressed(thebutton) == true)
{
if (thebutton == 3) // check to see if button 3 is pressed
{
playbutton3sound(); // a function that plays the .wav
}
}
strText += thebutton + " ";
}
buttonspressed.Text = strText; // to quickly see what buttons are pressed, useful to debug

// Let's assume you used Alex's spiffy sound code.

private void playbutton3sound()
{
if (Button3InUse == "NO") // check to see if the textbox shows button 3 is not in use
{
Button3InUse = "YES"; // switch the textbox to show it's in use
soundPlayer.SoundLocation = Application.StartupPath + @"\button3beep.wav"; // set the .wav
soundPlayer.Play(); // play the wav
int LengthOfWav = 200; // may be required to prevent multiple runs of the file
System.Threading.Thread.Sleep(LengthOfWav); // may require Using System.Threading;
Button3InUse = "NO"; // switch the textbox to show it's no longer in use
}
}

those 2 may be required lines are in case it tries to run the wav multiple times. i don't think the thread will pause while the file plays. so you may need a delay that's the length of the wav to keep it from running multiple times.

This is probably the clunkiest way possible to do it.

ctx32
07-06-2008, 02:04 PM
Hey Indy,
I've got a few questions about the code in your post.
I found a video on sound files at: MicroSoft (http://msdn.microsoft.com/en-us/vcsharp/bb798022.aspx?wt.slv=RightRail) and it talks about different types of File .wav and .Mp3.
The Soundplayer will only play .Wav and I need to use mostly mp3.
It also told me to add the Windows Media Player to my form,
And Add this code to my ini.
string R2 Intro = @"C:\R2sounds\r2Intro.mp3";
windowsMediaPlayer.settings.autoStart = false
windowsMediaPlayer.URL = R2Intro;
It works, But I have no control from the gamepad.
Which I'm sure I need to code somehow.


I added this to my code from your post.

byte[] buttons = js.State.GetButtons();
string strText = "";
for (int x = 1; x <= 50; x++)
{
if (js.ButtonPressed(x) == true)
{
strText += x + " ";
if (x == 3)
{
//playbutton3sound(): I have this commented out for right now.
}
}
ButtonPressedLabel.Text = strText;
}
I'm not sure if the above is correct.

I also added down the code tree: The Private Void was created by C#
Private Void playbutton3sound ()
{
if (Button3InUse = "No")
{
Button3InUse = "Yes";

And that's as far as I have it now.
Could'nt the Private playbutton3sound be coded for the R2Intro.mp3
This way it would play the mp3 by pushing button 3.
Calvin

Adrenalynn
07-06-2008, 02:09 PM
Why not convert your sound files to wav? Shorter load times, lower memory utilization (additional storage requirements, though, but for short sound effects, wav will beat MP3 in usefulness every time)

ctx32
07-06-2008, 02:27 PM
Can .wav play music files?
Like the Star Wars theme?
Calvin

ctx32
07-06-2008, 02:36 PM
Ok I'll try it again but I'm confused about something.

To prevent this, create a simple textbox, lets call it "Button3InUse", and add a label to say it's for button 3. Go ahead and give the textbox a default value of "NO".
This is what Indy told me to do and I created the label and Textbox.
The default value of "No" for the textbox, You type this in the properties are under Text?
Calvin

Adrenalynn
07-06-2008, 03:04 PM
Any noise you can imagine can be encoded as a WAV file.

I'll betcha I could find the star wars theme already encoded as a wav in a few tenths of a second with a little google action... ;)

Adrenalynn
07-06-2008, 03:04 PM
Yup. I can.

http://www.ilovewavs.com/Movies/PT/Star%20Wars%20(John%20Williams%20Orchestra)%20-%20Movie%20Theme.wav (http://www.ilovewavs.com/Movies/PT/Star&#37;20Wars%20(John%20Williams%20Orchestra)%20-%20Movie%20Theme.wav)

Dang it. Won't let me deep link...

How bout this?

http://www.ilovewavs.com/Movies/PT/PT.htm

ctx32
07-06-2008, 07:10 PM
Thanks Adren,
I went back and started adding the Soundplayer code and I tried to do it the way Alex showed me,
But it would'nt work for me that way. So I went back to MicroSoft and watched the video on Soundplayer and got it added to my code.
It works by a button on my form and now I need to try and add the code that Indy sent me to get it working from a button on the gamepad.
I was messing around with the code and somehow I messed it completely up and nothing would work.
So I downloaded my own code and I'm back working again.
Glad I sent it to the group.
Calvin

Adrenalynn
07-06-2008, 08:00 PM
That's good advice. Always keep snapshots of your code. If it's a big project, then version control systems are the way to go. Otherwise, I tend to zip them up in their entirety a few times a day and name them by day-date. When I'm done with a good sized project, I burn a couple CDs of all the snapshots and toss 'em in my safe for a rainy day. ;)

ctx32
07-07-2008, 12:52 PM
I'm having trouble with this part:
if (js.ButtonPressed(thebutton) == true)
{
if (thebutton == 3) // check to see if button 3 is pressed
{
playbutton3sound(); // a function that plays the .wav
}
}
strText += thebutton + " ";
}
buttonspressed.Text = strText; // to quickly see what buttons are pressed, useful to debug

I'm assuming this part goes just below the area:
byte[] buttons = js.State.GetButtons();
string strText = "";
for (int x = 1; x <= 50; x++)
{
if (js.ButtonPressed(x) == true)
{
strText += x + " ";
}
}
ButtonPressedLabel.Text = strText;

Or does it get mixed into this code?
The problem I'm having is the (thebutton). Am I suppose to change this to something?
It say's it does not exist in the current context.
Calvin

ctx32
07-07-2008, 01:04 PM
Now I feel really STUPID!!!!
The button is the button you push which is 3.
I should have known that.
Calvin

ctx32
07-07-2008, 02:27 PM
I have it running now, But the textbox button3inuse is not reading yes/no.
I also in the IF statement had to add .Text to the button3inuse because it kept erroring on me.
Would this stop the textbox from working?
Calvin

ctx32
07-07-2008, 02:43 PM
Hey Indy,
Is there a way to mix button numbers in the code?
Instead of IF (1==1).
I need to dedicate button 7 to access the sounds and while holding button 7, Chose button 1-4 for a certain sound.
Calvin

ctx32
07-07-2008, 03:11 PM
Sorry about all the post, But I figured it out!!!!!!
I added :
IF (js.buttonpressed (7) == true
IF (7 == 7)
I added this to the code and now if I hold button 7 and then push button 1 my sound fires.
I must be learning something!!!!
I'll drop a marble YET!!!
Thanks Guys
Calvin

Adrenalynn
07-07-2008, 04:07 PM
Good work!

Generally we'd use a conditional AND operator there. For cleanliness if nothing else...

Something like if ((js.buttonpressed(7)) && (js.buttonpressed(1)))

ctx32
07-07-2008, 06:53 PM
Something I meant to ask you guys.
In the resources of my code I can store the sound files and various files.
I put the tada.wav in there as I was working my code, But I noticed if I try to
code the Soundplayer to use these files it gives me a problem telling it where the files are located.
So I have been putting them in a file on my hard drive and telling it to go there.
I know I'm doing something wrong.
I have stopped uploading my code for this reason as it will make the code crash if anyone is interested
in downloading the code.
I'll post more about this tommorrow.
Calvin

ctx32
07-08-2008, 03:34 PM
Hey Guys,
Is there a code or should I say path to the volume on a computer?
Sound player, I don't think it has this option.
Calvin

ctx32
07-09-2008, 05:58 AM
I found a code that works the wave sound volume.
So I'm adding it into my code.
Once I get it blended, I'll see if I can get my buttons to work the up/down of the volume.
Calvin

ctx32
07-09-2008, 05:30 PM
Here's the code I'm playing with:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace VolumeControl
{
public partial class Form1 : Form
{
[DllImport("winmm.dll")]
public static extern int waveOutGetVolume(IntPtr hwo, out uint dwVolume);
[DllImport("winmm.dll")]
public static extern int waveOutSetVolume(IntPtr hwo, uint dwVolume);

public Form1()
{
InitializeComponent();
// By the default set the volume to 0
uint CurrVol = 0;
// At this point, CurrVol gets assigned the volume
waveOutGetVolume(IntPtr.Zero, out CurrVol);
// Calculate the volume
ushort CalcVol = (ushort)(CurrVol & 0x0000ffff);
// Get the volume on a scale of 1 to 10 (to fit the trackbar)
trackWave.Value = CalcVol / (ushort.MaxValue / 10);
}

private void trackWave_Scroll(object sender, EventArgs e)
{
// Calculate the volume that's being set. BTW: this is a trackbar!
int NewVolume = ((ushort.MaxValue / 10) * trackWave.Value);
// Set the same volume for both the left and the right channels
uint NewVolumeAllChannels = (((uint)NewVolume & 0x0000ffff) | ((uint)NewVolume << 16));
// Set the volume
waveOutSetVolume(IntPtr.Zero, NewVolumeAllChannels);
It sets the trackbar acording to the wave volume control XP has built in.
But it's not controlling the volume for some reason.
I thought if I could get this working and then somehow attach my gamepad to the code I could control the volume.
Calvin

ctx32
07-09-2008, 06:01 PM
Hey Guys,
Forget all that above, I'm going another route.
But I'll leave the post incase it's interesting.
Calvin

ctx32
07-09-2008, 06:05 PM
I currently have button 7 and 2 on the gamepad controlling a sound.
Is there a way for the same buttons if pressed again to stop the sound?
Calvin

Adrenalynn
07-09-2008, 06:11 PM
call Dispose on your event.

So if you had something like m_Player instantiated (not sure what yours looks like now...) you'd do something like: try{m_Player.Dispose();} or better:

private void Stop()
{
if (m_Player != null)
try
{
m_Player.Dispose();
}
finally
{
m_Player = null;
}
}

Replace m_Player with whatever your object is named.

ctx32
07-10-2008, 07:07 PM
To compile a .cs, What does this mean and how is it done?
Is this the same thing as rebuild?
Thanks
Calvin

ctx32
07-10-2008, 07:21 PM
Just for safe keeping and I did'nt want to upload to the Members area,
Because my sound files are not in the program and it will crash without them.
Calvin

ctx32
07-10-2008, 08:30 PM
I'm playing around with my sound files and SoundPlayer.
I changed 1 of my files to use WindowsMediaPlayer instead and it works great.
I also found the the sound volume can be controlled with code:
WindowsMediaPlayer.Settings.Volume = 10; ( I guess 10 trough 100)
This has got me thinking of a way to control the volume with my gamepad.
Maybe something like:

if (js.ButtonPressed(8) == true)
{
if (8 == 8)
{
windowsMediaPlayer.Settings.Volume = ?
}
The question mark is what I have'nt figured out yet. This would be for lowering the volume.
I think there has to be a varible? Something that will allow the volume to lower each time you push
the button and it would drop the volume in stages. Say by 10 each time you push the button.
And there would be a code like above for button 9 to increase the volume.
Calvin

Adrenalynn
07-10-2008, 10:31 PM
When you rebuild, you compile and link. Compiling is converting it to "object code" - going from human readable to machine readable. Linking is where you go out and pull in the libraries that you need, also in machine readable form, and joining them into your code.

"rebuilding" is just the combination of those steps.

To protect Trossen's expenses in maintaining the site, I'd suggest as a general rule not to archive your Resources directory here every time. Your code is about 200KB, your mp3 file is 3MB. Don't need it more than once tops... At least until your final release. But that's just my suggestion.

Adrenalynn
07-10-2008, 10:37 PM
I'm playing around with my sound files and SoundPlayer.
I changed 1 of my files to use WindowsMediaPlayer instead and it works great.
I also found the the sound volume can be controlled with code:
WindowsMediaPlayer.Settings.Volume = 10; ( I guess 10 trough 100)
This has got me thinking of a way to control the volume with my gamepad.
Maybe something like:

if (js.ButtonPressed(8) == true)
{
if (8 == 8)
{
windowsMediaPlayer.Settings.Volume = ?
}
The question mark is what I have'nt figured out yet. This would be for lowering the volume.
I think there has to be a varible? Something that will allow the volume to lower each time you push
the button and it would drop the volume in stages. Say by 10 each time you push the button.
And there would be a code like above for button 9 to increase the volume.
Calvin

Yeah, something like this:

public short volumeLevel=50; // half volume on entry to the function. We want to do this ONLY ONCE when we make our global declarations. A short is a CTS Data Type of Int16, a 16 bit integer. 0-65,535. We could use a larger data type, but I come from the days where memory wasn't "free"... We could also use the CTS Data Type: "System.Int16 volumeLevel=50;" Name the variable whatever you want.

if (js.ButtonPressed(8) == true)
{
if (8) //(8==8 is a logically true statement. We don't need to be that verbose. Research "case" statements, too.
{
volumeLevel--; //decrement i by the step size, step=1 by default
windowsMediaPlayer.Settings.Volume = volumeLevel;
}
if (9)
{
volumeLevel++; //increment by step size
windowsMediaPlayer.Settings.Volume = volumeLevel;
}

Obviously this is just pseudo code, but it might give you a direction to start thinking about...

Adrenalynn
07-10-2008, 10:47 PM
Have you bought a good C# book yet? It's definitely time...;)

ctx32
07-11-2008, 06:35 AM
I did'nt think about the storage and the expence of the site.
I won't do that again, Thanks for pointing that out.
Yeah, I got 2 books on C#. I bought C# for Dummies and C# by Deitel.
I've been studying both books and I'm picking up some from both, But I've been working
at my code so hard I need to get back to the books.

Last night after I posted, I was thinking of the volume-- and the volume++,
Although I was thinking of calling it by just a letter, I guess this letter would have
done the same thing?
I knew it would be used in here somehow and I was thinking of useing an Int.
But I was thinking of using it in the button part of the code. I did'nt think about
a Global that could be used in different parts of the code.
Thanks Adren, Hopefully soon I will be able to just post my updates and instead of needing
so much help. Still allot to learn.
I've got a R2 Builders meeting the 27th in Clearwater, Fla. to attend and can't wait to show off the code and all the help you guys have been.
Calvin

ctx32
07-11-2008, 02:36 PM
Thank you Very Much Adren for the volume code help.
Guys I think from here on out I may be able to finish my code alone. (Scary!!)
Alex, Indy, and Adren I could not have gotten this far without your help.
I will continue to study my books and hope you don't mind if I pop back in
every once in awhile to ask more questions and to say HEY.
I'm still in the dark about things like:
How to control the servo speed,
How to set the servo position by a button,
And how to get to the POV settings to attach them to a servo.
I want to try and work this out by myself, So I can have post saying "Look what I did".
Thanks again guys, I learned alot from you all.
Calvin Thomas

Adrenalynn
07-11-2008, 03:50 PM
Don't go running off though! We expect you'll still be a regular! :) I know *I* certainly want to follow along with your progress! Congrats on just taking the plunge and learning it!

Yes, you could name the variable anything you want, even a single letter. We don't generally do that if we don't have to. (I originally named the variable "i" for "integer", then went back and changed it. The reason we don't do that is because it makes it almost impossible to read later. Even for the programmer that wrote it. Imagine coming back to your code a year later and trying to figure out what the heck you were thinking when you wrote it... Having descriptive variable names (and good comments!) are the two most important things you can do for maintanence of your code.

Notice the variable name I chose and also how I commented the code. The comments were a little excessive maybe, emphasized to help you understand what I was doing, but imagine if you came back a year or two later how much easier it'd be to follow along!

I'd suggest you even comment things like that "if(8) // if button 8 is pressed then..." . As you learn and grow, the spaghetti that you write today is going to look unreadably ugly tomorrow. As a novice programmer you're not doing things in the most optimal way today. That's fine and expected. But at some point you're going to want to go back and clean up your code with the new things you've learned. Save yourself the hassle now before it's too late, and you'll thank me later...

The things you're wanting to do are really more of the same. You have the basic skills required now to do what you're looking for.

Good luck, and let us know if you get stuck!

P.S. I chose a "short" instead of an "int" because it requires half the program memory, and can handle values from 0-65535. Since by definition that variable will never contain more than 10-100, there's no reason to burn twice as many bits. I could have used an "int" [and so can you] - but why burn bits you don't need?

Learn the data typing in whatever platform and language you're using. They're your friends. :)

ctx32
07-12-2008, 05:51 PM
Oh no, I'm not going anywhere I just don't want to become a pain asking so many questions.
And I need to understand my code, So I'm not totally in the dark.
Most of it I do understand, I just need to work at learning C# more.
I'll keep you guys updated.
Calvin

Alex
07-12-2008, 10:11 PM
no pain at all Calvin, I'm (as I'm sure others) glad to have you here! As I mentioned before, I love helping people out with programming. Unfortunatley, I've been beyond swamped this last week and a half, so I've been pretty absent from the community:(

Adrenalynn - I couldn't have said that better myself. THE most important thing to do when first starting out in programming is to use very descriptive variable names and to comment the hell out of every aspect of your code. I laugh my ass off at code that I look back at that I wrote when I first started programming. It really helps me to build up my own confidence in knowing just how much I've learned between now and then.

One thing to note though Calvin, with Phidgets, you cannot control the speed of servos, just the position. I can't remember off hand if you are using Phidgets though (this thread is like 16 pgs long and I'm drunk, hehe;))

Adrenalynn
07-12-2008, 10:18 PM
Another thing to love about the SSC-32. :)

Alex
07-12-2008, 10:25 PM
most def, but if you're programming the SSC 32 in C#, you have to understand serial command programming:( Until one of us develop a .NET wrapper at least

ctx32
07-13-2008, 06:13 AM
Hum, Can't control the speed?
Maybe use a servo slower inline between the Phidget and the servo?
There's noway to trick the Phidget using a code that pulses instead of just
telling the Phidget to move the servo? Or maybe just move the servo to increasing
positions, But the timing would have to be worked with great care.
There has be to someway to do this because I did it with Vex which is just a micro controller and
they use C.
Hum
Calvin

Alex
07-13-2008, 03:45 PM
Well, with a little bit of some sexy code, you can create a timer app that'll basically increment the servo positions by X increments at Y ticks per second, making it "appear" that your controlling the speed of the servo. But, as you mentioned, you'll have to find a nice balance of the speed vs. increment.

Adrenalynn
07-13-2008, 03:49 PM
you'll have to find a nice balance of the speed vs. increment.

I'd contend to do it "right" you'd need to throw another couple terms in there - speed vs increment vs "chatter"/accuracy vs wear-and-tear on the servo drivetrain.

BTW, Alex, I think I posted a dozen lines of code or so for handling serial communication in C# awhile back. Did you see it?

ctx32
07-13-2008, 05:14 PM
Just a question Guys,
Has anyone here tried TinyXp or Nlite for Xp?
I'm trying to get my OS setup for the Mini Itx and would like to cut Xp down in size.
Also, When your running your comp on Xp as the main board,
Will it be a problem with Xp not having the mouse or the keyboard connected all the time?
I assume you start your program and then disconnect these pieces along with the monitor
and everything will still run.
Calvin

Alex
07-13-2008, 07:53 PM
I haven't tried either, but here's a thread that might help ya out a bit:

http://forums.trossenrobotics.com/showthread.php?t=1500&highlight=strip+XP

:)

About not having a keyboard or mouse: there's really no problems with it, but you have to make sure that you have the proper fail safes in place with your application.

ctx32
07-13-2008, 08:14 PM
Fail safes, Would that be a code that will allow the mouse and keyboard to be unplugged
and not freakout Xp?
Oh, I just made a copy of stripped down Xp with Nlite and it cut about 250 meg out of Xp.
I've read about others cutting it down alot smaller though.
Calvin

Alex
07-13-2008, 08:51 PM
BTW, Alex, I think I posted a dozen lines of code or so for handling serial communication in C# awhile back. Did you see it?

It sounds really familar, but I looked through this thread and couldn't find it... I started a C# 2005 wrapper for the SSC32 about two years ago. I didn't have that much experience with sending serial commands to/from devices, let alone using that in conjunction with the SerialPort object. So... needless to say, I didn't last long, haha. I spent about a week researching serial communication, the SSC32, and finally the SerialPort object. Then, about a week into development, I realized what sort of project I was looking at with the limited knowledge I had, so we (matt and I) decided to scrap the project. I have it on my list of things to do now though. My guess is that it'd probably take me about 2-3 days now:)

I have no idea why I felt the urge to share that... :rolleyes:

Adrenalynn
07-14-2008, 12:08 AM
You can strip too much with nLite accidentally so think through it carefully. One of the early things it wants to tear-out is Direct-X. Just be cautious and know what you're stripping. I run nLited distributions on all my machines...

ctx32
07-14-2008, 01:23 PM
I don't want to strip it down too far, Just get the screen savers and things I know I'll never use.
I'll probly work it 3 or 4 times before I get a version I like.
Can you guys explain to me about the fail safe alex is talking about?
Calvin

ctx32
07-14-2008, 05:02 PM
I was playing around with my code and a question popped up.
Is it better to store your sound files in the resources or in a seperate folder on
the hard drive?
If resources is the best way,
I assume you would have to put:
using System Resources

private System.Resources resources;

The reason I ask is I've tried to get to the resources file and when I'm codeing
without the above it does'nt seem to work.
Unless I'm using the wrong path.
Calvin

Alex
07-16-2008, 08:53 AM
Can you guys explain to me about the fail safe alex is talking about?Basically, you need methods set in place to stop your robot when nasty things like your robot going out of control start happening. Remember Murphy's Law (http://en.wikipedia.org/wiki/Murphy&#37;27s_law); learn it, live it. Your bot will have some "unintended results", it's inevitable. However, there are things that you can do, that when your R2D2 does start chasing down children, you can slap the ruler on it's metal head and tell it to stop;)

Things to think of:



Without a keyboard and/or mouse (which obviously you don't want to have with an R2D2 bot), think of other ways to kill the robot in it's tracks if needed
What happens when your wireless remote looses communication with your PC?

This is just a couple of things I can think of off hand. The latter, I never did figure out, but then again, I wasn't too experienced with programming back when I originally developed that app using DX DirectInput.



I was playing around with my code and a question popped up.
Is it better to store your sound files in the resources or in a seperate folder on
the hard drive?I really don't know if there is a more "efficient" way of doing it. I'm betting that using the resources feature is far more easier and convenient than what I did in this post (http://forums.trossenrobotics.com/showpost.php?p=13517&postcount=121).

ctx32
07-16-2008, 03:06 PM
Now I know what you mean about Fail Safe.
I was planning on adding some type of sensor under one of R2's dome panels and if he goes nuts
on me I could slap that panel and kill all power to him.

Does'nt Xp go nuts when you don't have a keyboard/mouse connected?
Although I was planning on putting a portable touchpad inside him.

Alex, Thank you for the help with sound player, But I switched over to Media player.
I have more than sound files to add to the code and needed video and mp3 control.
Calvin

Adrenalynn
07-16-2008, 03:19 PM
Naw, as long as your BIOS plays nice, you can run XP headless. A few things to consider:

Make sure to "halt on no errors" in BIOS. Plug in a USB keyboard and mouse and make sure Windows finds and installs the drivers for them. Once you've done that once, you can hot plug key/mouse any time you want. Make sure your video card allows hot-plugging the monitor. Some MiniITX boards will default to composite video if they don't see a VGA monitor - if that happens, you'll have to reboot any time you want to plug in a monitor to it.

Install ultravnc on it [http://ultravnc.sourceforge.net] so that you can log into it remotely if the need or desire arises.

Don't forget to run the userpasswords hacks to make Windows XP autoboot into the desired user.

ctx32
07-16-2008, 03:36 PM
That Ultravnc would be AWESOME!!!
Then I would'nt have to open R2 just to do some comp work.
I could'nt find anything concerning Hot plugging the monitor on the board
I'm wanting to buy. http://www.logicsupply.com/products/d201gly2a
The only time I would need the monitor is to work on code, But maybe that Ultravnc
would be better than hooking a monitor?
Calvin

Adrenalynn
07-16-2008, 03:46 PM
95&#37; of the time you can do anything you want to do over VNC (Virtual Network Computing). There are those rare times when it doesn't cut it and you have to get at the machine directly.

All of my remote servers that aren't Linux have UltraVNC on them. They have to have someone touch them about once every 18mo. Generally that's my cue to yank 'em out and upgrade/replace the hardware.

My windows media machine underneath the stairs has been there for three years and I've never had to physically touch it in that time. It does have a remote power-booter on it though so I can reboot it over the network. (Effectively a network controlled relay)

ctx32
07-16-2008, 04:24 PM
I found the newer board Intel has out and it might be a better selection.
It also said this:

Booting Without Attached Devices

For use in embedded applications, the BIOS has been designed so that after passing
the POST, the operating system loader is invoked even if the following devices are not
present:

• Video adapter

• Keyboard
• Mouse
I may get this one and the price is about the same.
Calvin

Adrenalynn
07-16-2008, 04:30 PM
Is the other featureset the same? Because it's really not that special.

ctx32
07-16-2008, 04:48 PM
Actually Better,
Better video, sound and more options.
It also say's lower power demands.
Here's the link:
http://www.logicsupply.com/products/boxd945gclf
Calvin

Adrenalynn
07-16-2008, 04:50 PM
I didn't see current draw in there. What are you planning to power it/them with?

The PicoITX is low enough current draw to run from the PicoPSUs.

ctx32
07-16-2008, 06:19 PM
I currently have 2 - 12v batts in a 24v. configuration for the main drive motors
and have 2 more 12v. for just 12v.
I can add 2 more 12v. batts if needed.
Sorry I can't get to the actual size of the batts, Because they're mounted right now.
Is this what tells it:

Table 7. Power States and Targeted System Power

Global
States
Sleeping States
Processor
States
Device States
Targeted System
Power (Note 1)

G0 – working
state
S0 – working C0 – working D0 – working
state.
Full power > 30 W
G1 – sleeping
state
S1 – Processor
stopped
C1 – stop
grant
D1, D2, D3 –
device
specification
specific.
5 W < power < 52.5 W
G1 – sleeping
state
S3 – Suspend to
RAM. Context
saved to RAM.
No power D3 – no power
except for
wake-up logic.
Power < 5 W (Note 2)

G1 – sleeping
state
S4 – Suspend to
disk. Context
saved to disk.
No power D3 – no power
except for
wake-up logic.
Power < 5 W (Note 2)

G2/S5 S5 – Soft off.
Context not saved.
Cold boot is
required.
No power D3 – no power
except for
wake-up logic.
Power < 5 W (Note 2)

G3 –
mechanical off.
AC power is
disconnected
from the
computer.
No power to the
system.
No power D3 – no power for
wake-up logic,
except when
provided by
battery or
external source.
No power to the system.
Service can be performed
safely.
Notes:
1. Total system power is dependent on the system configuration, including add-in boards and peripherals
powered by the system chassis’ power supply.
2. Dependent on the standby power consumption of wake-up devices used in the system.

DresnerRobotics
07-16-2008, 06:22 PM
Any modern motherboard/cpu will boot into it's OS without keyboard/mouse/monitor.

Adrenalynn
07-16-2008, 10:11 PM
Whew. 52.5 W. About 4x a PicoITX. About 4.5A at 12v. So you might get 3/4 hour out of a 4500mAh battery at 12v. BUT, the wide input 60wt power supply won't work. You'll need something larger like the 160wt. Which will have more loss. And you need a P4 plug on it for that board...

ctx32
07-17-2008, 01:55 PM
I don't know why that says the power consumption is so high.
Everything I could find on the web says low power.
Calvin

ctx32
07-17-2008, 02:26 PM
I'm reading through my books and looking online for an answer,
But I can't find it.
After I complete my code, How do I create an .exe for the program?
Calvin

ctx32
07-17-2008, 02:44 PM
That might have just been a STUPID question.
I'm assuming the .exe is the one allready in the .bin file?
I quess a desktop shortcut would be the way to keep it available?
Calvin

Alex
07-17-2008, 02:54 PM
Yep:)

You can also create an installation file, which will install the exe into a folder you specify in your Program Files directory, in addition to any required files to run your application. I'm not sure if that feature is available in .NET Express, but if it's not, just PM me.

Adrenalynn
07-17-2008, 03:08 PM
60 watts is "low power" compared to the average 300wt desktop these days - it's just crazy high power compared to a PicoITX at 13wt

ctx32
07-17-2008, 06:25 PM
Ok, Alex is pretty quick on my Stupid questions HAHAHHAAAAA
Sometimes I look at my post and wonder why I did that. LoL
You know when I 1st started this thread I really didn't know diddly,
And now I'm learning and starting to catch myself with these questions.
Still got along way to go though.

Man, 13w.?
I hope this board does'nt make me hate life, Because I ordered it today.
Hey, Maybe instead of stupid questions, I'll make stupid purchases HAAHAHHAHAA
You guys brightend my dull day today, You made me laugh.
Thanks Guys
Calvin

Adrenalynn
07-17-2008, 11:11 PM
Which board did you end-up with?

ctx32
07-18-2008, 10:38 AM
I bought the Intel D945GCLF.
Hopefully the power consumption is lower than expected.
I've been reading more about it and test showed less, But it was still about 36w.
I may have to stuff R2 with bigger batts.
Calvin

Adrenalynn
07-18-2008, 10:43 AM
Which power supply did you get for it? You plan on running it from battery so you needed a Wide Input supply, right?

ctx32
07-18-2008, 11:02 AM
I have'nt ordered the power supply yet.
I will need one for setup off Ac and then I will need one for running off the batts in R2.
Any ideas?
Calvin

Adrenalynn
07-18-2008, 12:04 PM
This would probably do the job for you: http://www.logicsupply.com/products/m2_atx depending upon how many peripherals (read hard drive, CD, etc) you're looking to run.

Then for wall power, I'd look at something along these lines: http://www.logicsupply.com/products/powerkit150

ctx32
07-18-2008, 02:49 PM
The hard drive I was thinking of using a Emphase 40-pin Industrial Flash Disk Module 4GB - 4000X (http://www.logicsupply.com/products/fdm40xdi4g)
instead of a regular HD, Due to the rough ride R2 will provide.
And the Slimline DVD player, I'll probly hardly ever use.
The Phidgets would be the only thing pulling power from the motherboard and 3 of the 4 servo's per
Phidget will get external power.
Logic supply recommended this Dc-Dc power : Automotive 90W DC-DC Power Supply (http://www.logicsupply.com/products/m1_atx)
What do you think?
If I keep that MB down on Preps. It should pull less power?
I'm not sure, But got to get it figured out.
I would like to someday, Find away to run AC or DC when possible.
That way if R2 is stationary I could plug him into AC and Dc when I need it.
I also have to concider charging the batts without destroying the electronics.
Calvn

Adrenalynn
07-18-2008, 02:59 PM
With a flash disk, make sure you turn off the paging file system as it will chew-up the limited number of write cycles the flash is rated for.

I think that 90wt is under-rated for the task. How much memory are you adding (RAM)?

The cost difference between a 90 and a 160 is almost nothing, the 160 is in stock, the 90 isn't.

Aha - proof enough: Their own page states "Do not try this (m1) PSU with P4 mainboards"

The m2 also has some nice power management features that the m1 doesn't. Every time you flatten lead acid batteries, you put undue strain on your charger and tremendous strain on your batteries. The power management features that allow for clean shutdowns are really important.

The charging circuit is entirely separate from all of this, and will be dependant upon your battery choice. These are _not_ chargers.

ctx32
07-18-2008, 03:10 PM
Do you think the Flash disk is needed?
Would a Laptop Hd be good enough?
Memory, It will hold 2 gig, But I though 1 gig was enough.
I'm glad you know this stuff, They recommended the wrong supply.
Does there need to be something isolating the comp from the batts while charging?
calvin

Adrenalynn
07-18-2008, 03:44 PM
If you used a hard drive, I would shock isolate/insulate it.

We built DVRs (Digital Video Recorders) for the trucking industry. Very harsh environs. My prototype used rubber grommets/spacers between the hard drives and the frames. The rubber spacers damped out all the high frequency vibration. We put the whole thing on gel pads which damped the low frequency vibration. A couple of my original prototypes are still running more than a million harsh miles later.

Flash drives are nice, but they have very limited write cycles and tend to be smallish/expensive-ish. I'd probably use a data voyager 32GB just so I could have a "real sized" flash-based hard drive cheaply. I'm not sure for your application that the industrial solutions are required.

If you're using a flash drive with paging turned off, more memory is better. It should basically be about Net-0 power-consumption-wise. If you remove the HD, you get rid of moving parts = less power consumption. Adding more memory to the motherboard = more power consumption. Memory is nearly free these days, so adding another 1GB to it isn't the end of the world, I'd think.

Ideally your computer would be disconnected, either physically or electrically, from the circuit whilst charging. Those power supplies are pretty tolerant though - they're meant to be run in the harsh environs of vehicles which are constantly charging and discharging.

ctx32
07-19-2008, 10:43 AM
Adren,
I think I'm going to try your idea about the hard drive mounting.
The price is allot better and if it failed no big deal.

I've been reading more about nLite and learned more about how to use it.
I'm not going to shrink Xp much though.
Bought another book on code and working through it now.

If I wanted my code to run when Xp starts, Do I just add a shortcut in the start up file?
I meant to ask you also, Do you know of a small VGA monitor without touchscreen?
I've searched the web and everything I find has touchscreen.
Calvin

Adrenalynn
07-19-2008, 10:49 AM
I can post more info on shockmounting drives for you then.

Yes, you would just drop it in the startup, unless you write it as a service - which you'll probably end-up going back and doing at some point. For the moment, though, startup is fine.

What you're looking for are called "headrest monitors". I have a bunch of 'em around here. if you type headrest-monitor into google, you're set.

Examples: http://www.mobilevideo4less.com/headrest.html

Adrenalynn
07-19-2008, 11:07 AM
I'll probably regret this - and I don't have time at the moment to really expand upon this, but I wanted to get this idea out whilst I was thinking about it.

Here's an idea that would really make your R2 unique, I believe.

A "poorman's LCD project" (you should be able to search on that, or lookup LCD projector on Instructables, I'm sure. If not, I'll document further) is basically an LCD monitor and a surplus projection lens. It can project an LCD image some number of feet.

Several years ago I worked on a haunted house/yard for a neighbor. I used a fog machine and super-cooled the fog (more on that in a moment) to get it to hang low to the ground and be thick in consistancy, then projected "ghosts" onto the thick fog. It had a remarkably 3D holographic effect.

The way I supercooled my fog was by creating an output tube from copper pipe, and then putting a peltier junction (a "TEK cooler" or "TEK chiller" in overclocking parlance) on the copper pipe. Even on a warm evening I could bring my fog down to below zero F if I desired.

So if you were to replace R2's holoprojector with a projection lens, put a little 4-5" LCD behind it, and give him a small copper pipe at the bottom, he could put down a little fog, and then project a very 3D-ish pseudo-hologram onto the fog "screen".

I would mock it up in the lab before I started modding R2, but if you get bored, maybe it's something to think about?

Adrenalynn
07-19-2008, 11:21 AM
http://www.instructables.com/id/DIY-Projector-on-the-Cheap/

Think about LED lighting to keep the heat and power down. Probably like Cree 3wt chips and light diffusion panel from the home improvement store. Watch the focal length.

http://www.crazypc.com/products/5910.html Read up on using peltier junctions in computers for overclocking. There's more that goes into this than just this. At the very least a *good* heatsink, or you will crack the chip

http://www.sciplus.com/category.cfm/subsection/category.cfm/subsection/21 Surplus lenses. Do a "show 98 on a page" and look about halfway down for projection lens

ctx32
07-19-2008, 01:47 PM
Thanks Adren,
I'll keep that in mind.
There is 1 of our builders that has taken a toy type (Low cost) projector and modified it big time
and put it in the Holo. But he has to project the image on a wall.
His is neat, But not really all that cool.
Calvin

ctx32
07-21-2008, 04:52 PM
I don't have anything to write into my code right now,
So I'm back to the books and the tutorials.

I do have a couple of questions to ask:
In this code,

if (js.ButtonPressed(9) == true)
{
if (9 == 9)
{
Servo2.servos[0].Position = ((80 + js.State.GetButtons) * ServoStep);
}

Would this give me access to Servo controller #2 and Servo 0 (Which is really servo #1).
And I understand the Joystick State Button part.
The Servo Step I think is avalue to move the servo in pulses?
This leaves me with the 80+.
I understand it controlls the movement of the servo, Because I had to adjust it before.
Now if I wanted to move a servo a certain direction if the button is pressed, Would I just adjust
the 80 or does this need the be written differently.
Calvin

Alex
07-22-2008, 01:24 PM
Would this give me access to Servo controller #2 and Servo 0 (Which is really servo #1).

It depends on the way that you have your application setup, but if Servo2 is indeed your #2 servo controller, then yes, that snippet of code would give you access to this.

js.State.GetButtons has nothing to do with positioning your servo. About the ServoStep; When you're using the Phidgets API (Application Programming Interface - the thing that you make a reference to in order to use the Phidgets) do not think in terms of Servo Pulses. Think in terms of servo motor positions (and not angular positions). Check out the docs on the PhidgetServo motor controller (http://www.phidgets.com/documentation/Phidgets/1001.pdf) and the Phidgets Programming Manual (http://www.phidgets.com/documentation/Programming_Manual.pdf) for more info.

It looks like you're trying to get a little ahead of yourself though Calvin, which will def. cause you some major headache. In addition to the links above, what I'd also recommend is checking out the code behind Phidgets' demo example for the PhidgetServo motor controller. Once you fully understand what you can/cannot do with the servo controller and the Phidgets API (and how to use it), then go back to your joystick code and learn about what the different areas return. There are a TON of things to learn here, so just take it one step at a time. Don't get ahead of yourself and take your time. Don't try to learn more than one topic at a time when it comes to this sort of stuff. Trust me, you'll save a lot of uneccessary stress.

Just my $0.02 though:D

ctx32
07-22-2008, 06:35 PM
Yeah, I have it commented in my code for later use as Servo controller #2.
And I figured it was basically a repeat of the 1st controller, Just different
actions to code.

The js.State.GetButtons that is the code getting the status of the button,
Pressed - which is probly a 1 and unpressed - which is probly a 0.
Because the buttons are digital, correct?

I should have caught myself about the pulses, I knew it meant position,
Since I did adjust it to make my Syren motor controller stop turning the motor.
As it was still getting a signal from the Phidget controller.

So, I guess all that was needed to set the position of the servo was:
Servo2.servos[0].Position = ((80) * ServoStep);

I'm working the books, But what it has me doing is building a Web Browser
and adding features to it. The book is: Microsoft 2008 Visual C# express.
I've learned a few tricks that I will use in my code as far as renaming the form.cs
and the main name of the entire code.
I'll catch up as soon as I get more Phidgets to work with and be able to see what I'm doing
as I work the code.
Thanks
Calvin

Alex
07-23-2008, 01:21 PM
The js.State.GetButtons that is the code getting the status of the button,
Pressed - which is probly a 1 and unpressed - which is probly a 0.
Because the buttons are digital, correct?
The js.State.GetButtons() method issues a request to the JoystickState object contained within the USBJoystick class that I built. It returns an array of all buttons, not just the ones on your joystick, but all buttons within the JoystickState object. You need to roll through this array to find the current state of the particular button you want to find the state of.

look at my original joystick example code and step through this section to understand what it is doing:


byte[] buttons = js.State.GetButtons();


for (int x = 1; x <= 12; x++)
{
if (js.ButtonPressed(x) == true)
{
strText += x + " ";
}
}

Honestly, unless you're really wanting to learn about it, I'd skip over the stuff that it's having you do in regards to web programming. It's not really necessary if all you want to learn is programming standalone apps in C#. Then again, maybe you should learn a bit about this. I could think of some really cool apps with web programming and your R2D2...

Adrenalynn
07-23-2008, 01:24 PM
Like web-based remote control? :)

ctx32
07-23-2008, 06:19 PM
Byte is a small bit of memory used for storing the Interger, correct?
[] These I sorry I still don't understand.

For is simular to a While Loop, But it doesn't break out like a While loop,
It keeps checking for a change in the loop, correct?

Int x is declaring X as a memory value with the value of 1, correct?
And X(which has the value of 1) if it's less than or equal to 12, correct?
The X++, I think means add the value of 1 + 1, Not sure on that one.

The rest I do understand, Hopefully I got these right.
The book I will continue working becuase I really want to understand all of C#.
And it has me typing all kinds of stuff I've never seen before. It might not help me
on my code much, But it probly will on something else later.

Hey, I almost forgot!!!
My Intel Atom board came in the mail today and I can't wait to get the memory, hard drive etc.
Thanks Guys
Calvin

Adrenalynn
07-23-2008, 06:51 PM
Set x equal to 1
go through the for loop
increment x by 1, x now = 2
go through the for loop
increment x by 1, x now = 3
go through the loop
increment x ... x now = 12, fall out of the for look and do the next thing.

ctx32
07-23-2008, 07:07 PM
Now I get it.
And I understand the 12, Because there's 12 buttons on the gamepad.
As this loop runs it's so fast that you never realize it's moved on to the next thing.
Thanks Adren.
Calvin

ctx32
07-24-2008, 02:22 PM
Alex, Adren,Indy,

I just wanted you guys to know and I guess it's Ok,
I'll be showing the R2D2 Phidget code off this weekend to fellow Droid builders.
The meeting is in Clearwater, Florida and I will be bragging about you guys and doing
a demo of how the software works.
I'm so PROUD of this project and can't wait to see and hear their comments.
Thanks again Guys for what you've done to help me.
Calvin

Alex
07-24-2008, 03:37 PM
The "[]" (no quotes) indicates an array or a collection. Read up on these two terms in your book. When you run into a term that you're not sure about, make sure to read up on that term as well. It's really kinda difficult to break down the definition of an array/collection in a single post.

A bit outdated, but this will still help you quite a bit with definitions of .NET terms I'm sure:

http://docs.msdnaa.net/ark/Webfiles/glossary.htm#net_glossary


Good luck this weekend! Let us know how everything goes:D

ctx32
07-24-2008, 07:20 PM
Array
Values whose members, called elements, are accessed by an index rather than by name. Arrays have a rank which specifies the number of indices needed to locate an element (sometimes called the number of dimensions). Arrays may have either zero or non-zero lower bounds in each dimension.

I'm going to have to find more on this, It should be in my books.
Let me read up on this one and I'll get the correct answer and come back to you.
Thanks Alex
Calvin

Alex
07-24-2008, 07:50 PM
sounds good. After reading up on arrays a bit, I can help clarify anything you need:D

ctx32
07-28-2008, 03:29 PM
I'm Back,
I guess that's a good thing LoL.
Anyway, Our group was impressed with the code and the Phidgets.
I bragged my Butt of about you guys ( Alex, Adren and Indy )
I told them how much help you guys are and I would not have been able to do this without
your help. Some of the builders were like me in the beginning about learning Visual C#, But
I explained to them if I could learn C# they could too. I have pics on my blog if you would like to
see the meet. Toms R2 (http://www.tomsr2.blogspot.com/)
I also explained to them how I thought this setup would cut the power consumption in a droid.
Instead of running different electronics for each action like sound, servo controll and etc.
I just want to say: Thank you so much for being there guys, I really do appreciate everything
you've done.
Calvin

Alex
07-29-2008, 09:22 AM
Thanks for the update and pix! I love the little Jawa (?) in the background here:

http://bp2.blogger.com/_dg2MnBnUt8Y/SI4m5m3kOuI/AAAAAAAAAt4/fO0EMVCmz1U/s1600/DSC03157.JPG

It's great to hear everything was a hit, congrats!

ctx32
08-07-2008, 05:32 PM
Hey Guys,
Sorry I haven't been around lately, But after our R2 meeting I got the build fever again.
I'm trying to finish my R2 and help my wife finish her R3.
We were invited to MegaCon next year and would love to have our droids moving.
I also wanted to ask you guys if Trossen has any type of banner that could be used at MegaCon.
We have a booth and it will be set up very tasteful.
Anyway I thought I'd say HEY!!!
Calvin

ctx32
08-16-2008, 08:08 AM
Alex,
You mentioned a Failsafe to me awhile back and I do plan to have a mechanical kill switch on the dome. But I've read more and more about rogue robots and need a better setup.
I've looked at different setups for R/C, But they don't look like they will work with Phidgets.
What would you recommend?
Calvin

ctx32
08-16-2008, 08:27 AM
I found this info on the controller I plan to use.
Will this stop the drive motors?


R/C input mode takes two standard R/C channels and uses those to set the speed and direction of
the motor. There is an optional timeout setting. When timeout is enabled, the motor driver will
shut down on loss of signal. This is for safety and to prevent the robot from running away should
it encounter interference and should be used if a radio is being used to control the driver. If
timeout is disabled, the motor driver will continue to drive at the commanded speed until another
command is given. This makes the Sabertooth easy to interface to a Basic Stamp or other lowspeed
microcontrollers.

As I understand the Pc should only send the drive signal to the Phidget as long as it receives the signal from the remote (Gamepad). Correct?

But will the Phidgets return to the neutral state if the signal is lost from the remote and the Pc is not sending a drive signal to the Phidget?
Or will it continue to run the motors until a signal is received to stop the motors?

I watched a video of a robot going rogue and it ran over some kids, Don't want that to happen.
Calvin

Adrenalynn
08-16-2008, 10:58 AM
What happens if the motor controller's brains die? Sending it a command to stop isn't really valuable since it's braindead and the motors just keep on churning.

Appropriately sized relays on a wireless transmitter are the only way to go, IMHO. And even with that, I have a big read safety stop switch on my big bot.

ctx32
08-16-2008, 03:03 PM
You mean have a seperate transmitter just for a kill switch.
I have a 12Ch. Ebay remote that I'm using for powering lights, I could run a
line to a relay so if R2 goes rogue I could shut the feet down.

And I will have a hidden switch on the top of the dome for a manual kill switch.
IMHO?
Calvin

Alex
08-16-2008, 10:36 PM
But will the Phidgets return to the neutral state if the signal is lost from the remote and the Pc is not sending a drive signal to the Phidget?
Or will it continue to run the motors until a signal is received to stop the motors?

It doesn't do this automatically, you'd have to code it in. There is some kind of object(s) that you can use that will notify you when the computer has lost communication with the gamepad. I can't remember the name of the object(s) and I removed all that code anyway because I couldn't figure out how to get it to work.

I'd second Adrenalynn's solution. Much easier and safer to rely on rather than writing code for a failsafe. There are just too many variables involved that would cause a robot to go rouge, so it's best to have a hardwired failsafe.

ctx32
09-01-2008, 02:46 PM
Hey Guys,
Sorry I have'nt been around lately, But I'm doing my best to get R2 complete by MegaCon.
I don't think I'm going to make it though.
I found a single channel remote with a relay board for the emergency kill.
I need to find out if the relay can handle 24v. I know the power for the board itself is 12v.
Anyway just wanted to say HEY.
Calvin

Adrenalynn
09-01-2008, 05:22 PM
What are the ratings on the relays? And how many amps are you looking to pull through them?

There should be a Max DC/Max AC rating on the relays themselves, but the really important number is the current ratings.

ctx32
09-01-2008, 09:03 PM
I just got the info and it's 3 amp 14v.
So it won't work, I need the relay for 24v.
Is it possible to use this relay board to switch a larger relay.
I'll have to find out the max on the 135w. motor will pull.
Calvin

ctx32
09-05-2008, 02:19 PM
I was in the dumps for a few days, My laptop crashed and along with it was my code.
Luckly, I had backed up the code and all I lost was the sound files.
I've allmost got it back to what I had and I'm happy again.
Hopefully soon, I will be able to order some more parts and work on the code again.
Calvin

ctx32
11-13-2008, 03:13 PM
Hey Guys,
There's been alot of talk on the R2 Builders Group about Failsafe.
It will be something I really look into before I run R2.
I've been very busy trying to finish R2 and it looks like I'll have to run him with my
Vex setup at MegaCon.
Nice to see you guys are still here.
Calvin

4mem8
11-13-2008, 05:12 PM
As for swapping relays on your board, just make sure the coil rating of the relay you use Ohm wise is similar to what you have already on the board, Otherwise if it is to high it may not pull in.

ctx32
03-13-2009, 09:28 AM
Hey Guys,
Just a small update on R2.
He was running at MegaCon in Orlando, Florida and it was a real blast to drive him around for the 1st time.
Once I get the onboard comp going, I'll start transferring some functions to this system and finally get to use
my Phidgets.
SeeYa
Calvin

Adrenalynn
03-13-2009, 02:02 PM
Pictures! Video! We wanna see!

Grats!

ctx32
03-14-2009, 09:10 AM
Hey Adren,
Here's a link to the pics and videos.
MegaCon (http://s71.photobucket.com/albums/i124/ctx3201/MegaCon&#37;2009/)
I have more video of my R2 running around But I don't have them uploaded yet.
Calvin

ctx32
03-14-2009, 07:38 PM
I do have a question you might be able to help me with Adren
If I use Xp without a monitor on this little Intel board.
How will I boot and shut down the board?
If I just switch the comp off, Won't Xp give me a problem?
Calvin

Adrenalynn
03-15-2009, 02:28 AM
Do you have anything on the 'bot that can take digital inputs and spit out serial/usb/whatever?

Just read a button and send a shutdown. Startup's easy. Just turn it on.

jes1510
03-15-2009, 01:35 PM
If you can pass commands to the command line from your control program then this may help:
http://www.tech-recipes.com/rx/84/xp-easy-shortcut-or-command-line-shutdown/

lnxfergy
03-15-2009, 01:56 PM
I do have a question you might be able to help me with Adren
If I use Xp without a monitor on this little Intel board.
How will I boot and shut down the board?
If I just switch the comp off, Won't Xp give me a problem?
Calvin

Doesn't the motherboard have a power switch plug? You should be able to put a switch on there, run it out to the outside, and then set the BIOS/windows settings to shutdown on power press (startup when pressed is already there).

I know our CHIARA robots have pico-ITX boards and this works with Ubuntu on them.

-Fergs

ctx32
03-15-2009, 04:49 PM
I don't have anything that I know of for input.
I did try the shutdown.exe -s and yep it shut this comp off.
I'll have to check the bios and see if it has a shutdown by the power button.
Calvin

ctx32
03-15-2009, 05:40 PM
The bios does have a setting for the power button, But it's just on/off.
Not really being able to have a monitor attached I won't know if Xp did a
correct shutdown.
It may not really matter, I guess.
I'm also trying to find out how much battery power it will eat when in standby.
I have 3- 12v.10ah batts in R2 now and I could put alittle larger batts in him.
The batts so far are only running the main drive feet and last along time.
Calvin

jes1510
03-15-2009, 05:42 PM
Beautiful work by the way. That thing is gorgeous!

ctx32
03-16-2009, 10:20 AM
Thanks Jes!!!!!
I have a new problem that I need help with guys.
When I boot this old comp the Phidget manager appears in the right lower corner
and if you click the manger it shows my 4- servo controller, But if you click the Ui it
doesn't work the controller. If use unplug the controller then try the sets again it works.

So I downloaded the updated manager and now the code that Alex and Adren helped me with
won't work or come up at all.
Is there something in the code that works with the manager that needs to be changed?
Calvin

Alex
03-16-2009, 10:36 AM
Could you include the snippet of code that is crashing your app?

ctx32
03-16-2009, 11:36 AM
Hey Alex,
I got it running in the VC# enviroment again, I did a rebuild and it works now.
I'm trying to publish the code onto my harddrive, But it does'nt seem to be working.
It does the publish, But if I they the setup file after the publish it tells me I can't do that.
I'm reading trying to figure out what I'm doing wrong becuase I did it before and it put a
program icon on my list and it was working.
Calvin

Alex
03-16-2009, 11:41 AM
good to hear you got it working again! I was thinking it had something to do with referencing an older DLL, but wasn't sure.

I'm not sure I understand what you mean by "publishing the code onto your hard drive"? Are you trying to create a setup.exe type file that when you run it, it'll install the application directly onto your computer? Could you provide some steps as to what you're trying to do?

ctx32
03-16-2009, 11:48 AM
After MegaCon it really got me wanting to finish R2.
I got it installed as a program and it runs now. it was still installed from the 1st time I did the setup.
(Slow Learner I am)
The only problem I'm having now is:
If I reboot the comp, The Phidget Manager does show down in the right corner as it should and it
knows the 4- servo controller is connected but unless I unplug the controller and reconnect it
I can't use the controller and my code won't work either.
Is there something on the Phmanger I need to work on?
Calvin

Alex
03-16-2009, 12:01 PM
starting with Windows is just a setting in the PhidgetManager. Once you load it up, double click on the Ph icon and you should see a checkbox underneath the grid that says "Start Phidget Control Panel with Windows"

As far as the other problem I'm not sure. You may somehow be still using the old DLL, so to be absolutely certain you are not, do the following:



Open your application in VS.
Go to Solution Explorer, expand the References node and delete the Phidgets reference
Go to Build -> Clean Solution.
Go to Build -> Build Solution.

You should now be getting the error that the app cannot find the Phidget assembly. That's good:) If so, then go ahead and re-add this reference (Project -> Add Reference, .NET tab -> Phidget21.NET v2.1.4.51 runtime ver. 2.0.50727). There are three different Phidget components, so make sure you are adding the correct reference.

ctx32
03-16-2009, 12:22 PM
Done.
But if I reboot the comp (Like I was starting up R2) the manager comes up
and it knows the controller is there, But unless I unhook the controller and reconnect
the controller does'nt work. After I reconnect the manager and my code works.
Maybe it's this old comp.
Calvin

Alex
03-16-2009, 01:25 PM
Not sure what to tell you about that one... I just tried it out myself and it worked just fine. Just to verify, this is what I did:

- loaded up the Phidget manager making sure "start with windows" is checked.
- loaded up demo app by double clicking on item in list and tested single sensor to see if values change
- closed Phidget Manager and restarted computer.
- opened/double clicked Phidget Manager icon and loaded up app by double clicking on item in list. Sensor worked just as it did before.

I'm running Windows XP Pro on an Acer Aspire 5570z laptop with 1 GB of RAM.

ctx32
03-16-2009, 01:35 PM
Do you allways have to open the manager after a reboot to get the phidgets working?
Cause if I reboot and do not doulbe click in the manager the phidgets don't work
with any code until I do.
Manager is set to start with Xp and it does, But without the double click it's dead.
This is a big problem for me if I have to do this since R2 will not have a monitor.
Calvin

ctx32
03-16-2009, 01:38 PM
Sorry,
Also if I don't unplug the phidget and reconnect it, Even the manager app will not control
the phidget.
It's probly this crappy comp.
I hope so, If not this will kill my project.
Thanks for the help Alex
Calvin

Alex
03-16-2009, 01:58 PM
no, you don't need to always open up the Phidget Manager to get a Phidget working after a reboot. Think of Phidget devices the same way that you think of a USB keyboard or a mouse. It's all in the way that you design your application.

If you have to unplug & reconnect your Phidget just to get the manager to work, then there must be something screwy with your computer. I'd suggest downloading the Phidget Manager onto a different machine and testing just the manager with the notes I gave above.