Pablo Aizpiri

My experiences and thoughts on [mostly] technology.

Category: Miscellaneous

Random topics that don’t fit in any other category, or information on the blog maintenance itself.

.NET Serial Communication and Microbotlabs’ Robotic Claw

Microbotlabs Robotic Claw

Microbotlabs Robotic Claw

I always enjoy playing with electronics and seeing what I can do with them, so I’m a big fan of Arduino and the maker movement. One area I had been wanting to explore with electronics was real world physical interactions, like moving robots or robotic claws. So I added a robotic kit to my wish list on Amazon and just so happened to get one for the holidays!

This is the Microbotlabs “MeArm DIY Robot Arm Kit With MeCon Pro Motion Control Software and Arduino Source Code” that you can get on Amazon MeArm DIY Robot Arm Kit With MeCon Pro Motion Control Software and Arduino Source Code. The kit quality is a little low (especially the servos) and the instructions and support seem lacking; but I was able to put it together and it was still a lot of fun and pretty cool. Once I built the claw, I connected it to my Arduino and tried running the application Microbotlabs include to control the claw from your computer (MeCon).

With everything working, I toyed around with the application for a bit. What I thought was really cool was the idea of “recording” servo positions and playing them back so that the robot could record and playback motions. Below is a screenshot of the application, where you can see the controls. There’s the ability to move the base and each of the 3 servos controlling various parts of the arm, and the on the right there is a list of “coordinates”. These are servo positions, and you can use the application to record a list of these “coordinates” and play them back so that the robotic claw can perform a specified movement (and presumably so you can generate code from it that you can maybe add in your project).

Microbotloabs MeCon application

Microbotloabs MeCon application

This was pretty fun, but it very quickly became obvious it was going to be difficult to record and playback smooth motions without a lot of work. I would record some movements and then I would play the recording back, but the Robotic Claw would jerk and jump to the new servo positions. I was either going to need to record a lot of motion data or just accept jerky movements. Adding insult to injury, it was also difficult to edit a motion once recorded. Here’s a short video of playback of the motion recording with the standard software:

To be fair, I’m sure if I would have spent enough time adjusting and tweaking I could have gotten that to work somewhat, but I still had limitations. I decided it would be fun to build my own interface to address these problems using .NET and very generically called it “Crawl Controller”…

Ta dah!!:

.NET ClawController Application

.NET ClawController Application

Basically, the major feature difference is that a user can move the claw to the desired position and record “key frames” much like 3D animation for 3D models in video games. On playback, the user can have the application interpolate in between each key frame and come up with the “frames” in between so that the motion is nice and smooth. I went ahead and put all my code (which wasn’t the prettiest, but hopefully clear enough) on GitHub so anyone can download and play with it. The application also makes it easier to delete and add new key frames wherever desired which really comes in handy when “designing” a new movement. The application also allows the user to send more precise servo positions rather than just a degree (180 degrees), but the application is still backwards compatible with the code that Microlabs provides out of the box. (See GitHub for Arduino code that allows “Crawl Controller” to use more precise servo positions)

Anyway, here is a video of the finished product with interpolation. It is much easier to put together complex motions and the smooth movement allows much more gentle motions making it easier to pick up and set down objects consistently and repeatedly. Here, I recorded movement for the claw that loops and you can see the claw can repeatedly put down and pick up the VGA/DVI adapter again after finishing the animation without knocking over the adapter- the animation also was easy to record.

Code on GitHub: https://github.com/JhottMaster/ClawController

Hope someone else has as much fun with it as I did.

Executing an SSIS package from Stored Procedure

I recently needed to do this for a report. In theory, the SSIS package was going to run on some sort of schedule, but then it was decided that the user wanted the ability to run the report on-demand. Since the SSIS package didn’t take too long to execute, I decided I would try to run it on-demand. I was using this in an SSRS report, so I had to build a stored procedure to do this.

The key here is that I had to run the SSIS package, wait until the package was done, and then return data. I also didn’t want the package to potentially run indefinitely, and so if a package ran longer than the timeout or the job ran into an issue, the report should return empty.

NOTE: Make sure the user that will run the procedure also has access to run the SSIS package. (This is granted by giving user access to SSIS database; more here)

This is what I came up with which ended up working rather nicely:

-- =============================================
-- Author:		Pablo Aizpiri
-- Create date: 7.15.2015
-- Description:	Runs the SSIS package that returns results
-- results
-- =============================================
ALTER PROCEDURE [dbo].[RefreshAndQueryFromSSIS]
	@TIMEOUT_SECONDS INT = 60 -- Max number of seconds to wait for SP to execute.
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	DECLARE @EXECUTION_ID BIGINT, @OUTPUT_EXECUTION_ID BIGINT

	-- Setup SSIS package to run:
	EXEC SSISDB.CATALOG.CREATE_EXECUTION
						@FOLDER_NAME = '[SSIS Package Folder Name]'
						,@PROJECT_NAME = '[SSIS Project Name'
						,@PACKAGE_NAME = '[SSIS Package .DTSX File Name]'
						,@EXECUTION_ID = @EXECUTION_ID OUTPUT

	-- Run SSIS package:
	EXEC SSISDB.CATALOG.START_EXECUTION @EXECUTION_ID
	SET @OUTPUT_EXECUTION_ID = @EXECUTION_ID;

	DECLARE @STATEID AS INT = 0, @SECONDSRAN AS INT = 0
	-- Waits until package is successfully completed or until max timeout is reached:
	WHILE (@STATEID < 3 OR @STATEID = 5) AND @SECONDSRAN < @TIMEOUT_SECONDS
	BEGIN
		WAITFOR DELAY '00:00:00:5'; -- Give time back to CPU while waiting for timeout
		SELECT @STATEID = status, @SECONDSRAN = DATEDIFF(SECOND, start_time, GETUTCDATE())
		FROM SSISDB.catalog.executions
		WHERE execution_id = @EXECUTION_ID;
	END

	SELECT *
	FROM [Results table here]
	WHERE @STATEID = 7 -- this ensures results are only returned if the package execution was successful.
END

© 2017 Pablo Aizpiri

Theme by Anders NorenUp ↑