Taking Pictures with the Camera tool#
Before Starting:#
Clear any existing items off the bed of your machine!
[ ]:
from science_jubilee.Machine import Machine
from science_jubilee.tools.WebCam import WebCam
[ ]:
m = Machine(address='192.168.1.2')
[ ]:
# m.home_all() # uncomment and run if your machine needs to be homed
Tool import and set up#
Our camera tool will require a tool_index
and a tool_name
. These should be the same as the ones defined in the machine’s config.g
file.
Camera Tool
[ ]:
# initialize the camera object from the configuration file
cam = WebCam(1, 'Camera', 'webcam_config.json')
# note that 1 is the tool index, which is different than camera index in the config file
# camera index is useful when you have multiple cameras
# load the camera tool into the machine
m.load_tool(cam)
Let’s pick it up!
[ ]:
m.pickup_tool(cam)
Let’s move the camera to the spot where you want a picture taken.
[ ]:
m.move_to(150, 150, 100) # move to the center
[ ]:
cam.preview() # show the camera preview
# press 'q' to quit the preview
Let’s take a photo!
[ ]:
filename = 'test_image.jpg'
cam.take_picture(filename)
Simple as is!
Let’s take a video!
[ ]:
cam.record_video('test_video.avi', 5) # record a 5 second video
Sometimes it might be helpful to record videos in parallel of other things! you can use record_video_async
for that purpose.
[ ]:
cam.record_video_async('test_video_async.avi', 5)
# record a 5 second video asynchronously
# while the bed is moving
m.move(30, 30, 0)
m.move(-30, -30, 30)
# note that if you move z at full speed, the frame may be out of focus
We can now park the camera:
[ ]:
m.park_tool()
And turn off the camera!
[ ]:
cam.release()