Thread: Hex Kiwi Drive
View Single Post
  #35   Spotlight this post!  
Unread 05-06-2016, 22:21
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,038
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Hex Kiwi Drive

Quote:
Originally Posted by caume View Post
With this model, the battery is the back of the drive, the point opposite it is the front. flMotor would be the motor on the left side, closest the point opposite the battery.

Psuedocode:
Code:
if (fieldOriented) {
	cosA = cos(( target - gyroAngle ) * 3.14159 / 180 )
	sinA = sin(( target - gyroAngle ) * 3.14159 / 180 )

	x = (driverLX * cosA) - (driverLY * sinA)
	y = (driverLX * sinA) + (driverLY * cosA)
}


flMotor =   y*sind(60) + x*cosd(60) + turn
mlMotor =   y + turn
blMotor =   y*sind(60) - x*cosd(60) + turn 
frMotor = - y*sind(60) - x*cosd(60) + turn
mrMotor = - y + turn
brMotor = - y/sind(60) + x/cosd(60) + turn

If I assume the following:
driverLX is the driver's field-centric move right command
driverLY is the driver's field-centric move downfield command
turn is the driver's rotate clockwise command
target is an angle offset which defines the "front" of the robot relative to the point opposite the battery
... then your code gives incorrect answers for the wheel speeds. See example with target=0 (front is defined as the point opposite the battery as stated above) and gyroAngle=0 (robot front is facing straight downfield).


Quote:
Originally Posted by caume View Post
this guy did it just how I did.
Apparently not. The code I posted gives the correct wheel speeds for robot-centric driver FWD and STR commands.

To make that code give the correct wheel speeds for field-centric driver FWD and STR commands, just modify those commands as follows before calculating the wheel speeds:

Code:

temp =  FWD·cos(θ) + STR·sin(θ);
STR  = -FWD·sin(θ) + STR·cos(θ);
FWD  =  temp;
... where θ is the gyro angle, measured clockwise from straight downfield.

Attached Thumbnails
Click image for larger version

Name:	badcode.png
Views:	18
Size:	6.9 KB
ID:	20837  
Attached Files
File Type: xls badcode.xls (14.5 KB, 3 views)

Last edited by Ether : 06-06-2016 at 15:12.
Reply With Quote