Move robot towards reference axis
Show older comments
Hi! I'm an undergraduate currently working on a project where the goal is to control a robot with two DC-motors(no encoders) and an arduino board, towards a target by using visual data. I take an image with a webcam and then the robot needs to angle itself towards the target. My problem here is that the robot and the camera has two separate coordinate systems, so I need to calibrate the robot's angle towards the x-axis first, so that the readout from the angle-meter on the robot corresponds to the offset from the x-axis on the camera's coordinate system. I written a program that can find the xy-coordinates of the robot in the camera plane and I have a readout from the angle of the robot's angle-meter in MATLAB. How can I calibrate the robot so that it always has (approximately) a zero degrees readout from it's angle-meter when it is angled towards the camera's x-axis ?
My current code looks like this:
function[Offset] = CalibrateRobCam(ard, cam);
Frames = 1; %Number of frames to snap of plane.
Color = 1; % Red = 1, Green = 2, Blue = 3.
[X Y] = trackObject(cam, Color, Frames); %Gets coordinates of robot in the camera plane
X = round(X); Y = round(Y);
RobotPos = [X ;Y];
%%Calibrate Robot coordinate system with camera coordinate system
ZeroPos(ard); % Positions the robot for where it read euler angle approx zero degrees.
theta = readAngle2(ard); %reads robot angle from gyro/accelerometer. angle is [-180 180]
O = [cosd(theta) - X ; Y]; %Creates reference vector for positioning the robot towards x-axis.
U = [cosd(theta); sind(theta)]; %Creates vector for robot, converting from polar to cartesian.
CosTheta = dot(O,U)/(norm(O)*norm(U)); %Angle in radians between vectors
Theta = round(acosd(CosTheta)) ; % Angle in degrees between robot and target
Drive3Angle(ard, -Theta, 5); %Steers the robot towards the target angle
Offset = readAngle(ard); %Robot angle-meter offset when it is positioned towards camera x-axis
end
This will not work as I intend it to do... the input variables "ard" and "cam" correspond to the arduino-serial connection and the webcam. Here's an illustration for clarification:

I need to find the angle "theta" and then steer the robot that amount of degrees. I would be very thankful if anyone could help me with this issue since I've been stuck for a long while on this problem now. I have access to almost every toolbox. Thanks!
Answers (0)
Categories
Find more on Robotics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!