| By karont333,
|
Views : 1242  |
Control SolidWorks
World-Class 3DCAD design software. Developed by Alibre who also make Catia, a high-end 3D package used by transprtation designers among others. Solidworks shares many features with Catia, but alone bears the distinction of being clearly the most popular 3DCAD package on the market at this time.
with a Basic Stamp  With the ‘new’ control paradigm being popularized by Nintendo wii, there has been quite an increased interest in gestural control. The wii controller contains a number of sophisticated sensors, including; an Analog Devices ADXL330, accelerometer and a PixArt optical sensor which is similar to a CCD camera. The complexity of implementing these devices is one thing but cost is another issue. These sensors can be reasonably priced in the huge quantities Nintendo orders, but for us, they are quite expensive and fragile parts. For this reason I choose to use simple tilt switches for this project. The switches I found are “Right Angle PCB Mount Tilt Switch’. Similar to old mercury switches, these use a small metal bearing to close contacts when they have reached about a 10 degree incline. Alternately you can build the project using momentary push switches. This misses some of the magic of gestural control, but it also allows you to avoid hunting down difficult to find devices. It should be possible to make your own tilt sensors from bent paperclips, a soda straw, and a BB - or similar materials.  The tilt switches i used looked like this. In this article I will detail how to use Visual Basic 6, SolidWorks 2006 API, and a Parallax Basic Stamp 2 to make hardware communication with SolidWorks possible. Presented in the form of a simple low cost 'gestural controller', this project can serve as both an introduction to SolidWorks API programming, and a tutorial on Basic Stamp to Visual Basic RS232 communication. Sort of like a wii controller but in a very limited way, at a fraction of the cost: and interacting with a popular 3D design package! If you do not have SolidWorks, you can still benefit from the example of a useful working example of polled RS232 communication between VB6 and a BS2. This has been covered other places, but not in the form of such a rediculous application.   The screenshot above is the 'interface driver' which communicates with SolidWorks, and the image below is of the hardware I created. I built the hardware onto a RadioShack project board that plugs directly into the Parallax BS2 Homework Board, but it is possible to be built on a breadboard using a BS2 IC, or easily converted to PicBasic Pro, or other MCU basic languages - if there is any demand, a C version of the project will be considered.
Looking at the PC aplication you can get a general idea how the program works. 4 input bits are read, to create 10 possible states if you include neutral. To provide smooth operation, an acceleration, max speed, and visual feedback section allows fine tuning of the device dynamics. These features are quite simple programatically, but they provide a much richer user experience. Parts List | Quantity | Part | | 1 | Parallax Basic Stamp 2 | | 1 | Green LED | | 1 | Red LED | | 4 | 220 ohm to 1k Resistors | | 4 | 10K Resistors | | 4 | 470 ohm Resistors | | 4 | Pushbuttons or Tilt Switches | | | Wire, hot glue gun, soldering iron, and other common project supplies | Part 1 - Project Overview: Hardware For a general overview of the BS2 serial in/out commands, I recommend you checkout the Scott Edwards ‘Nuts & Volts of BASIC Stamps #16’ column. Otherwise, lets look at the schematic. The hardware consists of BS2 IO pins P0 through P3 pulled low, and switched active high. Additionally, 4 LEDs are connected to P4 through P7 to provide visual feedback of hardware operation. All of this can be built on a breadboard, or constructed on prototype
A prototype is an original type, form, or instance of some thing serving as a typical example, basis, epitome, or standard for other things of the same category.The most common use of the word prototype is a functional, although experimental, version of a device or product(e.g., automobiles, domestic appliances, consumer electronics) whose designers would like to have built by mass production means, as opposed to a mockup, which is an inert representation of a machine's appearance, often made of some non-durable substance.
PCB as I have done.  My hardware which I threw together in an evening to impress the guys at the office. My enclosure was made of a piece of 1x1x1/8” aluminum square tubing and some acrylic I had. I added a scroll wheel scalvaged from an old Microsoft Mouse, however, the encoder has not been implemented in the current hardware or software. I imagined it being used to zoom or scroll. An easy feature to add may be to have a different action assigned to the scroll wheel for each of the 8 ‘directions’ our controller features. While my hardware is fairly elaborate, much simpler hardware can provide similar control potential.  The inside of my controller was assembled with wire-wrap wire and built on a polystyrene frame.
Milled translucent acrylic endcaps allowed me to run the activity output to a bright white LED inside the controller body, which created a pleasent glowing effect when the device is in use. Part 1 - Project Overview: Software The software I have used is fairly simple on the BS2 end, with more work on the PC side to communicate between Solidworks and VB6. First the BS2 code: ' -----[ I/O Definitions ]------------------------------------------------ SIOpin CON 16 ' serial I/O on programming port ' -----[ Constants ]------------------------------------------------------ Baud96 CON 84 ' 9600-8-N-1 (matches DEBUG) CmdID CON $F0 ' get string ID CmdSet CON $F1 ' set string ID CmdStat CON $B0 ' get digital output status CmdLEDs CON $B1 ' set LED outputs CmdBtns CON $B2 'Get button state ' -----[ Variables ]------------------------------------------------------ ' cmd VAR Byte ' command from PC/terminal addr VAR Byte ' EE address pointer eeDat VAR Byte ' EE data param VAR Word ' parameter from PC char VAR param.LOWBYTE potVal VAR Word ' reading from BSAC pot Buttons VAR Nib ' BSAC input buttons ' -----[ EEPROM Data ]---------------------------------------------------- ID DATA "version: alpha 001", CR ' CR-terminated string ' -----[ Initialization ]------------------------------------------------- OUTB = %0000 ' turn off LEDs (active low) DIRB = %1111 ' make port C all outputs ' -----[ Main ]----------------------------------------------------------- Main: ' wait for a command cmd = 0 SERIN SIOpin,Baud96,[WAIT ("?"),HEX cmd] ' check for command IF cmd = CmdID THEN ShowID IF cmd = CmdSet THEN SetID IF cmd = CmdStat THEN ShowStat IF cmd = CmdLEDs THEN SetLEDs IF cmd = cmdBtns THEN GetBTNstate BadCommand: DEBUG "Invalid Command: ",HEX2 cmd,CR GOTO Main ' -----[ Subroutines ]---------------------------------------------------- ShowID: DEBUG "ID=" ' label output addr = ID ' point to first character of ID HIGH 4 GetEE: READ addr, eeDat ' read a character from EEPROM DEBUG eeDat ' print the character addr = addr + 1 ' point to next character IF eeDat <> CR THEN GetEE ' if not CR, read another PAUSE 5 LOW 4 GOTO Main GetBTNstate: DEBUG "BtnState=",BIN4 INA, CR HIGH 4 PAUSE 5 LOW 4 IF INA > 0000 THEN HIGH 7 PAUSE 5 LOW 7 ENDIF GOTO main SetID: addr = ID ' point to ID location GetC: SERIN SIOpin,Baud96,[char] ' get character from PC WRITE addr, char ' write character to EEPROM addr = addr + 1 ' point to next location IF char <> CR THEN GetC ' if not CR, wait for another GOTO ShowID ' confirm new ID ShowStat: ' show LED status DEBUG "Status=", BIN4 ~OUTB, CR GOTO Main SetLEDs: ' wait for output bits ' - as binary string SERIN SIOpin,Baud96,[BIN param] OUTB = param.LOWNIB ' set the outputs GOTO ShowStat ' confirm new outputs End ‘end program Recommend this article... |