Control pioneer with Matlab

Typically: "How do I... ", "How can I... " questions
Post Reply
andrea1999
Posts: 8
Joined: 30 Oct 2023, 19:01

Control pioneer with Matlab

Post by andrea1999 »

Hello, I'm trying to control my pioneer robot with api in Matlab. I would like the robot to go straight first and then rotate 90º around itself. For the moment I have the following code but the robot seems to misalign with the path. Is there a way I could do it more exactly?

Code: Select all

            
            	    this.client.setStepping(true);
		    this.sim.startSimulation();
                    position_0 = this.sim.getObjectPosition(this.pioneer, this.sim.handle_world);
                    while 1
                        % t = this.sim.getSimulationTime();
                        position = this.sim.getObjectPosition(this.pioneer, this.sim.handle_world);
                        if abs(position{1}-position_0{1}) >= this.cell_length || abs(position{2}-position_0{2}) >= this.cell_length break; end
                        this.sim.setJointTargetVelocity(this.rightMotor, this.velocity_wheel); % en rad/s
                        this.sim.setJointTargetVelocity(this.leftMotor, this.velocity_wheel);
                        this.client.step();
                    end
                    while 1 % rotate 90º
                        orientation = this.sim.getObjectOrientation(this.pioneer, this.sim.handle_world);
                        if abs(orientation{3}-orientation_0{3}) >= 89.9*pi/180 && abs(orientation{3}-orientation_0{3}) <= 90.1*pi/180 break; end
                        this.sim.setJointTargetVelocity(this.rightMotor, this.velocity_turning); % en rad/s
                        this.sim.setJointTargetVelocity(this.leftMotor, -this.velocity_turning);
                        this.client.step();
                    end

Thank you

coppelia
Site Admin
Posts: 10378
Joined: 14 Dec 2012, 00:25

Re: Control pioneer with Matlab

Post by coppelia »

Hello,

best would be to post a minimalistic, self-containing scene, that illustrates your problem.

Not sure what object you use to get the robot's position/orientation, but if you use the robot's base, then indeed you can only look at the gamma component of the orientation. Keep in mind that it varies between +-pi
Better would be to get the orientation of the robot relative to a reference object that represents the desired position/orientation, e.g.:

Code: Select all

sim.getObjectOrientation(robot, refObject)
You might have to create such an object (e.g. a dummy) and move it around as a helper object.

Cheers

Post Reply