Skip to content

Instantly share code, notes, and snippets.

@iKrishneel
Created July 21, 2022 01:54
Show Gist options
  • Save iKrishneel/bc45ac96f776e729cfac55f4b5ee966d to your computer and use it in GitHub Desktop.
Save iKrishneel/bc45ac96f776e729cfac55f4b5ee966d to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import rospy
from phoxi_camera.srv import (
ConnectCamera,
ConnectCameraRequest,
GetFrame,
GetFrameRequest,
TriggerImage,
TriggerImageRequest,
)
class Photoneo(object):
def __init__(self):
sensor_id = rospy.get_param('~sensor_id', 'CDV-170')
connection_srv = rospy.get_param('~connection_name', '/phoxi_camera/connect_camera')
trigger_srv = rospy.get_param('~trigger_name', '/phoxi_camera/trigger_image')
getframe_srv = rospy.get_param('~getframe_name', '/phoxi_camera/get_frame')
connect = self.service_init(connection_srv, ConnectCamera)
self.trigger = self.service_init(trigger_srv, TriggerImage)
self.get_frame = self.service_init(getframe_srv, GetFrame)
rospy.loginfo('Connecting to the camera: {}'.format(sensor_id))
request = ConnectCameraRequest(name=sensor_id)
response = connect.call(request)
if response.success:
rospy.loginfo('Sensor {} is successfully connected'.format(sensor_id))
else:
rospy.logerr('Failed to connect to {} {}'.format(sensor_id, response.message))
rospy.signal_shutdown(response.message)
def service_init(self, srv_name, srv_type, timeout=20):
rospy.wait_for_service(srv_name, timeout)
srv = rospy.ServiceProxy(srv_name, srv_type)
rospy.loginfo('Connected to SRV {}'.format(srv_name))
return srv
def capture_once(self):
trigger_request = TriggerImageRequest()
trigger_response = self.trigger.call(trigger_request)
if not trigger_response.success:
rospy.logwarn('Failed to trigger')
return
get_response = self.get_frame.call(GetFrameRequest(in_=trigger_response.id))
if not get_response.message:
rospy.logwarn('Failed to get the image')
def main(argv):
try:
rospy.init_node('photoneo', anonymous=False)
pe = Photoneo()
assert pe
import IPython
IPython.embed()
# in the ipython termianl
pe.capture_once()
rospy.spin()
except rospy.ROSInterruptException:
sys.exit()
if __name__ == '__main__':
import sys
main(sys.argv)
@iKrishneel
Copy link
Author

iKrishneel commented Aug 8, 2022

calibration manual

1. Run the camera driver docker container

# build the API
$ cd /opt/Photoneo/PhoXiControl-1.7.5/API/examples/CPP/ExternalCamera
$ mkdir build && cd build
$ cmake .. && make build 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment